Optimizing Code for Development Time

Another way of optimizing code is to save development time
Photo: freeimages.com

A while back I made an interesting personal discovery, and I want to share it with everyone in the hopes that it’s as useful to you as it is to me. Hi, my name is Ryan, and I like to develop software in my free time. Mostly, I like developing games.
It all started when I recently looked back over some of the work I did before I went to college. I was actually very impressed with my past work, too impressed. The games I developed before school were really putting my current work to shame. I started to think about why that might be. I figured I was busier now that I have marketable skills, and let’s be honest here, you can never play enough Dwarf Fortress.
I started to look around for techniques to speed up my development time while maintaining a relatively high quality of work. I stumbled across this video, and it blew my mind. It turns out I was wasting all my time trying to optimize code that most likely did not need to be optimized. See, optimization is a process of speeding up code execution by sacrificing flexibility and maintainability of the code. Basically, your code runs faster, but you will most likely never want to touch that part of the code again, it’s too ugly and adding new functionality will break it.
What changed in me from before college to after college? Simple, I know more tricks now. I know how to optimize better than ever before. I learned lots of things. And I was trying to apply the best solution to every problem I came across. I didn’t really see many of these things as optimizations, things like using a linked list vs. an array. It is subtle, but I was trying to optimize my design before even getting to writing code. I would think things like “I will only add and iterate over this list, so a linked list is a perfect fit.” Projects change though; all of a sudden that wonderfully quick linked list is causing a lot of ugly code and special cases. Soon you are writing a function to find the nth element and you are asking yourself “Why did I think a linked list was a good idea again?” My pre-college self is writing the simplest code to solve the problem at hand, mostly using arrays and if statements. If the code started to get gnarly, I would refactor it. I could easily refactor it, because it was all easy to read and understand. I would test my code, find the points that needed to be optimized and then optimize only those parts.
Don’t get me wrong. I would not be nearly as skilled today if I didn’t go to college, that is a given. I think knowing how to optimize makes you a good developer, however knowing when to optimize makes you an amazing developer. Most developers think of optimizing for memory or CPU. There is actually a third way to optimize; optimizing for your time.