Less is More

Despite my agreement with Matthew's "Fat Models are Good", he starts to bump up against another point that I run into regularly:

Less Code is Better

End of Story.  There are no exceptions.

Sure, lots of people want their code to be extensible, flexible, powerful, handle 100% of the cases flawlessly, handle all input, fail gracefully, be readable, blah, blah, blah.  All of those are great goals but Less Code (that still meets the specs) is still better.

If you have the choice of writing a new function for something or copy/pasting -vs- using one already in your library, I would say the answer is to use the existing one.  Everyone knows of the problem with copy/pasted code.  As soon as you discover a bug in one place, you have to remember to fix it in all occurances or you're going to be copy/pasting forever.  It gets dramatically worse once the different instances of the function resolve different issues.  Eventually you end up with all these "branches" of very-similar-but-not-quite-the-same code that have to be debugged, tracked, and updated indepedently.

By education, I'm an Electrical Engineer.  While I haven't used my education to build a proton pack (... yet), the constantly-evaluating-and-improving-things-nature of my engineering side drives a perverse joy:

I Love to Delete Code

For every line of code deleted...

... it's one less place for a bug to hide.

... it's one less thing anyone has to work to understand.

... it's one less thing anyone has to debug.

... it's one less thing for the PHP engine itself to parse.

I couldn't agree more! The

I couldn't agree more! The tempation to write generic code too early is common too. It's better to generalise when you have two (or more) uses for the same code though. No point in guessing about how the code will be used in the future. (Unless of course, it's blindingly obvious!) Regards, Rob...