Every programmer has heard the phrase “Premature Optimization is the Root of All Evil”; make no mistake, there is a reason this phrase is so often repeated.
Prematurely Optimizing an algorithm can lead to all sorts of trouble; including but not limited to boundary case bugs, ugly/unreadable/unmaintainable code, investing too much effort on a solution which is not optimal anyway, and stuttering while coding the resulting solution. This post will focus on the latter example.
Recently I was faced with a relatively simple programming challenge. As is often the case with these kinds of challenges, there was an obvious answer which works but, as usual, it was not the ideal solution to the problem at hand. Being a programmer and also being concerned with the execution time of my solution I started thinking of different approaches to attempt to minimize the runtime of the algorithm.
This is usually a good thing, however I came upon this stage of problem solving before coding the base solution and the optimization ideas distracted me as I was coding the solution. In the end I managed to solve the problem but it took me longer than a relatively simple problem such as the one that was at hand would have taken me and I stuttered significantly during the implementation of the solution.
Which brings me to the point of this post. I’ve also done some interviews for development related candidates recently which involved asking the candidate a variety of programming questions; in these too, I’ve seen people stutter with simple problems in an attempt to optimize any and all solution proposals immediately instead of solving the problem, making sure it works and THEN optimizing. As an interviewer this left a somewhat negative impression of some of the candidate and, given the nature of these interviews, it is standard practice to pass on candidates you’re not sure on.
If I had been interviewing myself when solving the programming challenge I mentioned earlier and that were all the exposure I had to myself, I believe I would have had doubts on the coding abilities of the candidate in question (in this case, myself). Just something to consider during interviews, programming competitions and everyday coding.