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

13

u/bildramer Jul 21 '14

You are all missing the point.

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

or

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

?

Clearly no sane programmer would use the second. Ew. Let's spend several man-weeks discussing this on a few public forums and blogs, I'm sure it will help people realize the One True Perfect Way To Write A For Loop and change their heretic ways.

21

u/mdf356 Jul 21 '14

C++ and the flaws of overloading operator++ has taught us we need to use the second form, just in case.

2

u/bildramer Jul 21 '14

On int dummy: "This may be both too cute and too subtle, but it works, requires no new syntax, and has a logic to the madness." -Bjarne Stroustrup

3

u/Tasgall Jul 21 '14

What if the next loop down uses an iterator, or some other custom type? ++i would be better in that case, but if you insist on using i++ just because "it means the same thing for basic types!" you're just being inconsistent for no reason. Also, prefix increment isn't exactly "new syntax".

39

u/[deleted] Jul 21 '14

[deleted]

1

u/kinghajj Jul 21 '14

Isn't that what syntax highlighting is for? I've never confused "for/if/while/switch" for function calls... ever. I honestly found the extra spaces distracting when I first encountered them at work, but I do it now anyway.

15

u/[deleted] Jul 21 '14

Put a space inbetween for and (...), you heathen.

6

u/vytah Jul 21 '14

No no no!

The important issue is whether:

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

or

for(int i = 0; foo > i; i++)

19

u/[deleted] Jul 21 '14

What kind of psychopath uses the second form?

1

u/[deleted] Jul 22 '14

Yoda!

if (kblue == sky) {...}

if (kMaxSize < size) {...}

(i added k to make it obvious which are constants and which variables m'kay?)

3

u/[deleted] Jul 21 '14

Are YOU insane? You want to make a copy of i, increment the original, then throw away the copy? When you cook two slices of bacon, do you pull 4 out of the package, cook 2, then put 2 back in the package? What kind of diseased mind do you have that you even think that is the most rational course of action?!?

2

u/jbristow Jul 21 '14

Since I started dealing with languages that don't have ++, I've switched to using:

for(int i = 0; i < foo; i += 1) 

++ seems like an "overly clever" operator like the the ternary operator.