4 ms·
It's a C-style language syntax option. If it's only a single line in after the if, the braces are optional. I've also seen it in C++ and PHP. Whether or not
by workingandtired 12y ago
It's a C-style language syntax option. If it's only a single line in after the if, the braces are optional. I've also seen it in C++ and PHP.
Whether or not it's sloppy is up for debate and just a matter of personal preference.
- solistice 12y agoC# also has it, and i've heard Java has got it as well, but I've never tested it in the latter. I personally like being able to do it since it allows me to do away with the 2 extra lines auto indent puts in if i add brackets. That's a 50% reduction for a 4 line if. Maybe I should just buy a bigger monitor.
- workingandtired 12y agoThe lead programmer at my last job encouraged us to use it as a way to make sure our conditionals & foreach loops (PHP programmer) weren't doing too much. If we had to use braces, it was a sign to check it out and see if it could stand some refactoring.
- tenementfunster 12y agoSounds a tad inane.
- seanmcdirmid 12y agoI use a plugin called littlebrace for visual studio, which reduces brace lines to like 3 pt font. My C# code has started looking like Python :)
- TheEzEzz 12y agoThis sounds really neat. Can you drop a link? I browsed around but couldn't find anything.
- vacri 12y agohttps://github.com/lukesdm/little-braces https://github.com/lukesdm/little-braces looks like the one.
- seanmcdirmid 12y agoAlso see this fork/port to VS2013: https://github.com/owen2/little-braces https://github.com/owen2/little-braces Also, it is available from the online add-in manager if you search for "little braces." The VS2013 community edition is just in time :) I couple it with the indent guideline plugin for best effect (braces are super small, light lines to track indent level, 2 space indent...).
- MichaelGG 12y agoOr use a better bracing style. Or move to significant whitespace.
- Someone 12y ago"If it's only a single line in after the if, the braces are optional." Not _line_, _statement_. Consider if(flag) foo(); bar(); and if(flag) foo = bar + baz; That first example always calls bar(). Warning: I haven't tested this, and am beginning to doubt a bit. It must be correct, but why, then, don't I remember seeing this in underhanded C contests? Combining that with macros allows you to hide the semicolon.