Solve Problems

Introduction

A programmer’s job is to solve problems. During the process you may find that some things need to get refactored or a new approach is required altogether. It is natural to take some steps to reduce the amount of time having to rewrite things by trying to go for the final result first. I find that this sort of thinking can overcomplicate the solving process and reduce productivity.

Usually one’s understanding of a given problem is quite low at the beginning. Going at the problem as if you did have full understanding would lead to an incomplete answer. Trying to pre-solve the problem can also be disorienting as you may eventually find that the wrong problem is being solved. So I believe that some time should be dedicating to exploring the problem and not focusing quite as much on your final product.

Quick and Dirty

One way to ensure that no time is wasted is by writing only the code that is absolutely necessary. Speculating about what might be useful in the future can often lead wasted efforts and unnecessary complexity. One example I have is when I wrote a general free list for a game I’m working on. It turns out that I didn’t use nearly as many I thought I would and that free lists are an extremely simple data structure. Writing the general free list and trying to use it took much more time than just writing the basic code a few times.

While code quality is fairly important for maintainability, there is almost no point in tidying up code that will inevitably by deleted later. Nobody likes poor code but perfecting variable names and line count really shouldn’t be a priority when the problem is nowhere near being solved. Leaving in-depth comments about code only you will see only wastes time and leads to several out-of-date comments, only increasing confusion.

Exposing Complexity

When working on a problem, it often splits into several subproblems. Working on the hardest parts of a problem is usually not a particularly efficient use of time. Going all in on one implementation is risky early on as a facet of the problem may be uncovered which renders the solution useless. Sometimes working on something more imminent is the best way to go. I do think it is a good idea to do basic bug fixing and document your observations to expose the hard parts of a problem so that it may be solved at a later time when it is more important. 

An example of this in my game is in the asset management system. If an asset gets unloaded in between when a system calls for it and when the asset is used, garbage data would replace the original asset data. The solution to this problem might be very complicated partly because multithreaded contexts are involved. The circumstances of this occurrence are very rare and the consequences are not very severe. By just acknowledging this as a potential problem, I can ensure it doesn’t impact the final game, if the system sticks around, but work on more pressing matters in the present.

Compression

Once a solution is in a decent spot, then commonalities throughout the codebase can start to be collapsed. This ensures that any general systems have proper context and so can fit the solution appropriately. Keeping a compression oriented programming mindset can help mitigate the amount of time you spend doing unnecessary work. It also helps you to shape your solution around the problem, rather than the other way around.

Lofting code into functions or systems only when necessary also reduces complexity. By hesitating on abstractions, you can stay close the problem until you feel confident in your understanding. Then the priorities can shift into maintainability and optimization since the problem is well-defined and in a working state. Of course there is a balance as horrible code and algorithmic inefficiencies can be hard to work around.

Conclusion

Approaching difficult problems requires constant decision making about what to do next. Staying focused on the actual problems you’re presented with helps you better understand them. Being cognizant about exactly how you’re spending your time can help to make sure that you are making constant progress. I find that staying focused on the problem at hand makes me more productive and happier as I waste less time. See what you can do to reduce the amount of speculation you do and make sure your time is well-spent.

Next
Next

Life Without Recursion