Created
July 18, 2011 09:02
-
-
Save alecmce/1088960 to your computer and use it in GitHub Desktop.
one return per method
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// a difference is not a difference unless it *makes* a difference | |
public function add(item:*):Boolean | |
{ | |
if (contains(item)) | |
return false; | |
push(item); | |
return true; | |
} | |
public function add(item:*):Boolean | |
{ | |
var notContained:Boolean = !contains(item); | |
if (notContained) | |
push(item); | |
return notContained; | |
} |
I'm with squeedee. Guard clauses rule; conditional slaloms drool.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
well we have two issues now.. On the original one, I never claimed that Guards are outright the right way. Just that they are awesome.
I originally got concerned that Tanya thought they're "Bad" and then was as amazed as you were at the outright position that Dave took.
If i can read it and make sense of it quickly, then i love it. Ergo, i have no issue with Dave's version... except... issue 2:
What I take to be a misunderstanding of Bob Martin's attempt to explain "when has extract method stopped being useful" and "how to name a function"
Describing the behaviour of the method does not necessarily make it an 'and'. I think i've outlined why I think this above?