Braces go on the next line.
July 25, 2012 3:18 PM   Subscribe

The Profound Programmer combines realistic exclamations with beautiful nature imagery.
posted by Nomyte (60 comments total) 22 users marked this as a favorite
 
This
posted by hellojed at 3:29 PM on July 25, 2012 [4 favorites]


This is awesome, thanks. Just subscribed to the Twitter feed.
posted by yerfatma at 3:29 PM on July 25, 2012


They are correct about tabs, braces and compilers.
posted by Gary at 3:31 PM on July 25, 2012


I like tabs.
posted by condour75 at 3:35 PM on July 25, 2012 [7 favorites]


And I like K&R braces. The wonderful thing about being a programmer is that you get to have strong opinions about trivial, stupid things that don't matter and everyone else will fight you about it :)
posted by JoeBlubaugh at 3:38 PM on July 25, 2012 [19 favorites]


Ugh, really, from the looks of that, you'd think programmers fuck things up all the time.
posted by monospace at 3:42 PM on July 25, 2012


They are correct about tabs, braces and compilers.
posted by aspo at 3:44 PM on July 25, 2012


Ugh, really, from the looks of that, you'd think programmers fuck things up all the time.

Probably no more than anyone else, it's just that a computer holds us responsible before we can dodge it.
posted by Foosnark at 3:45 PM on July 25, 2012


monospace: "Ugh, really, from the looks of that, you'd think programmers fuck things up all the time."

Well... yeah. Wait, am I doing it wrong by doing it wrong?
posted by brundlefly at 3:46 PM on July 25, 2012 [2 favorites]


single letter variables who the fuck do you think you are
posted by boo_radley at 3:48 PM on July 25, 2012 [5 favorites]


The wonderful thing about being a programmer is that you get to have strong opinions about trivial, stupid things that don't matter and everyone else will fight you about it :)

Guilty as charged.

My favorite instance of this is when Douglas Crockford says things like "Conforming to a consistent style improves readability, and frees you to express yourself in ways that matter." Which is big talk from the guy who appointed himself in charge of what everyone else's style should be.
posted by Gary at 3:49 PM on July 25, 2012


Gary: "Which is big talk from the guy who appointed himself in charge of what everyone else's style should be."

get out of here fat

fat you don't even program in a real language
posted by boo_radley at 3:55 PM on July 25, 2012 [1 favorite]


well the joke's on me, his homepage on github is listed as byfat.xxx, clicked on it and now security is asking me about porn sites

time to box up my stuff i guess

curse you fat

curse you
posted by boo_radley at 3:58 PM on July 25, 2012 [3 favorites]


This may be the amateur typographer in me more than the amateur programmer, but I really like braces to be on their own line. It just feels more organized.
posted by Doleful Creature at 4:10 PM on July 25, 2012 [1 favorite]


Of course the brace goes on the next line. Because [[vi]] says so.
posted by sfenders at 4:33 PM on July 25, 2012


I'm not the guy from this thread, boo_radley.

When I saw the semi-colon one I was actually thinking of C++'s classes. If you forget the semi-colon at the end, some compilers tend to go a bit nuts with the errors. I'd really like a prompt that says "you forgot this, you want me to add it?". Although I'm sure that's a bad idea for a variety of reasons.

I wasn't thinking of automatic semi-colon insertion as implemented by javascript.
posted by Gary at 4:40 PM on July 25, 2012


I let my students choose their own style, the only requirement being consistency.
Sometimes
	{
	it invites some pretty weird shit
		;
	}
Until they meet Python, that is.
posted by anarch at 4:41 PM on July 25, 2012 [5 favorites]


I prefer K&R braces. Seems a waste of a line* to have a brace there all by itself, telling you nothing you don't already know about which statements begin blocks and which don't. The closing brace has a purpose worth being on its own, though.

* Yes, I know that lines are not in finite supply.
posted by axiom at 4:44 PM on July 25, 2012 [5 favorites]


Until they meet Python, that is.

Significant whitespace is a big divider though. I like how python looks so think it's great. It doesn't slap me on the wrists for trivial stuff and we get along. Other people just recoil in horror over the whole concept, though.

(But you should run it with -tt if you have multiple programmers. Tabs or spaces are fine, if I have to be honest. But mixing them in a python program is asking for trouble.)
posted by Gary at 5:00 PM on July 25, 2012


If you didn't use one one true brace style {
    You are over using new lines.
}
posted by humanfont at 5:11 PM on July 25, 2012 [8 favorites]


I have much experience in developing and working with standards, including developing the standard used most widely by programmers of a particular programming language. The most important thing about programming style is that all the members of the programming team choose one and use it. Since choosing one always devolves into a religious argument, the team can get hung up for months arguing about what the style to use.

The best solution is for management to briefly survey the opinions then impose a style on the team (preferably on tablets carved in stone). Programmers who then don't follow the standard are then publicly flogged or other punishments deemed appropriate.
posted by Xoc at 5:11 PM on July 25, 2012


Too close to home.

Fuckers.
posted by clvrmnky at 6:07 PM on July 25, 2012


(As a hack, can someone expose me to the argument that shows what a total ass I am for indenting with tabs?)
posted by maxwelton at 6:21 PM on July 25, 2012


(As a hack, can someone expose me to the argument that shows what a total ass I am for indenting with tabs?)

Tabs versus Spaces: An Eternal Holy War.

You're not an ass, there are deeply personal aspects to this holy war. But there are also pretty good technical reasons for using spaces over tabs.
posted by Blazecock Pileon at 6:33 PM on July 25, 2012 [2 favorites]


This is my favorite.
posted by trip and a half at 7:09 PM on July 25, 2012


* Yes, I know that lines are not in finite supply.

Lines simultaneously visible on the screen are, though.

Tabs versus Spaces: An Eternal Holy War.

That article not only makes some good arguments, it stands as a striking contrast to the topic of this post.
posted by weston at 7:19 PM on July 25, 2012


I've been shouting this when something just won't damn work recently.
posted by lucidium at 7:20 PM on July 25, 2012


This one is good and made better because they included the shameful twin. Sometimes those happen one after another, which is why you don't rant and rave about a bug until you are sure it isn't yours.
posted by Gary at 7:24 PM on July 25, 2012 [3 favorites]


(As a hack, can someone expose me to the argument that shows what a total ass I am for indenting with tabs?)

You can see a space. You can't see a tab. The tab is a code that your editor interprets, and different editors have different ideas about what to do with tabs (2 spaces, 3, 4 (hey, COBOL old guy!), the abominable 8?).

You have may have your own sacred views about coding style. When I work on someone else's code, though, I try to mimic his or her style, even if I think an abomination, simply because a reasonably consistent style improves readability.

But looking at tab-indented code, there are formatting secrets hidden there I cannot see. Perhaps everywhere, Joe Coder used tabs, except in this one section where Liz Programmer came in and made a fix, with spaces. Not to be malicious, mind you. But Liz couldn't see what Joe was doing, because tabs and spaces all look like spaces.
posted by SPrintF at 7:27 PM on July 25, 2012


Although, in delimited data files, I like the tab as a delimiter precisely because a user cannot enter a tab in common applications. The application interprets the tab, you see, as go to the next thing, and the tab itself is discarded. So, tab-delimited files are blobs of text separated by markers that you can confidently assume the user couldn't enter.

So, tabs are most useful when you don't have to look at the darn things.
posted by SPrintF at 7:38 PM on July 25, 2012 [3 favorites]


one line fix, my ass

This is an awesome site. I will buy their posters.
posted by A dead Quaker at 7:58 PM on July 25, 2012 [1 favorite]


Metafilter: fix my ass.
posted by Nomyte at 8:02 PM on July 25, 2012 [1 favorite]


And I thought you meant a real programmer who takes great nature photographs, like Bill Atkinson.
posted by scruss at 8:08 PM on July 25, 2012


More like the self-loathing programmer. It's true that it can be frustrating to deal with other people's shit code. But I don't know, if you're having this much trouble with your own code you probably just suck.

Also, braces go at the end of the line.
posted by delmoi at 11:17 PM on July 25, 2012


Who the fuck indents with tabs, I hope the sandman fucks you through a mattress.

I indent with tabs. I'm from the linux kernel, bitch.
posted by smcameron at 11:26 PM on July 25, 2012 [3 favorites]


This reminds me of a programming questionnaire a company gave me about working in teams, I was going to write a short paragraph about communication and making compromises, but instead I wrote "AGREE ON FORMATTING AND NAMING CONVENTION"
posted by hellojed at 1:55 AM on July 26, 2012


I'm pretty sure the universe has now decided that tabs are for indentation, spaces are for alignment.

That way you can set your tab settings to 8 like a moron while reading my horizontal-saving 4 tabbed code just fine. AND continued lines will still line up because we used spaces to do it.
posted by DU at 4:27 AM on July 26, 2012


Now, some people will claim that having 8-character indentations makes
the code move too far to the right, and makes it hard to read on a
80-character terminal screen. The answer to that is that if you need
more than 3 levels of indentation, you're screwed anyway, and should fix
your program.
Spoken like someone who never uses strings or even variables of more than one letter.
posted by DU at 4:29 AM on July 26, 2012


DU: "Spoken like someone who never uses strings or even variables of more than one letter."

Indents imply braces imply nesting imply increased conditional complexity and among other things, commingling of concern.
posted by boo_radley at 8:07 AM on July 26, 2012 [1 favorite]


I'm pretty sure the universe has now decided that tabs are for indentation, spaces are for alignment.

Whatever the universe thinks, if tabs people and spaces people can agree on one single thing, it's that mixed-tabs-and-spaces pretty much need to die in a fire.
posted by brennen at 9:50 AM on July 26, 2012 [1 favorite]


More like the self-loathing programmer. It's true that it can be frustrating to deal with other people's shit code. But I don't know, if you're having this much trouble with your own code you probably just suck.

Here's the thing: You suck.

I mean, if you, as a programmer, don't understand that you suck, I don't really want to work with you. Because it probably means that you have never learned how to cope with the inevitable entropy of your own work. I'm not a great programmer, but I'm a better programmer than plenty of people who are smarter than me because I know that:

a) Past Me was dumber and less experienced than he knew how to know he was, and I'm gonna have to deal with his work.

b) Future Me will forget more than he knows how to know he's forgetting, and he's gonna have to deal with whatever bullshit Present Me is committing with the mental context that makes him just capable of pulling it off eroded all to hell and gone.
posted by brennen at 10:11 AM on July 26, 2012 [3 favorites]


mixed-tabs-and-spaces pretty much need to die in a fire.

This is the gist of the argument against using tabs: Eventually, spaces will get mixed in, always, and you won't know this because you can't see them with normal editor settings.

This means I get to try multiple tab settings in my editor trying to get the code to line up right, until I figure out that for some reason the original tab setting was (perhaps) "3". And then something still doesn't line up right, because somebody edited with spaces and a different tab setting and didn't notice that 80% of the source file looked totally random, so regardless of what setting I choose the file still looks wrong.

Every time I have to do this with some arbitrary source code it convinces me more that tabs are evil.
posted by and for no one at 10:45 AM on July 26, 2012


Plus, spaces nice granular, concrete single values that never change, whereas tabs live in this nebulous "do what thou wilt" world where the boundaries are always shifting. A space is always a space. That just feels nice.

I like the fact that in many good text editors there's a setting for "all indentations are spaces" so you can still use the tab key with invoking an actual tab value.
posted by Doleful Creature at 11:11 AM on July 26, 2012


Doleful Creature: "A space is always a space. That just feels nice. "

And that in fact is the entire problem - if you prefer indentation levels to be modulo 8, and you use ascii space characters to accomplish this, then I am forced to view the code the same way, even if I prefer modulo 4 (or even worse, what if I'm one of those heathens out there who prefer modulo 2!).

If you use a single ascii tab character per indentation level, then we both get to view the code the way we prefer.

make(1) files and python are the only places I can think of off the top of my head where ascii space characters become necessary (since both make and python care about whitespace chars.)

Everywhere else, when it comes to indentation, it should be ASCII 9, all the time.
posted by namewithoutwords at 11:20 AM on July 26, 2012


This is the gist of the argument against using tabs: Eventually, spaces will get mixed in, always, and you won't know this because you can't see them with normal editor settings.

Very true. And that is also the argument against using spaces: Eventually, some tabs will get mixed in, always, and you won't be able to see them with normal editor settings.
posted by sfenders at 11:25 AM on July 26, 2012


... so obviously, the correct thing to do is indent with semicolons.
posted by sfenders at 11:30 AM on July 26, 2012 [3 favorites]


it's that mixed-tabs-and-spaces pretty much need to die in a fire.

Yeah. I was always a strong proponent of tabs because they allow everyone to customize things they way they like. Then I started working for myself, so I really didn't need to worry about the argument, except I started contributing to Open Source Python projects and PEP8 says "Spaces", so I've switched everything over which has the awesome side effect of making me angry at myself whenever I have to open an old codebase up and the whole things is underlined with green squigglies by my IDE.
posted by yerfatma at 11:33 AM on July 26, 2012


so obviously, the correct thing to do is indent with semicolons.

Which is good news for you K&R brace fans. The rest of us are kind of screwed.
;;;;for( i=0; i<4; ++i )
;;;;{
;;;;;;;;printf("Hi\n");
;;;;}
posted by Gary at 11:39 AM on July 26, 2012 [4 favorites]


Eventually, some tabs will get mixed in, always, and you won't be able to see them with normal editor settings.

My post-checkin hook will tell me if some tabs got into a file. I suppose you could do a similar test for leading spaces instead.

You young whippersnappers and your variable-width fonts...
posted by and for no one at 1:24 PM on July 26, 2012


Gary: "so obviously, the correct thing to do is indent with semicolons.

Which is good news for you K&R brace fans. The rest of us are kind of screwed.
;;;;for( i=0; i<4; ++i )
;;;;{
;;;;;;;;printf("Hi\n");
;;;;}
"


~ soon ~

"eat flaming death, four-semicolon indenter!"

"suck it, two-semicolon haver!"
posted by boo_radley at 3:00 PM on July 26, 2012


All this thread really needs now is an invocation of the You People Are Living in the Stone Age Everything Should Just Be A Representation of the Abstract Syntax Tree Which You Edit WITH YOUR MIND meme.
posted by brennen at 3:10 PM on July 26, 2012 [1 favorite]


John McCarthy isn't with us any more.
posted by boo_radley at 3:44 PM on July 26, 2012 [1 favorite]


Everything Should Just Be A Representation of the Abstract Syntax Tree Which You Edit WITH YOUR MIND

yeah-but: I don't like LISP.
posted by and for no one at 5:04 PM on July 26, 2012 [1 favorite]


These things always seem to end up with int 21h
posted by humanfont at 5:15 PM on July 26, 2012


and for no one: "yeah-but: I don't like LISP."

thank you for beating the joke to death.
posted by boo_radley at 6:13 PM on July 26, 2012


All coding conventions wither and die when faced with the terrifying might of Acme::Bleach.
posted by scruss at 8:33 AM on July 27, 2012


I mean, if you, as a programmer, don't understand that you suck, I don't really want to work with you. Because it probably means that you have never learned how to cope with the inevitable entropy of your own work. I'm not a great programmer, but I'm a better programmer than plenty of people who are smarter than me because I know that:
One of the things that annoys me about the way a lot of programmers like to communicate is that they come up with "general rules" that are meant to always apply to every situation. According to your "rule", you'd refuse to work with John Carmack or Linus Torvalds. They don't think they suck, and they're correct.

Your rule isn't a rule that applies in every case. Obviously some developers are over confident and think they don't suck when they do, but it's simply not the case that every programmer who doesn't think they suck actually does.

The problems you mention about not being able to figure out what you were trying to do have never been a problem for me. It could be because I haven't had to edit my own code too often, but one reason for that might be that my code just works and doesn't need to be fixed very often (and that it's modularized and encapsulated so well that adding features doesn't require touching very much code at all)

When I do go back and look at my old code, I don't have much trouble figuring out what I was trying to do.
posted by delmoi at 10:16 PM on July 27, 2012


you'd refuse to work with John Carmack or Linus Torvalds. They don't think they suck, and they're correct.

To quote Carmack: The first step is fully admitting that the code you write is riddled with errors. That is a bitter pill to swallow for a lot of people, but without it, most suggestions for change will be viewed with irritation or outright hostility. You have to want criticism of your code.

Which is not quite the same as saying he sucks. But coding valuable programs on time is really hard, and most code sucks as a result.

You're probably right about Linus.
posted by Gary at 10:58 PM on July 27, 2012 [1 favorite]


Which is not quite the same as saying he sucks.
No, it's not. And brennen didn't seem to be talking about code having bugs, obviously all code is going to have some bugs, but rather being hard to understand/whatever. Also, of course code is going to be buggy on the first pass, but when it's a 'finished product' it should be relatively bug free. Obviously, if there are time constraints and you don't get a chance to fix all the bugs, that doesn't mean you suck, it means your boss does (or that the cost of the time it would take to fix the bugs is less then the money you would lose by having them exist)
posted by delmoi at 10:32 PM on July 28, 2012 [1 favorite]


No, it's not. And brennen didn't seem to be talking about code having bugs, obviously all code is going to have some bugs, but rather being hard to understand/whatever. Also, of course code is going to be buggy on the first pass, but when it's a 'finished product' it should be relatively bug free. Obviously, if there are time constraints and you don't get a chance to fix all the bugs, that doesn't mean you suck, it means your boss does (or that the cost of the time it would take to fix the bugs is less then the money you would lose by having them exist)

I'm coming back in here way late, but I'll just suggest that, whatever the rhetoric, near-universally-respected programmers like Carmack and Torvalds have internalized the bedrock reality of just how fallible programmers including themselves are, and act accordingly. And are thus probably less fallible than they otherwise would be. Knowing the deficiencies of the human organism is fundamental to writing code that won't ruin the lives of future human organisms, including yourself. The fallibility of programmers is also the better part of why we have most of the tooling and process that conditions the working life of serious programmers. You probably don't write one of the most popular and successful version control systems, frex, without having some awareness of this.

I suppose it's also worth saying that I'm entirely comfortable operating with rules of thumb which assume that most programmers I will ever work with are not Linus Torvalds or John Carmack.
posted by brennen at 10:49 AM on August 6, 2012


« Older The American Fertility Crisis   |   If you're going to run away from home - fly Jet2 Newer »


This thread has been archived and is closed to new comments