Why I'm glad I learnt the basics
blogs | main site
description: Why I'm glad I learnt the basics
Today, I was diving into threads, processes, messengers and databases. And at times, I was glad that I studied C, and Operating systems, and the other basics. It helped me a ton of times, as I tried to optimize the operations and shave off a few more milliseconds.
I’m sure a lot more people understand metaphors and examples when they are done about cars. And so I’ll try to form one for this as well.
Imagine you are the driver of a car which makes frequent journeys between places. It’s all a part of your business. One day, you’re driving the car, and for some reason it breaks down. Or, it has some problem – maybe the engine isn’t working properly, the engine check light is on, or the mileage isn’t great. The next step you do is to call in a mechanic to look at the car. The mechanic knows the internals of every part, how it works and why it isn’t working in this case. He fixes whatever is not working, and you get back your car.Compare this with a person who knows something about cars – how they work, what causes them to break down, or what ‘maintenance’ is about. This person will do all kinds of things, with gears, breaks, fuel, oil, etc. to keep the car in a good condition. That’s why you have some cars from decades ago working in very good conditions. They’re maintained well. And it’s only possible because someone somewhere knows their basics. The same analogy is applicable in programming.
One can only do things up to a certain level before you fail to understand the underlying mechanisms a.k.a. the basics.Programming in Java and Python is intuitively easier, because they offer a very high-level abstraction in terms of what is happening behind the scenes. On the contrary, every C function has to be carefully safeguarded against performance, and safety considerations. Sure, it’s more work, but it also teaches one to be aware of what the function are doing rather than what they are returning. Programming for Android, its somewhat back to basics. Because I now have to think about performance, and considerations, and side-effects.
If I call a particular function or library, is it doing to hamper my performance. Every millisecond saved is a huge consideration. That’s why, games and other performance applications are still written in C++, which is still ultimately C. The basics part teaches you think in terms of the machine, rather than just a code line. It teaches you to analyze every possible side effect, because at the end, you have to choose the one which gives the best performance.Writing an application, all the GUI parts, and all the services that download the files, do all the nifty tasks are all ok.
There’s not much to think about but how your application ties in to everything. But when one is designing a library or a framework which every app is supposed to query, it becomes critical that the results are shared back in the smallest amount of time. This is where knowing the basics helped me a lot. I know that certain operations are faster than others, even though the results returned are the same. I’ve tried to save the references and reuse them, just so the system wouldn’t have to garbage collect them, wasting my time. The loops have been optimized for least iterations possible. Sure, the compiler might do that anyways, but I can’t rely on that.
All these nifty little tricks are from the days, when C was the primary language of coding. We learned to handle pointers with caution. But a world of programmers screamed in glee when Java didn’t sport them. But that doesn’t mean that the world is free of troubles. We now have references, which although much simpler and easier to use than pointers, are also much more sly. I have to be careful to know whether the reference I’m holding is the same one held by the other side. If not, then I’m going to run into errors at RunTime.
A lot of the things are what is called “programming common-sense”. One doesn’t have to specifically learn C, or Operating Systems in college to know them. But like I said right at the start, they’re the basics. And knowing them is going to be very, very helpful to do things.