What computer science teachers don’t teach you
Most courses starts with simple topics and gradually introduces complex topics. For each topic, a simple problem will be used to illustrate the complex solution. In many cases, where simpler solutions exist, teachers fail to point that out.
I believe this is a problem. The teachers are training their students to look for complex approaches, instead of searching for simpler solution.
For example, if you are programmer, you would have written code to compute the nth Fibonacci number.
F(n) = F(n-1) + F(n-2) for n >= 2 and F(0) = 0, F(1) = 1.
In your programming course, when loops are introduced, you would have written something similar to the following code.
There is no issues with this code. It works. Simple to write. Simple to explain.
Once recursion is introduced, the same fibonacci code will be rewritten either as an example or as an exercise.
Very simple to understand. Very short. But horribly slow because the complexity is O(2^N)
After explaining why the previous code is bad, a new topic memoization will be introduced. Just store the previously computed value.
This code is much faster. A bit more complicated. Now you have learnt a new concept. The teaching ends here.
What if, there is a simple and faster solution. Only needs some basic math operations. A simple Formula.
It is one line. Unfortunately, this doesn’t use any important programming concepts. Therefore, no one teaches it. Teachers teach topics, not how to find the best solution when there are many. We have successfully taught the students to find the complex solution to the simple problem.
It can be worse…
Given a problem, instead of learning about various approaches, we immediately jump to code.
It was in 2008. There was a senior engineer in our team. He was a backend engineer. We noticed a bug. When submitting a form with a text field filled with large text, it gets truncated. He learnt that GET requests get truncated because of url limits.
He jumped to the solution. True Story!
- Break the text into small chunks
- Send each chunk with some AJAX
- On the server, merge all the chunks.
How hard is it? Except, we want to keep the server stateless.
- Store the chunks in a persistent storage. It was 2008. Bigtable was not hard. But, what happens when the subsequent requests goes to different regions?
- Cross-region replication might be eventually consistent, but not suitable for this use-case. Solve this with even more complexity.
Weekend was over. Proud about the design, he worked through the weekend and on Tuesday, he announced to the team during the status update, how he solved this complex problem. He was enthusiastically explaining, until another teammate asked,
“Have you tried POST?”