For my birthday this year my wonderful girlfriend gave me the book Beautiful Code. It is a collection of extremely well written and efficient snippets of code that are analyzed by the developer who wrote them or were involved with them. The goal of the book is for the reader to understand how and why each master coder solved the problem they are faced with. So far I’ve absolutely loved the book even though a good part of the actual code goes over my head.
As I have been reading I’ve been trying to think of ways that I can take the ideas and concepts of the book and put them into practice in my every-day work. Some of the chapters are harder to see how I could implement into my work flow but normally I can at least gleam ideas that I can use when working on code. The most inspiration chapter for me so far was titled “What was the most beautiful piece of code you never wrote?”. This chapter focused on making things as short and simple as possible. Going along with this mentality is a great quote from Jason Fried, “I don’t like the phrase less is more, it implies more is better. Less is less”.
Looking back on the code I wrote even months ago its extremely obvious how inefficient and bloated my code is. Part of this is due to my relatively little experience but I think a bigger part is that I rarely spent time refactoring code. Once I get a section of code to work, I move on. Now a lot of times I have to move on because of a time restraint, but looking back on some of the parts of my code that I didn’t spent any time optimizing, these were the areas of my code that caused me the most problems down the road. Even if the bloated code didn’t cause bugs, it did make it much harder to upkeep the code when I needed to add a new feature.
The other chapter that really stuck out at me was about testing. Testing is something that I know I should do but always put it off till the last minute. This chapter talked about test-centric development, meaning rather then writing code and then writing tests for that code you write the tests first then write the code. This definitely confused me a bit at first but as I thought more about it the more sense it made. That is the other idea that I would like to try to implement into my every day coding.
Hopefully I will continue to post what I think of the rest of Beautiful Code as I finish it.
