3 ms·
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 t
by mikegioia 14y ago
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.
- RyanZAG 14y agoThat 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.