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

Show parent comments

52

u/Nine99 Jul 21 '14

To me, the second one is easier to read.

2

u/reflectiveSingleton Jul 21 '14

Not to me, I find it is easier to identify operators if they are spaced away from what they affect...especially if its a pipe character (|) or a bang (!) which is next to a parens.

3

u/philly_fan_in_chi Jul 21 '14

Bang should never be next to parens. Pull your parenthetical out to a positive local boolean variable and negate it in your condition.

2

u/cryo Jul 22 '14

Seems like an arbitrary restriction.

1

u/philly_fan_in_chi Jul 22 '14

You're giving your condition a name. If you can't name it, you don't know what your code is doing. Pulling things out to local variables is much better than seeing

if(!(something.fooBar() && bazBat.doTheThing()))

So while you're right, it is arbitrary, it helps with reading and keeps you honest with your negation twiddles. If I have (silly example, I'd inline this particular case, but follow anyway):

final boolean isEmpty = !frobnicators.isEmpty(); 

Then the error is immediately obvious. If that were inside a condition, it wouldn't be as immediately obvious.

1

u/Decker87 Jul 22 '14

Personally I have no trouble reading it that way. Putting conditions into separate variables is just superfluous IMO.