A little bit of this and a little bit of that.

Just another WordPress.com weblog

A little bit of coding

Posted by amitbehere on April 11, 2008

I have been super busy coding for the last few days. We are in the middle of re-architecting the Yahoo! Media Player. I consider myself an average coder but a very persistent and decent debugger. It means I can find errors quickly and easily.

My personal experience of programming has been as follows:

1. As a very new, raw programmer I used to write code and BE SURE that it was going to fail. And ofcourse, it would always fail. I would fix the first error,  but the code failed again at the 2nd one. This iterative approach meant that it took about 4-6 passes to be code complete depending on complexity.

2. As an intermediate programmer, I used to write code and look it over a few times to make sure it was right. I would think, maybe it will work, maybe it will fail. It almost always failed. However, when I fixed the error, I would also be proactively looking for more errors down the line. This approach allowed me to write decent working code in about 2-3 passes.

3. As a resonably decent programmer now I write test cases, put try- catch blocks and review every line of code carefully before moving on. My style has improved and every once in a while I will write a fairly big piece of code that just works. It is beautiful however the frequency is about 1 in 5.

There are very good coders I know who never err. I am not sure I can be as good but I do not think that it is NECESSARY that I be that good. However I could definitely be better than what I am right now. I want to eventually be able to write solid, maintainable code that people after me will understand. Some people, actually a lot of people, write very efficient and optimized code that is unnecessarily complex and hard to understand. That is not good code. Being a good coder involves doing a lot more than writing fast, optimized code. It involves putting more thought in design, architecture and documentation.

To summarize:

1. Design and design review (VERY IMPORTANT). Even before you write code.

2. Code and code review with peers.

3. Include atleast rudimentary documentation on first pass (never leave big chunks of code undocumented)

4. Most functions or pieces of codes are step-wise. Include comments like /* Step 1: Check the input */ /* Step 2: put input into code buckets */ /* Step 3: Inspect code bucket one */ and so on and so forth.

5. Accept that you will never write perfect code. Code is a living being. It grows from infancy and gains strength over time. However if you over-code, it will get old quickly and die.

And finally, the most important lesson I have learnt as a software programmer

A lot of people may review your code badly and point to book examples or traditional coding methodologies to support their point. If they are right, fix your code. However if you still truly believe you are right, follow your heart and DO NOT CHANGE. If you are responsible for a piece of code, you have the right to decide how it is going to be. No matter how senior the reviewer, he or she can only advise, NOT order. As with everything in life, trust your gut.

HAPPY CODING!!

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>