August 28, 2003Stylistic issuesComments on a few stylistic issues I noticed these past days. Ted talks about "cuddled else's" (what a cute name):
This convention is recommended by Sun, but I usually prefer to have the closing brace and the next instruction on separate lines. Nothing religious or artistic about this preference, the reason is pragmatic: easier copy and paste. For example, suppose you need to move the catch block to a different place in your source. Compare the copy/paste operation between the following two formattings:
and
Cameron posted the following code snippet, that I would also write slightly differently:
I have two remarks about this code:
Therefore, I would rewrite Cameron's code this way:
(Cameron, note that I respectfully respected your insane indentation scheme). Posted by cedric at August 28, 2003 09:41 AMComments
Yeah, your code is arguably better in this particular example. Except it should have been 'aoResult' (result is an array of objects). Smartypants. However, having more than one return doesn't bother me in Java quite as much as it did in C++. It's not something that I avoid religiously. Posted by: Cameron at August 28, 2003 10:36 AMRespectfully respected? Beautiful :) Posted by: at August 28, 2003 03:30 PMThe "Only one result" rule is good, but it oftens goes agains the "Deeply nested if statements are hard to read" rule. Then, you start having to comment your closing brackets, ... Besides, I find it elegant to treat these "weaker" post-conditions at the beginning of the method and once for all.
"note that I respectfully respected your insane indentation scheme" Really insane. Posted by: iwaku at August 30, 2003 02:58 AMWell I'm glad I'm not the only one using the 'insane' indentation :) Hang in there Cameron, we're a dying breed but still alive and kicking ;) Posted by: Daniel Farinha at August 30, 2003 02:19 PMYou guys haven't got anything better to do? In the end - who cares? It's really a matter of personal taste and so you set up your IDE to format it the way you like it and if someone else has to work with it, they can just format it the way they like it. Posted by: Richard at September 1, 2003 03:32 PMWell, I have no problems "cutting and pasting" the cuddled-catches. You just have to paste *over* the closing brace of try. The closing brace will be replaced by the catch's first brace. --Das Posted by: Das at September 4, 2003 11:37 AMI followed the link to all your ads Hi - I was looking for some political sites with articles on the recent US election and found your nice site. The comments from others on here are pretty good so I just thought I'd add my thoughts also! Elaine Cooper Posted by: lose weight with zone diet at November 4, 2004 01:11 PMCould it be that conservatives tend to spend more time at home? Now that these (fairly damning) facts have been documented by records obtained under the FOIA (AFTER the 2000 election by the way), we should focus on the even more damning issues: Merci pour l'information ici Posted by: yaoi at December 10, 2004 01:27 PMjust lunch new site Posted by: kayuar at October 17, 2005 11:36 PMYou guys haven't got anything better to do? On the contrast, I think multiple returns is easier to understand the flow. If you have many if-else, then single return assignment may soon be buried. But if a return can be made immediately after a condition is met, it is a clear flag that its flow ends there and it is easier to track. Anyway, this is really kind of personal preference. Posted by: Bo Wen at May 15, 2006 10:49 PMPost a comment
|