Firstly, I've made that mistake twice in the time I've been using Java (and C and C++), so not adding the braces has cost me about 20 minutes in terms of problems it caused in 12 years.
Secondly, my IDE can spot 'suspicious indentation', and does my indentation for me anyway, so I'd have to really try to get this wrong. Not using braces where they're unnecessary improves readability; programmers actually read by indentation, not by braces. On Thu, Sep 23, 2010 at 6:29 AM, Miroslav Pokorny < [email protected]> wrote: > On 23/09/2010, at 11:12 AM, Josh McDonald <[email protected]> wrote: > > Hey guys, I'm not weighing in on checked v unchecked, just a syntax sugar > idea! > > We've got two ifs: > > if (foo) > bar(); > > and > > if (foo) { > bar(); > } > > So why not introduce a cut-down syntax for common exceptions? Something > like this: > > > I believe it's fair to say the second firm if ifs an it's cousins while > loops etc without braces are considered bad form because it's too easy to > insert a statement inside and forget to enclose in braces afterwards if > necessary. > > > try file=File.open(...) catch(SomeException se, OtherException oe); > > Which would be expanded out by the compiler to this: > > SomeException se = null; > OtherException oe = null; > > try { > file = File.open(...); > } catch (SomeException e) { > se = e; > } catch (OtherException e) { > oe = e; > } > > And you can check the contents of the exception or not at your leisure. > > Thoughts? > > -- > "Therefore, send not to know For whom the bell tolls. It tolls for thee." > > Josh 'G-Funk' McDonald > - <[email protected]>[email protected] > - <http://twitter.com/sophistifunk>http://twitter.com/sophistifunk > - <http://flex.joshmcdonald.info/>http://flex.joshmcdonald.info/ > > -- > You received this message because you are subscribed to the Google Groups > "The Java Posse" group. > To post to this group, send email to [email protected]. > To unsubscribe from this group, send email to > [email protected]. > For more options, visit this group at > http://groups.google.com/group/javaposse?hl=en. > > -- > You received this message because you are subscribed to the Google Groups > "The Java Posse" group. > To post to this group, send email to [email protected]. > To unsubscribe from this group, send email to > [email protected]<javaposse%[email protected]> > . > For more options, visit this group at > http://groups.google.com/group/javaposse?hl=en. > -- You received this message because you are subscribed to the Google Groups "The Java Posse" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/javaposse?hl=en.
