in Technology

Comments before code

I used a very interesting technique in my college exams. I knew how long an answer should be for 10 marks (or whatever). After I got the question paper, I would decide which questions I will answer. Then take the answer sheet and start writing down the headings for each answer – leaving enough gap to fill the actual content. Once I have completed writing the main points / headings of each answer, I come to the first answer and start filling in the gaps.

This made me ask for supplements within the first half an hour! People turned their heads at this! But it worked wonderfully for me. I could complete the exam on time, and did not have to think about the answers while doing the “gap filling” 🙂

And I do that with code now!

All my code starts as comments. I would put the whole logic of the module as comments in the file, and then go and fill in the code after that.
When I start on a programming module, I think through it and have it ready in my head before I actually code. As a matter of fact, I keep telling people to “run the code in your head, before you run it on the computer”. I also tend to scribble complex logic on paper before I do code.

Working on a complicated logic yesterday, I realized pseudo code can be a great tool to share logic with other people. Rather than keeping it to myself, I can sit with the team, think up a logic, and document it as pseudo code. Simple sentences that would describe the steps in a module / function. When I am sitting in a meeting room, I tend to do this in a text file. While with developers, I would go ahead and add it as comments. The devs then can fill in the code later.

But it is extremely important that these comments / pseudo code is readable and understandable. Otherwise it serves no purpose.

Just another thing why communication skills are so important in programming!

PS: And that’s why I think Ruby and RoR have become so popular! The code is like pseudo code! 

Write a Comment

Comment

  1. “Then take the answer sheet and start writing down the headings for each answer”

    Smart … Btw every 3rd B.Com student does that … Atleast I did that …

    “This made me ask for supplements within the first half an hour”

    I can so very relate to that … Thou I never tried this in economics exam … marketing and advertising were fine …

    nice post

  2. Hey Ankur.. I thought I was the only smart guy doing this 😉 None of my friends did it. People used to “fill in the gaps” for individual answers, not the whole exam!

    And well, I did it for eco too 😉

  3. if u did that for eco too sp in T.Y.B.Com … I would say Hat-Off … simply coz Eco was one paper where I found it time consuming to arrange the answer content into relevant sub-headings … Thus i stuck to writing essay style answers …