News for hackers. Stuff that matters.
Re:Code May Work, But It Still Might Suck by mikegioia on Friday March 29, 2013 @01:19PM (#5461760)
I could not agree with #5 any more. I can't tell you how many times I see default parameters being set incorrectly (i.e. defaults to a corner case so you have to set it on every call). It creates code that looks like:

foo( $data, FALSE, FALSE, FALSE, TRUE );

That drives me nuts.

Re:Code May Work, But It Still Might Suck by RyanZAG on Friday March 29, 2013 @01:46PM (#5461925)
That code example completely breaks rules #1, #2, and #3 completely. There are probably a lot of ways to refactor that code so that it's still specific. The most common method is to define constants for each value and then pass them in as 'flags' to the method. For example:

  foo( $data, Foo.NEVER_USE_CATS | Foo.DRAW_SQUIGGLIES );
This pattern lets you add in new parameters easily and makes it very clear what parameters are being passed to any function and set sane defaults. This style is widely used in Android to good effect.