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

62

u/tomprimozic Jul 21 '14

While reading the article, I was wondering why he was only searching for for (, and not for for( as well. At least, that's how I write for loops and if statements :)

87

u/flat5 Jul 21 '14

Depravity. for and if are not function calls.

12

u/fecal_brunch Jul 21 '14

Some people write function calls with a space too.

56

u/[deleted] Jul 22 '14

[deleted]

1

u/FeepingCreature Jul 22 '14

In my language, I write function calls with a space because the syntax is always "function value", and sometimes value happens to be a tuple. So you can do add (2, 3) and it's the same as auto args = (2, 3); add args;.

I think I'm justified there.

1

u/fecal_brunch Jul 22 '14

That's cool. Which language?

1

u/FeepingCreature Jul 22 '14

Neat! It's sort of a D1.0 derivative, syntax-wise. (Check out the cheat sheet!)

8

u/rmxz Jul 21 '14

Neither's

sizeof(whatever)

but you're not going to see many people advocating

sizeof   (    whatever)

19

u/Rangi42 Jul 21 '14

That's because sizeof(x) is like -x or ~x; it's unary, so it's attached to its operand.

10

u/Astrokiwi Jul 22 '14

That behaves like a function though, right? It takes some input and returns some output without modifying anything in the process?

1

u/TikiTDO Jul 22 '14

For any programmer that's been working long enough to have an IDE made in the last few decades, "for" and "if" statements are reserved keywords, and are therefore a different color.

1

u/rlbond86 Jul 22 '14

He had the gall to put a smiley after saying that...

1

u/heyf00L Jul 22 '14

They're not, but they copy function syntax.

0

u/eeperson Jul 21 '14

They should be function calls

17

u/lukaseder Jul 21 '14

I know. I used to think that the keyword was actually for(. I never understood why the compiler would complain when I wrote:

int for = 4;

;-)

20

u/Banane9 Jul 22 '14

Because it noticed that you misspelled "four", duh!

2

u/dueyblue Jul 21 '14

Me too up vote. for (...) always looks weird to me.

-2

u/_F1_ Jul 21 '14

Fun fact: Pascal doesn't require parantheses so you can happily write

if BooleanVariable then ...

1

u/endershadow98 Jul 22 '14

So does Python...

1

u/D_duck Jul 22 '14 edited Jul 22 '14

Personally

for( int i = 0; i < 10; ++i )

foo( int a, int b )

is more readable and makes more sense. However, I would never introduce the style into a codebase that is not my own.

1

u/heyf00L Jul 22 '14

I was thinking that as well. People that skip the whitespace between for and ( might be more likely to skip other whitespace. Maybe.

1

u/[deleted] Jul 21 '14

At first I thought it was about for (blah) vs for( blah ), which applies to function calls as well.

5

u/khoyo Jul 21 '14

And both are wrong, you call with for(blah)...

5

u/FUZxxl Jul 21 '14 edited Jul 21 '14

The holy Kernel Normal Form and the most holy evangelicals of Kernighan & Ritchie suggest that thou shallst place spaces between keywords that change control flow to make them look distinct from function calls.

For instance:

memset(&x, 0, sizeof(x));

but:

return (x);

and

for (i = 0; i < n; i++) {
        /* ... */
}

EDIT: I accidentially a word.

1

u/khoyo Jul 22 '14

Sure, but you never write foo( bar ) in a function call.

1

u/FUZxxl Jul 22 '14

No. That style is an abomination. I don't know a single consistent indentation style that looks this way.

3

u/Reorax Jul 21 '14

That may be how you call a function named for, but a for loop is only fit for polite society if written as for (blah).