9
dbonev
8y

if (condition)
Action();

Curly braces are not that expensive God dammit!

Comments
  • 3
    But sometimes quite redundant
  • 1
    saves a couple of key presses and 1 line. :P
  • 0
    The problem is that this easily becomes

    if (condition)
    Action();
    SomeOtherAction();

    And this is hard to spot.
    One of the reasons for the notorious Apple 'goto fail bug' was exactly that. A pair of braces and a line more is a good price to pay for scope clarity.
  • 1
    I only ever do this as a one-liner to avoid contingency errors like above
  • 0
    This is why I love Sublime Text; open curly braces -> Enter and you have both braces with your cursor in the correct position for adding your code.
  • 0
    the lack of curly braces on 1 line code blocks was the source of the major security certificate bug in iOS a while back
  • 0
    @CodeOrDie doesn't mean the rest of us can't take advantage of compiler/interpreter shortcuts, JS-focused dev here. In Go for example it's incredibly annoying to have to specify a block for each `if err` because the wasted space accumulates
  • 0
    And what about the placement of the braces? Same line or separate? 😈😈
  • 0
    Oww i see the evil 😠
Add Comment