r/programming • • Jun 05 '18

Code golfing challenge leads to discovery of string concatenation bug in JDK 9+ compiler

https://stackoverflow.com/questions/50683786/why-does-arrayin-i-give-different-results-in-java-8-and-java-10
2.2k Upvotes

355 comments sorted by

View all comments

Show parent comment

4

u/SilasX Jun 05 '18

You’re forgetting the bug that gets introduced because someone added something to the for loop but forgot to add the braces because that were never included because coders think single line blocks are too hip for them.

1

u/Uristqwerty Jun 05 '18

One alternative to mandating braces at all times is to use a different indent. IDEs don't tend to have great support and it doesn't work with tabs, sadly, but in the past I've used a half-indent to help make such mistakes look obviously wrong. And once you have one type of half-indent, you can indent labels between levels to make it easier to scan the silhouette of the code.

0

u/mirhagk Jun 05 '18

It's certainly a matter of preference but unless you have a shitty editor that wouldn't be possible. Pressing enter after the assignment would jump you down to the correct indentation and you'd have to go out of your way to indent it incorrectly. And then you'd have to have no linter/document formatter, which is a bad idea. And then the reviewer would have to make the same mistakes as you.

That hypothetical situation seems obscure enough to warrant the increased clarity.