Tuesday, 3 March 2009

4 ways to become a better programmer

Leonhard Euler by Emanuel Handmann.
Image via Wikipedia

Becoming a better programmer is not only a laudable goal for improving the quality of the science you produce but programming is a great skill to have if you decide to leave the academic world. This post covers ways of becoming a better programmer.

1) Read

Reading about coding is a great way of learning new techniques, algorithms and ideas. This is pretty obvious and probably one of the reasons you are here, now, reading this. Books, articles and blogs are all great places to learn how to improve your craft and we have several recommendations here.

However, reading also covers another aspect, reading code directly rather than reading about code. Code is the ultimate source of how programs work and learning how to read code is an incredibly valuable skill. While this doesn't sound like a difficult skill different styles, optimizations and the availability of comments make reading code, even in the same language, very difficult. The ultimate example of this is the International Obfuscated C Code Contest (although it's pretty dead at the moment), the code is compilable C but is made as totally unreadable as possible. Final proof, if it were needed, that code serves two masters and they have different needs: compilers, which only care about syntax and semantics, and humans who need to readability and maintainability. A great exercise is to take a block of obfuscated code and make it readable again. You'll really understand the code at the end!

2) Write
Reading is easy to do: fire up your browser, go to the library or sit in a bookshop and 'browse'. You feel like you are learning and it's not even that difficult. The problem is that you aren't practicing the craft and that is where you'll encounter the real problems and learn the real solutions. Book and blogs can help you find the answers but you have to have the problem to solve in the first place. Like learning any new skill, it is important to stretch yourself and try new things. An easy and effective way to do this is to find an interesting problem outside of work and solve it. It doesn't matter if it has been done before or even how well you solve it (see Review below), the act of trying something new will teach you a lot.
If you want small bite sized problems, and have a mathematical leaning, then Project Euler is the place for you. Project Euler consists of a growing list of mathematics problems that are designed to be solved using a computer. They follow a rough series where the solution to one problem may suggest solutions to the next. A neat feature is that once you have submitted the correct answer a discussion thread is opened up so you can see how other people have solved it, an invaluable learning resource.

3) Review
The scientist-programmer often works alone and can end up finding all sorts of 'eccentric' solutions to problems. Having your code reviewed is a great opportunity to learn new techniques, find hidden bugs and helps you keep your code clean, in the same way that having your parents visiting is a great way to keep your house clean. It may sound trite, but knowing that somebody else is going to be looking at your code is a very effective way of keeping you doing things the right way. Otherwise, it is very tempting to cut corners and just get things done which is the slippery slope down to having spaghetti code.
The three things that are needed for a good code review are constructive criticism, an open mind and the realisation that your code is not you. Being able to let go of your code, and have it constructively criticised without feeling defensive, is vital otherwise you will feel that you are being personally attacked and this is not conducive to getting feedback.
If you have a more experienced programmer to hand then getting them to review, and discuss, your code is great but a group of similarly skilled people can, and should, review each others code as they will learn from each other. The Wikipedia entry on code review has links to resources on how to conduct a good code review.

4) Contribute
The open source movement has made an incredible impact on so many areas of computing that it is easy to forget that a lot of it is driven by people donating their time and expertise. Contributing to an open source project is a tried and true way of improving your skills. Find one that has an active community and is working on something you are interested in and start to help out. It is best to start small, find a few small bugs, fix them (and don't create any new bugs!) and get them accepted. Bingo, you've helped make the world a better place and hopefully you've found some like minded people that can help you get better. If you are looking for a project to help then freshmeat or sourceforge are great places to start looking.

It is very easy to get stuck in a rut doing the same thing over and over but it is important to try new things, to push yourself and to learn. Reading, writing, reviewing and contributing are all great ways to get you out of the rut.

Reblog this post [with Zemanta]


  1. [...] Via FriendFeed: 4 ways to become a better programmer 2009 March 3 tags: help, programming by jwinget Link to the source article [...]

  2. 5) Experiment different programming languages to see what suits you better. Also, it is better to think "outside the box" to fix some problems

  3. Great article.

    It would be nice if it was continued though, although it serves as a good introduction to better programming techniques

    It's amazing how many times people forget that they can read!!

  4. "Being able to let go of your code, and have it constructively criticised without feeling defensive, is vital otherwise you will feel that you are being personally attacked and this is not conducive to getting feedback."

    Agreed! The key is for everyone (reviewers and the author of the code) to understand that the code is being reviewed *not* the coder. A white paper on the social effects of code review is available here: http://smartbear.com/docs/CodeReviewSocialEffects.pdf

  5. [...] 4 ways to become a better programmer | Programming for Scientists [...]

  6. [...] 4 ways to become a better programmer Programming for Scientists (tags: programming) [...]

  7. [...] the last post we covered four fundamental ways to improve your code: read, write, review and contribute. This [...]

  8. I try to do all of these things, especially 1, 2 and 4.

    However, it is not easy to contribute to an opensource project, as it requires great 'diplomatic' skills.
    You must have survived for at least one or two years in usenet, or have great patience, otherwise, you will end up by giving up, as contributing to open source projects maintained by scientists can be especially difficult.

  9. Excellent article. I would add 'Test' though.

    The act of writing tests at different scales (unit, integration, functional) makes you think about structuring your code into well-defined units with clear responsibilities. And it discourages practices like shotgun debugging that are all too common in part-time programmers. (Myself included, until fairly recently)

    And a variation on number 4 -- make your own research code open-source. It makes you think about writing code that others can understand, good documentation, following a clear change-build-test-release cycle etc., and forces you to use source control and issue tracking.

    Inaugurating a new project in SourceForge isn't actually that hard.

  10. how will i understand question in programming and answering them,easy steps I want to know

  11. Some great advice there on improving as a programmer. I have been procrastinating working on an open source project for some time. I hope to begin as soon as possible as that is the best way to improve myself.

  12. Good article, thanks.