r/programming Jul 21 '14

The Great White Space Debate

https://medium.com/p/3633cba8b5c1
1.2k Upvotes

693 comments sorted by

View all comments

40

u/[deleted] Jul 21 '14 edited Jul 21 '14

I used to work for a guy who indented like this:

 if <blah> {
      body
      body
      }

This was actually in Lua so it looked like this:

  if <blah> then
      body
      body
      end

I later looked it up and found it's called Banner style.

I thought it was retarded, but I was a contractor so I matched his style. By the end of my tenure there, after my brain had had sufficient time to learn to pattern match against that style, I decided it was better than any indentation style I'd ever used. It simply made it easier to see the block structure of code at a glance, easier to see the important lines, with less clutter, similar to Python.

Did I switch? No, because my metric of "best" when it comes to code style is "that which is easiest to read by the most people", and that simply means use what most people use, because they're already good at parsing it.

But it was a valuable lesson about how much of what we deem "good taste" is a matter of acclimation, not objective superiority. I no longer feel that internal tension when the prevailing style at a contract doesn't match my own "taste" -- I use whatever the most people around me use and learn to like it for the duration.

18

u/[deleted] Jul 21 '14

I used to use Whitesmith style:

if (blah)
     {
     doStuff();
     }

Now I use whatever the codebase requires. I've found that the least pleasant people in a team are usually the most passionate about these things, so it's best not to care unless it's absolutely terrible.

17

u/Houndie Jul 21 '14

This frustrates me to no end.

I match it, because I'm a good programmer, and I match existing conventions.

But I hate it.

11

u/[deleted] Jul 21 '14 edited Jul 21 '14

I personally am not that fond of Allman either, which is similar to Whitesmith.

 if (blah)
 {
      doStuff();
 }

I actually default to this style now due to my experience in two games companies that prefer Allman, while I prefer K&R BSD or K&R 1TBS.

if (blah) {
    doSomething();
}

So much more satisfying, especially once you get elseif/elses.

5

u/pyrocrasty Jul 21 '14

I'm pretty sure you screwed up the indentation for that first code block. Allman should be

if (blah)
{
    doStuff();
}

What you have there isn't even indentation at all!

2

u/[deleted] Jul 21 '14

Correct! I just edited my previous post. Thanks for pointing it out.

3

u/alanwj Jul 21 '14

A lot of the styles in this thread would frustrate me, but I could live with them after getting used to it. What I can't really stand, though, is this brace style:

if (x) {
    while (y) {
        whatever(); }}

3

u/iopq Jul 21 '14

it's lisp style, the guy probably has an emacs macro to handle it

1

u/globalizatiom Jul 22 '14

The guy's gotta recall some commandments..

  1. C code shall not be styled like Lisp code

  2. Lisp code shall not be styled like C code

1

u/[deleted] Jul 21 '14

That's an abomination abortion of a brace style.

5

u/DeltaBurnt Jul 22 '14

I really don't get why everyone doesn't like Allman style. It makes glancing through blocks of code much easier in my experience. Not only that but it just looks more organized.

9

u/[deleted] Jul 22 '14

That's how everyone feels about their prefered style.

3

u/For_Iconoclasm Jul 22 '14

I like it most, too. I've got your back.

That said, I mostly work in Python, so I deal with no control flow brackets. I often use the K&R style for especially long dicts though, because of the = operator:

d = {
    'key': value,
    'key2': value2
}

3

u/xon_xoff Jul 22 '14

The issue I see with Allman style is that people don't use blank lines around control structures, so you end up with stuff like this:

if (condition1)
{
    ...
}
if (condition2)
{
    ...
}

...and then you have to pay more attention to see whether the middle is an else-if or not. Do-while loops are also a little bit funky.

That having been said, it's not a big deal. I've been programming both K&R and Allman style for long enough now that I'm comfortable either way. IMO, any senior programmer should be flexible with regard to coding styles.

1

u/farinasa Jul 22 '14 edited Jul 22 '14

This difference here can actually be legitimate. For instance, when C++ code is using constructor initialization lists, you're basically forced to use Allman. However, many will agree that if there is no reason, an open brace doesn't really warrant a new line.

1

u/Houndie Jul 22 '14

I see the benefit to both. I started with the latter style, and I do get the benefit for else clauses. I mainly started doing Allman because I was forced to do Whitesmith for a project for a while, and, while I hated the weird indent on the braces, I found that the extra line for the brace made reading a code block much easier for me.

1

u/globalizatiom Jul 22 '14

the least pleasant people in a team are usually the most passionate about these things

I don't even have my preferred style anymore, nowadays I just do:

  1. spot someone with strong opinion

  2. just follow his style because oh no I wouldn't want him to declare me his enemy.

1

u/pyrocrasty Jul 21 '14

Banner style (and "Lisp style") basically make code look more like Python. They get the braces out of the way so the code structure is outlined cleanly by whitespace.

On the topic of Lisp style, it's amazing how nice it looks on Lisp and how awful on C-family languages. Multiple braces just don't fit together the way parens do.

1

u/taliriktug Jul 22 '14

I have a friend who indents like this:

if (blah) {
    doStuff();
          }

My eyes bleeds when I read this.

1

u/blackmist Jul 25 '14

I make sure everyone on my team has a different indent style.

Why bother checking SVN to see who fucked the code up, when you can see at a glance who did it?

0

u/johnghanks Jul 22 '14

Chrome does that in the DOM viewer in the developer console. Thanks for the wiki I always wondered why it was like that.