Friday, July 6, 2012

Programming thoughts II


Some thoughts on what I learnt about programming this week. First when I started programming in rails, the challenge was to understand the syntax and semantics and how to use them in the problem. But now that I am fairly decent in working on Rails, the next challenge that I encounter is how to code better. There are different definitions of better code. Have you ever seen the source code of some of the popular gems in rails? When the documentation of a particular gem is not available and you have to search through the source code to look for the methods that help you solve your problem, the first thing that is easily noticeable is the comments that lie above every method describing the use of the function along with the one or two examples that help understand the description better. Also the comments are so succinct and concise that you look at them and you know how to use them. 



Secondly comes modularization and naming. The names give the impression that they are easy to incorporate in your code but my experience says that they are one of the challenging aspects of programming. In OOP, modularization strategies are available in bulk but the challenge is to know each strategy when need arises and how to choose one over the other. Firstly it is indispensable to know the programming concepts to its smallest detail. Then only one make sound decisions on which to use where. Secondly, if your code is too big, divide into segments in such a way that you, along with any programmer can just look at the code and understand its functions in and out. Also the method names should give an idea of the underlying operations performed. Every functions written should be as independent as possible. By independent, I mean that they can be used anywhere in the module without thinking on what dependences should be taken care of along with it and what side changes should be done to the structure to incorporate that function.

Programming thoughts I

Today I want to write something about the conversations I had with priyank about programming. Our talk revolved around who can be called as true programmers, what do we mean by good code, when can someone be called as an expert programmer? Well the thoughts that resulted at the end were mostly his observations as I was merely a listener most of the time.

It all started with finding an optimal solution to a problem in www.codechef.com related to prime nos. Unable to think more about the problem (I wasn’t able to give him some hints to solving the problem because of my weak algorithmic skills), he started asking questions on the credibility of OO programming. He wondered why  some people focus more on making the code more object-oriented rather than focusing on the efficiency of the solution. I replied that it is important to focus on object-oriented-ness because it makes the code more understandable, it ensures that the modules involved are as independent as possible, making it more usable. And most importantly I said that most of the problems involved in our daily jobs are not algorithmically that complex that we have to invest such a huge amount of time in finding the most efficient solution. Instead the problem at hand is how to code such that if someone is editing your code, he doesn’t need to come to you at every point asking you what you did. Code in such a way that there is little need for others to seek help i.e it should be understandable (and yes it’s the code itself and not the comments that should suffice).

Then the conversation shifted on who can be called as a good programmer. There are many websites devoted to problems requiring to finding the optimal solutions to a problem. When companies like directi appreciates an employee who has solved a complex problem in just 0.65 millisec in its presentation, it does mean that a good programmer is the one who has the ability to crack the problem using minimal system resources and time. Also, it is essential to gain expertise over a programming language one is coding in. Because a single task can be done in different ways using different programming constructs and methods. In some of the cases, it’s the api calls of that language that make the difference in the efficiency of the solution. If one doesn’t know how the api calls perform their job, he/she can’t decipher the effectiveness of the solution. In the country where there are bulk of IT guys available to do the job, it’s these that separates one from rest. Its not what one does, it’s how one does that differentiates him/her. And we at last came to a conclusion that an expert programmer has two things:
1. A drive to always look for the efficient way to solve a problem
2. He/She should have a sound knowledge about the programming constructs so that he can meticulously utilize those methods over others when needed

These were just the thoughts that were shared during our tea break. So it is highly possible that most of the advantages of OO programming, or maybe our belief in expert programming be wrong and inaccurate