Coding Should Be Like Writing A Book
By Spicer Matthews
The story I am about to tell happens almost monthly.
I needed to add some complex functionality to a project I was working on. I did what any good programmer would do and searched the web for a library that already did what I needed. I found a great library and got to work. I was really excited this library was going to save me hours and hours of time (in the end it still did). As I was moving forward I discovered some bugs in the library. I was hoping to just be able to make a few fixes and continue on. After diving into the library I found the code very hard to read. By many standards the code was pretty well written, but you really had to go through the code with a fine tooth comb. You could not just easily skim the code and figure out what was going on. Functions were very cryptic and variables were short in nature and not very descriptive.
I get it. Programmers do not like to type. Saving keystrokes saves on finger pain. Again, I get it. We all learned that a line of code should never be longer than 80 chars long (well that was when monitors had tubes).
Everytime I find a library just like the one I mentioned above I end up just rewriting it. At the end of the day the logic is nearly the same. I have just written the code to be more descriptive and easy to understand. I like code to read like a book. You can quickly skim the code and understand what is going on. I also like my code to look pretty. If you printed it out and hung it on the wall it would be pleasing. I find code starts to look like crap when people wrap too many lines, or add too much logic without a few comments to break it up. There should be some symmetry to code.
Love me or hate me for it, I am going to continue to write very long descriptive functions, clearly define my variables, crazy long database column names, and add some sexxy curves of symmetry to my code. Oh, I almost forgot, don’t give me crap about code bloat and performance. There are always bigger performance fish to fry.
<?php echo $this->readers->ThankYouForReadingThisBlogPost(‘You Rock!’); ?>