By bloid
via weblogs.java.net
Published: Dec 09 2007 / 22:45
![]() | |
| BIRT 3.7 | |
| Written by: Michael Williams | |
| Featured Refcardz: Top Refcardz: | |
| 150+ Refcardz Available · Get them all | |
By bloid
via weblogs.java.net
Published: Dec 09 2007 / 22:45
Comments
seanhussey replied ago:
Informative post, but I disagree with the content. Is there a neutral vote? :)
Eric Burke replied ago:
"if" makes code more complex? Give me a break. Sounds like dogma.
Ricky Clarkson replied ago:
The blogger didn't give enough detail. He said the talk was really about if and for. If you're using a for loop and an if statement inside it to find all items in a list that have a certain property, you are effectively hand-coding something like this:
list.filter(hasPropertyX)
Not only that but you're likely doing it eagerly, which means that you're creating a new copy of the elements in the list when you create the list, rather than lazily. The above filter code may not necessarily be lazy, but we've decoupled whether it's lazy from the calling code.
robse replied ago:
Patternoholics.
English link was 404.
wittgen replied ago:
actually I do feel a little dirty whenever I use an "if". weird.
antych replied ago:
It makes kinda sense, polymorphism is your friend. Too many conditional statements in OO code usually mean the author has no clue. Of course there's no point in getting religious about it. You can end up with rally messed up code if you try avoiding them no matter what.
palsforpals replied ago:
I voted up because it provides a completely new perspective, eventhough I have to say a little weird observation....
willcode4beer replied ago:
I think one of the bigger points is what I like to call "logic reduction".
Basically, this means, "is there a more simple way to do it?"
Often while refactoring code, I try to eliminate conditionals and loops, not as dogma, but as a way to simplify the code. Often, complex logic is created to make something simply work. Upon refactoring, the complex logic can be reduced and simplified. Performance gains are often a side effect. Maintainability and stability are the major goals.
Jevgeni Kabanov replied ago:
This is just stupid. I agree with the sentiments ("if" and "for" are too low level constructs for every use), but not the solution. OO is not meant to replace control flow structures, it's for higher level organization. Functional languages have great facilities for higher order data manipulation, which is what you need (i.e. they want map and filter and try to emulate it in OO, that's been done before a 100 times, always unsuccessfully). The word they are looking for is Scala, not Java :)
Voters For This Link (13)
Voters Against This Link (19)