tag:blogger.com,1999:blog-1468479222802516939.post7522810122215800627..comments2023-09-30T05:55:46.349-04:00Comments on The Virtual Machinist: Proportionality of incremental changesPeter Burkahttp://www.blogger.com/profile/15290253671442020919noreply@blogger.comBlogger3125tag:blogger.com,1999:blog-1468479222802516939.post-78060491829881070532011-03-16T01:32:57.967-04:002011-03-16T01:32:57.967-04:00I totally agree. I used to always use braces and ...I totally agree. I used to always use braces and always had "one way in, and one way out" of a method. But in recent years I've softened.<br /><br />On the braces front I cannot argue that it's better to always use them. But on the "one way out" front I must say that I find "early returns" to be helpful in simplifying the code. But I generally only do this at the start of method, rather than in the middle of a loop, for example.<br /><br />This, I guess is one of those age old arguments that software developers love to debate. So what color are we going to paint this bike shed, anyway? :-)Unknownhttps://www.blogger.com/profile/07249270283032139001noreply@blogger.comtag:blogger.com,1999:blog-1468479222802516939.post-46233060424878063542011-03-15T08:44:10.458-04:002011-03-15T08:44:10.458-04:00Simon:
No exceptions (to this rule) in our coding...Simon:<br /><br />No exceptions (to this rule) in our coding standards. Return, continue, break and throw must also be be in braces in this case. What if you want to change the return statement?<br /><br />Start with:<br /><br />if (foo) <br /> return getResult();<br /><br />and change it to:<br /><br />if (foo) {<br /> int result = getResult();<br /> return result;<br />}<br /><br />Now you need the braces.<br /><br />Also, we discourage, but don't forbid returning from the middle of a function. It's essentially equivalent to a goto. I'll write more about multiple return points some other time.Peter Burkahttps://www.blogger.com/profile/15290253671442020919noreply@blogger.comtag:blogger.com,1999:blog-1468479222802516939.post-63684952470015473342011-03-14T11:19:45.050-04:002011-03-14T11:19:45.050-04:00I agree completely, Peter. Things get even worse ...I agree completely, Peter. Things get even worse when the one line is another control structure, such as an if-statement that has an else-clause and braces are not used again. Boy can that get confusing! You should be able to understand the code independent of white-space and indentation, which is not always the case when braces are not used. Of course for every rule there's an exception: I skip the braces when the one line is terminating, such as a return, continue break or throws.Unknownhttps://www.blogger.com/profile/07249270283032139001noreply@blogger.com