Since I became a professional software engineer in 2006, I've spent a fair amount of time reading books and online articles about software. Most article were related to object orientation, web technologies, software design, testing, automation, Agile and Lean, etc. Last year, I decided to take a break from such topics on purpose. So, I cleared all my RSS subscriptions.
Instead, I thought I would revisit some of the algorithms that I learned during my undergraduate courses. It’s been a few years since I studied algorithms and I thought I was more seasoned to appreciate and solve some of the algorithm problems than in the past. So, I started with the dynamic programming problems such as: Longest Common Subsequence (LCS) and Knapsack Problem and found this solution in Wikipedia:
As a software developer, when I’m reading an article, if there is accompanying source code, my eyes automatically scroll into it skipping any textual blurb. It was the same in this case, and I must say, I noticed a few things here:
- The single literal variable names need some love.
- The code could use some logical grouping and naming to easily communicate what’s happening here.
I found this to be a UI problem. The algorithm itself is quite complicated for an average person to understand. However, we can probably reduce some noise with better naming or grouping. Here’s an alternate version of the same code.
I know this modified code is verbose, but I find it self-explanatory. Using descriptive names is not a new concept in software engineering at all. I wish we had our algorithm books with annotated source code like this, where it’s readable by humans.
Let’s use uglifiers and minifiers to do the machinification for us.