[Adium-devl] Early Returns and the Coding Style Docs

Mac-arena the Bored Zo boredzo at gmail.com
Tue Mar 28 07:29:54 UTC 2006


On Mar 27, 2006, at 19:46:02, David Smith wrote:
> I was looking at a block of code, and noticed that using early  
> returns could make it, imo, much more readable. Basically, less  
> indentation depth, less masses of closing braces to try to match  
> up, and less scoping oddities (like having to declare  
> replacementMessage outside the if). However, our coding guidelines  
> say to avoid early returns. I can see the reasoning behind it  
> (single exit point functions do have some appeal), but I think we  
> make too many sacrifices.
>
> I do agree with the guidelines in that stuff like while() { while()  
> { if() { return foo; } } } return bar; should be avoided though. I  
> see early returns as mostly being useful for bypassing method  
> bodies when preconditions aren't met, such as below.

I agree with all of the above.

Shark hates on early exits for performance reasons. I don't think we  
need to worry about this except in cases of a real performance  
problem, though. In the general case, early returns are a Good Thing.

> There's also a side issue in that *somehow* 	replacementMessage =  
> [inAttributedString mutableCopy]; is failing, claiming that it's  
> calling -initWithAttributedString: with a nil argument. Dunno how  
> that happens.

You failed to properly install the Chicken Sacrifice Plug-in. Among  
other things, it patches a few libgaim bugs.
_____________________________________________
\ Mac-arena the Bored Zo / boredzo at gmail.com
PGP public key ID: 7AB26BAD (since 2006-01-01)


-------------- next part --------------
A non-text attachment was scrubbed...
Name: PGP.sig
Type: application/pgp-signature
Size: 186 bytes
Desc: This is a digitally signed message part
URL: <http://adium.im/pipermail/devel_adium.im/attachments/20060327/ce50b311/attachment.sig>


More information about the devel mailing list