Monday, July 29, 2013

The importance of habit and mathematics for programmers

I  think I am in the right position to write an article on the importance of mathematics in my career. No this isnt a rehash of Steve Yegge's Math for programmers article. The outline is similar but this is based on my own experience.
I was lazy when it was the right time for me to study. I wasted my high school days ,playing games on my computer , reading Sci-Fi novels and bumming time with my friends on the road , hanging out like there is no tomorrow. We hung out till late night ,returning home often late.  I rarely gave a shit about my studies , by the middle of my final year at high school , I guess I should have realized that there is no way I'd make decent marks in the exam . Yet I was over confident , thinking that I still could burn the midnight oil and study in time for my final exam. I had this distorted view of the world where I believed that I was only a few hours away from learning everything .
All these dreams shattered on the day of the result . Confident of a rather decent marks in math , I was shattered when I saw my math results. low 70s . Not bad , but bad enough in today's world to ensure that I get stuck in a dump for the next 4 years wearing formal dresses  and being trained to be a corporate slave. I wanted out . Thankfully I got a second chance . A decent course at a rather good college. Some freedom . Yet I bummed most of my next 3 years too out of sheer habit.

I then realized at the end of the 3rd year that the reason I was failing to learn math was not because I was bad at math. It was because of the fact that I learnt to make it a habit to learn math the way its meant to be learnt . Unlike 10th grade CBSE where I learnt most of my subjects by reading the book like a novel in less than 30 mins , there is no way you could learn calculus or matrices just by skimming problems , theorems and solution. You have to work them out , find answers , break your head over incomprehensible solutions and hints . Its a mental exercise . I spent all my time in high school learning matrices without knowing what is a singular matrix. I just learnt it a few days ago. For a guy that dreams of being a Computational Scientist this is like shooting an elephant with a revolver . You are just going to get trampled. I spent a lot of time , reading problems , reading solutions , but NEVER spent time solving them .
I cant stress on the importance of maths in a programmer's toolbox enough. Imagine trying to build a bicycle without a spanner. Can it be done ? Even if thats possible , what do you lose in terms of time and energy  ? Math is the language of science. With a knowledge of mathematics you don't just learn about numbers. You learn how to use it to solve problems AND analyze your solutions. You have a powerful toolkit in your hand with which you can build efficient solutions . Some of you must have heard of NP-complete problems. Basically its a problem where the solution takes tonnes of time and for a problem of sufficiently big size it will take a time beyond that of humanity's lifetime . However instead of being defeated at the prospect of such daunting problems , mathematics gives programmers tools to solve a few problems in a (slightly) shorter period of time. There are ways to defeat problems in specific contexts even though you cant find a general solution for the set of such problems .
From measuring running times , to formulating proofs for the correctness of your solution to a problem , math is really really important to a programmer's toolbox.
Some of you might say , "but I don't work with mathematics . I work on projects that arent really mathy or too involved in computer science . I design websites and create software for online applications "
Granted , such projects are not too involved in math. But the very fundamentals of your software lies in mathematics. Why is a linked list slower than a hash table ? Why is merge sort preferred over quicksort or bubble sort ? Such questions are answers based on math. You are indirectly using the product of mathematics in your software. If it weren't for such tools we'd all be stuck in the stone age of computers , trying to make faster and bigger computers never realizing that math can help solve some problems faster by giving you a set of more appropriate tools. In fact to every programmer I'd suggest learning math purely for the profound enlightenment it gives when you can understand something that you take for granted .
And habit ? where does that figure in ? Well , its important to cultivate a habit for solving problems and trying to formulate your solutions before attempting to search for one . I cant stress on this enough . Granted solutions to problems are available all over. But the reason people learn maths is to enjoy the journey and not the destination. By solving you problems you train yourself to identify solutions and generate a heuristic for solving problems in the future . You discover patterns in problems and methods that are quite an experience by themselves . A habit of solving problems makes it easier to solve the N+1 th problem after solving N problems . You dont have to really push yourself to solve it . Your brain does it by itself. You learn the intricacies of a method and can find shortcuts and many other alternatives . It feels more like a walk in the park  on a cool breezy evening , rather than a sprint across hot concrete .
So if you are a programmer and you have problems like me learning mathematics , remember that it is never too late to learn mathematics . There are plenty of sites of learn . Khanacademy is one of my favorites as the videos are designed for young people and are very very approachable. Additionally I find some math lectures of MIT to be easy to understand too . So start learning math today 

No comments:

Post a Comment