I am sure that every software engineer has had somebody more senior than themselves say that they should write something correct the first time and not have to go back and correct their earlier work. I know I have. I think there is a time and a place that this statement holds true. For instance, in a project at work, where time is critical, getting software correct the first time is desirable as this saves vast amounts of time when it comes to testing, debugging etc…
However, this is easier said than done. Writing something correct first time, especially when it is an area that you do not know very well, which is often the case in the work place, is very difficult. So how do we write once, write right?
As an analogy, imagine a drummer. She practices the drums every day, practices lots of different styles, techniques and can play all of the music in her collection. One day she gets a phone call and is asked if she can turn up at a venue and play a piece of sheet music correct first time, an original piece she has never seen before. Of course she can. The general concepts are the same as the music already in her collection, she has practiced them, recognises them as soon as she sees them on the sheet and can play them with relative ease. She even knows the potential pitfalls of certain arrangements and has worked out her own ways of avoiding them. All this talent has come with practice and experience that she has built up in her years as a drummer.
Lets get back to the software world. Write once, write right is great for the work place. But like the drummer in our analogy, practicing software at home, learning the styles, techniques and pitfalls is the best way to be able to write once, write right in the workplace. The place to make mistakes (and learn from them) is at home.
So how do we practice programming?
I have recently compiled a list of software languages that I want to learn. All have different benefits and strengths. They also all solve different problems (just like a plumber would have lots of tools in his bag, one for every job….some things might do more than one job but you get what I am saying).
I have books on most of the languages I want to learn and a collection of online resources (just google your chosen language and you will be sure to find hundreds of tutorials). But how can I practice? Just like our drummer had file of sheet music, we must have a file of programming problems. Luckily, some very nice people on the internet have already created these files for us, packed with hundreds of programming problems. The best part about most of them is that they are not language specific (this is a pro and a con as the non-language specific ones do require you to enter a final answer, no code need submitting)
Here are a few of the sites that I find most useful:
http://projecteuler.net/problems – maths based problems where you write a program and submit an answer.*
http://www.spoj.pl/problems/classical/ - a range of problems (the input and expected output is given in the example)*
http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=1 - again, this site has a range of programming excercies and the input and expected outputs are given.*
This is certainly not a comprehensive list, and googling your chosen language along with “programming exercises” is sure to turn up a hole host of sites that you will find useful.
There are also online courses that you will find, such as:
http://ocw.mit.edu/index.htm - MIT open courseware has some great materials online for programming and computer science.
http://www.db-class.org/course/auth/welcome - Stanford are running a series of free elearning courses. This is a link to the database class, all the other classes can be found at the botton of the database class page. I did the database class on the last run. The interface is great and you will learn a lot. The downside is that it is timed, there are online tests and the schedule can be demanding if you have a full time job and a social life as well. (you can just sign up and do it at your own pace if you do not care for the statistics of you vs’ all the other participants).
*the cons of these types of learning are that they do not mark the code, just the output.
These types of online materials are great to get you thinking about the code without having to have a specific motivation. I believe that the best way to use these resources is to repeat each exercise in a variety of languages to see which one best fits the problem. This way you will learn multiple languages and have the knowledge and the tools to make similar decisions in future.
In Summary, just like any other skill, software requires practice, there is only so much you can get from reading a book, doing a variety of programming exercises in a variety of languages will give you a programming tool box that you will be able to call upon at any time.
Pick your language, and start practicing!