Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
qntm
Jun 17, 2009

minato posted:

Do you put commas at the end of the line or the beginning?

code:
SELECT foo
     , bar
     , baz
FROM ...
This initially looks horrible, but it has a couple of advantages:
- Because the commas all line up, you can easily see missing commas
- It's common to add extra elements at the end, so it's easier to use vim's "yyp" to duplicate the last line and tweak it to what you want, instead of also having to go to the 2nd to last line and add a comma.
--- Corollary: when looking at a diff where someone's added a new line, the old last line is not affected so doesn't get added to the diff, so the diff is simpler to read (better fore code reviews). e.g diffs for adding a new column "wiz"

Commas at beginning:
code:
  SELECT foo
       , bar
       , baz
+      , wiz
  FROM ...
vs

Commas at end:
code:
  SELECT foo,
         bar,
-        baz
+        baz,
+        wiz
  FROM ...

I thought I was the only one who did this!

Adbot
ADBOT LOVES YOU

trex eaterofcadrs
Jun 17, 2005
My lack of understanding is only exceeded by my lack of concern.
MS SQL Server does the comma first style as well when you autogenerate SELECT queries in SSMS.

Factor Mystic
Mar 20, 2006

Baby's First Post-Apocalyptic Fiction
What? No it doesn't, at least circa 2008. Are you running an addin that's doing it for you like something from RedGate?

Volte
Oct 4, 2004

woosh woosh

qntm posted:

I thought I was the only one who did this!
It's the standard practice in Haskell:
code:
data Person = Person { firstName  :: String
                     , lastName   :: String
                     , address    :: Address
                     }

PrBacterio
Jul 19, 2000

Volte posted:

It's the standard practice in Haskell:
code:
data Person = Person { firstName  :: String
                     , lastName   :: String
                     , address    :: Address
                     }
Huh? (Not talking about the placement of the commans here but the braces instead but), I won't pretend that I actually know Haskell but I've always been led to believe that standard practice in Haskell was to leave all braces out because they'll be inferred automatically by an indentation-based rule, kind of like Python.

Opinion Haver
Apr 9, 2007

PrBacterio posted:

Huh? (Not talking about the placement of the commans here but the braces instead but), I won't pretend that I actually know Haskell but I've always been led to believe that standard practice in Haskell was to leave all braces out because they'll be inferred automatically by an indentation-based rule, kind of like Python.

Declaring records is pretty much one of the few places that braces are required.

shrughes
Oct 11, 2008

(call/cc call/cc)

PrBacterio posted:

Huh? (Not talking about the placement of the commans here but the braces instead but), I won't pretend that I actually know Haskell but I've always been led to believe that standard practice in Haskell was to leave all braces out because they'll be inferred automatically by an indentation-based rule, kind of like Python.

What yaoi prophet said, and also: using braces and semicolons is also very convenient for other forms of syntax that _could_ rely on indentation, because often it's easy to need to change the indentation of something, and it's a lot easier to get your editor to do it right if you used the braces.

TheresaJayne
Jul 1, 2011

Zhentar posted:

That is pretty terrible. If he never makes you fix that poo poo yourself, you're never going to stop doing it.

but then he is doing standard coding standard,
ie he is doing
code:
public void main(String[] args) {
     System.out.println("yes i know this is java and not php!");
}
where his super prefers

code:
public void main(String[] args) 
{
     System.out.println("yes i know this is java and not php!");
}
Where ever i am, (as a java dev) i try to get everyone to use PMD as it ensures that the code always matches the defined rules and stops that sort of problem, and I do believe that you can tweak it to work properly with any language so a php rule file might be helpful.

trex eaterofcadrs
Jun 17, 2005
My lack of understanding is only exceeded by my lack of concern.

Factor Mystic posted:

What? No it doesn't, at least circa 2008. Are you running an addin that's doing it for you like something from RedGate?

Yeah it does. In both 2005 and 2008 R2 at least.

Open SSMS, go find a table, right click on it, Script Table as >, SELECT To >, New Query Editor Window. Commas first.

Factor Mystic
Mar 20, 2006

Baby's First Post-Apocalyptic Fiction

TRex EaterofCars posted:

Yeah it does. In both 2005 and 2008 R2 at least.

Open SSMS, go find a table, right click on it, Script Table as >, SELECT To >, New Query Editor Window. Commas first.

I stand corrected. It doesn't do that for drop/create script creation though, which is what I checked when I read your post.


Anyway, gross. Add that to the unending list of SSMS failures I intend to solve with my SQL IDE.

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.

qntm posted:

I thought I was the only one who did this!

There's something of a movement in JavaScript-land for comma-first too.

code:
// standard style
var a = "ape",
  b = "bat",
  c = "cat",
  d = "dog",
  e = "elf",
  f = "fly",
  g = "gnu",
  h = "hat",
  i = "ibu";

// comma-first style
var a = "ape"
  , b = "bat"
  , c = "cat"
  , d = "dog"
  , e = "elf"
  , f = "fly"
  , g = "gnu"
  , h = "hat"
  , i = "ibu"
  ;

shrughes
Oct 11, 2008

(call/cc call/cc)

pokeyman posted:

JavaScript
code:
// comma-first style
var a = "ape"
  , b = "bat"
  , c = "cat"
  , d = "dog"
  , e = "elf"
  , f = "fly"
  , g = "gnu"
  , h = "hat"
  , i = "ibu"
  ;

I'm surprised that doesn't parse var a = "ape" as a complete statement and throw a syntax error on the next line.

No Safe Word
Feb 26, 2005

shrughes posted:

I'm surprised that doesn't parse var a = "ape" as a complete statement and throw a syntax error on the next line.

Why would that surprise you in a language that uses a line termination character?

shrughes
Oct 11, 2008

(call/cc call/cc)

No Safe Word posted:

Why would that surprise you in a language that uses a line termination character?

Because it's optional.

Plorkyeran
Mar 22, 2007

To Escape The Shackles Of The Old Forums, We Must Reject The Tribal Negativity He Endorsed

shrughes posted:

I'm surprised that doesn't parse var a = "ape" as a complete statement and throw a syntax error on the next line.
ASI normally only applies when the first token on the next line is not a valid continuation of the statement. return (along with break, continue, ++ and --) is just a dumb special case intended to fix the following problem:

code:
function do_stuff() {
    if (foo) return
    
    destroy_the_world()
}
Here the programmer clearly doesn't intend for destroy_the_world() to be called if foo is true, but without the special case it would be.

ASI has to be one of the worst ideas ever.

xarph
Jun 18, 2001


Torn between this thread and the poo poo that pisses you off thread...

code:
 # Stop command
  stop)
    echo "Stopping $APP"
    /bin/su -m $USER -c "$BASE/bin/shutdown.sh &> /dev/null"
    echo "$APP stopped successfully"
    ;;
I can forgive init scripts not being verbose, but at least you could check the goddamn return code or pass it through.

Edit:
code:
   # Restart command
   restart)
        $0 stop
        sleep 5
        $0 start
        ;;

xarph fucked around with this message at 02:11 on Aug 2, 2011

zeekner
Jul 14, 2007

xarph posted:

Torn between this thread and the poo poo that pisses you off thread...

code:
 # Stop command
  stop)
    echo "Stopping $APP"
    /bin/su -m $USER -c "$BASE/bin/shutdown.sh &> /dev/null"
    echo "$APP stopped successfully"
    ;;
I can forgive init scripts not being verbose, but at least you could check the goddamn return code or pass it through.

Edit:
code:
   # Restart command
   restart)
        $0 stop
        sleep 5
        $0 start
        ;;

That's like every init script ever written. I've seen one that used a web-interface to shut down the daemon, and never checked the output to find if that failed or not.

shinmai
Oct 9, 2007

CHK Instruction
e:nvm I'm an idiot.

ultramiraculous
Nov 12, 2003

"No..."
Grimey Drawer
Have to say the amount this thread has made me laugh has shown me I both know way more about programming than I realized and that I could have it wayyyy worse. The peak, for as far as I've gotten, was definitely the conversation about using prime factorization to set up parameter combinations.

I don't have any specific examples, but the project I'm working on is a mobile+server project. Version 1.0 of the django backend has several decent bits of way-too-complex logic copy pasted and many reimplimented features because the previous dev blatantly (from his code and talking to him) didn't trust the libraries. The iOS code is a set of classes with no hierarchy, as in no folder organization and no subclasses, and the query organization is basically a chain of HTTP requests whose response delegate targets are almost always in different classes. It basically turns into :bang: every time we need to hack something into the spaghetti code that we haven't had time to rewrite yet.

A lot of it is basically stuff you'd expect an intern or a novice programmer to do, but this guy has been a developer for about a decade :sigh:

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.

ultramiraculous posted:

The iOS code is a set of classes with no hierarchy, as in no folder organization and no subclasses...

For what it's worth, default Xcode behaviour is to throw everything in one folder, so you see tons of iOS/Mac apps that have no folder organization.

As for the lack of subclasses, I'm trying to picture an Objective-C project where no class has a superclass. It's an ugly picture.

the talent deficit
Dec 20, 2003

self-deprecation is a very british trait, and problems can arise when the british attempt to do so with a foreign culture





Aleksei Vasiliev posted:

If you wrap your lines at 80 characters I literally hate you irl

gently caress you i code in a terminal all the loving time :(

Malloc Voidstar
May 7, 2007

Fuck the cowboys. Unf. Fuck em hard.

the talent deficit posted:

gently caress you i code in a terminal all the loving time :(
why is your terminal 80chars wide

Blotto Skorzany
Nov 7, 2008

He's a PSoC, loose and runnin'
came the whisper from each lip
And he's here to do some business with
the bad ADC on his chip
bad ADC on his chiiiiip
So he can fit another one next to it

Shumagorath
Jun 6, 2001
I thought 80-chars was a hold-over from having to print out source code in university and not have it wrap. Python basically forces you to break that convention unless you like to use really short names for everything or end up cramming everything on the right side of the editor eventually.

Plorkyeran
Mar 22, 2007

To Escape The Shackles Of The Old Forums, We Must Reject The Tribal Negativity He Endorsed
i usually use a 87 character terminal because at my resolution and font size three 87 character windows just barely fit

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.

Shumagorath posted:

I thought 80-chars was a hold-over from having to print out source code in university and not have it wrap. Python basically forces you to break that convention unless you like to use really short names for everything or end up cramming everything on the right side of the editor eventually.

Of all the programming languages in use today, your example of one whose lines can't fit within 80 characters is the only one that suggests you do so.

mr_jim
Oct 30, 2006

OUT OF THE DARK

My terminal is 85 characters wide, so there's room for 4-digit line numbers and a space in Vim. Same with Emacs windows.

ninjeff
Jan 19, 2004

mr_jim posted:

4-digit line numbers

This is the real coding horror.

mr_jim
Oct 30, 2006

OUT OF THE DARK

ninjeff posted:

This is the real coding horror.

They usually don't get that high. If they do, they're much closer to 1000 than to 9999.

A A 2 3 5 8 K
Nov 24, 2003
Illiteracy... what does that word even mean?

pokeyman posted:

Of all the programming languages in use today, your example of one whose lines can't fit within 80 characters is the only one that suggests you do so.

Suggestions are made to be ignored, in accordance with how stupid they are, how outdated, or how much you find that something else simply works better for you.

Brecht
Nov 7, 2009

A A 2 3 5 8 K posted:

Suggestions are made to be ignored, in accordance with how stupid they are, how outdated, or how much you find that something else simply works better for you.
Coding horror spotted.

Munkeymon
Aug 14, 2003

Motherfucker's got an
armor-piercing crowbar! Rigoddamndicu𝜆ous.



Brecht posted:

Coding horror spotted.

<says the same thing upon seeing code that you've wrapped at 80 chars because you think you're supposed to do such things>

And the cycle continues

A A 2 3 5 8 K
Nov 24, 2003
Illiteracy... what does that word even mean?

Brecht posted:

Coding horror spotted.

"A Foolish Consistency is the Hobgoblin of Little Minds"

geonetix
Mar 6, 2011


Shumagorath posted:

I thought 80-chars was a hold-over from having to print out source code in university and not have it wrap. Python basically forces you to break that convention unless you like to use really short names for everything or end up cramming everything on the right side of the editor eventually.

I'm afraid to look at your code. I've written literally thousands of lines of python code in the past few years and have yet to run into that problem. You should try nesting less and making more clearly defined methods. It will make you love your code.

Also, it's 79 columns.

Doc Hawkins
Jun 15, 2010

Dashing? But I'm not even moving!


A A 2 3 5 8 K posted:

"A Foolish Consistency is the Hobgoblin of Little Minds"

Yeah, gently caress shared style standards, quite. :crossarms:

Hammerite
Mar 9, 2007

And you don't remember what I said here, either, but it was pompous and stupid.
Jade Ear Joe

Brecht posted:

Coding horror spotted.

He is right. At least: rules always have a reason behind them. It's important to understand the reason why a rule exists. If you understand the reason for the rule, you know enough to determine when breaking the rule is a valid course of action.

Lurchington
Jan 2, 2003

Forums Dragoon

Shumagorath posted:

I thought 80-chars was a hold-over from having to print out source code in university and not have it wrap. Python basically forces you to break that convention unless you like to use really short names for everything or end up cramming everything on the right side of the editor eventually.

I dunno, if the crowding on the right side is happening to me, I usually take that to mean that my stuff is too deeply nested.

it honestly isn't a constraint I find myself struggling against. I've occasionally had a less verbose function name than I would if I had been programming in something like Objective-C, but nothing I'd call 'short'

edit: basically what geonetix said

Goreld
May 8, 2002

"Identity Crisis" MurdererWild Guess Bizarro #1Bizarro"Me am first one I suspect!"

geonetix posted:

I'm afraid to look at your code. I've written literally thousands of lines of python code in the past few years and have yet to run into that problem. You should try nesting less and making more clearly defined methods. It will make you love your code.

Also, it's 79 columns.

In the case of C++, you can quite easily break the 80-column limit, especially if you're passing any templated arguments (especially using STL pairs).

It's a tradeoff between having easily readable names for variables and methods/functions, and having short code.

I aim for 80 columns, but in practice it usually ends up at around 100 columns or something that fits on a screen easily. Especially so when I was working on a very large codebase last summer and trying to follow a company's coding standards closely - there were occasionally calls that were impossible to format within 80 columns without doing dumb crap like naming variables A, B, C etc. (which would have violated their code standard anyways)


My opinion is this - try to keep your code consistently easily readable in Eclipse/MSVC without scrolling or wrapping, while keeping names of variables and functions consistent but descriptive. And if someone in VIM complains, well, they're the ones choosing to use an archaic editor. There's reasons to keep something easily readable on modern editors, but the 80-line standard is a bit over-restrictive and should die along with floppy disks and CRT monitors.

Goreld fucked around with this message at 19:02 on Aug 4, 2011

NotShadowStar
Sep 20, 2000

Goreld posted:

And if someone in VIM complains, well, they're the ones choosing to use an archaic editor.

Are you loving serious.

Also most people using VIM don't complain about line length if they're working on modern code.

Adbot
ADBOT LOVES YOU

kalleth
Jan 28, 2006

C'mon, just give it a shot
Fun Shoe

NotShadowStar posted:

Are you loving serious.

Also most people using VIM don't complain about line length if they're working on modern code.

He's quite clearly an emacs user

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply