View Single Post
Old 11-24-2010, 01:43 PM   #27
Perry Winkle
Esnohplad Semaj Ton
 
Join Date: Feb 2005
Location: A little south of sanity
Posts: 2,259
Quote:
Originally Posted by Flint View Post
I find it hard to argue with the fact that what I've done works. Because it works.
Your solution is perfectly acceptable for a classroom assignment. But you might get your ass kicked in a code review for settling for "it works."

In the real world, you want functions to have as few side-effects as possible. Ideally, a function would have no side-effect other than its return value. Some languages even ENFORCE this restriction.

Your solution depends on side effects. This makes it harder to reason about how and why it works. Happy Monkey's does not depend on side effects, and is easier to grok.

(I hope this post doesn't come off as critical. I'm just trying to add a little more to think about.)
Perry Winkle is offline   Reply With Quote