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.
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!
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.
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.
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.