Paul Vick posted these Seven Rules for Beginning Programmers earlier this week and I have been thinking about them a lot. They make sense to me. As a professional developer you have to understand that these are the rules for beginners. The last item concludes with “You may go beyond these rules after you have thoroughly understood and mastered them.” It is important to remember that there are few absolutes but at the same time beginners need to exercise some caution while they are mastering the basics. Though honestly, even professionals should “Never use language features whose meaning [they] are not sure of.” Of course there should be fewer of those for experienced professionals than for beginners. Here is Paul’s list.
I expect some to take exception with something in rule 7 - “getting rid of the bad programming language habits you picked up at the university” After all isn’t the purpose of a university education to learn “the right way” to do things? Sort of. But the truth is that the types of projects that most complete as part of their education don’t always lead to best practices. The problem is size of the projects and also, in many cases, the artificiality of the projects. They have to be both small and somewhat artificial to fit in the concepts that are being taught. And in some schools software engineering is a dirty word (term) in computer science programs. That’s not all bad as long as people who become software developers understand that they have things to learn about design and about creating large scale projects.
Copy and paste is another interesting case and I am glad to see it on the list. There a huge temptation to copy and paste. Sometimes the idea is to use the new code as is in which case one should really think about encapsulating the code in a method, function or subroutine. Or the idea is to copy/paste and then make a little modification. The problem with that is that one invariably misses something in the process. And of course you also have the possibility of copying something that is wrong, buggy or just plain not as close a fit as you thought. Copy/paste means trouble later if far too many cases for beginners to use it as often as they seem to like to do.
So what do you think of these rules? I see that Garth is planning on posting them in his lab. Would you consider doing the same thing?
4 and 5 are the two that the kids love to abuse. They find a chunk of code that does what they want and then copy it into their program willy-nilly. I tell the kids to not reinvent the wheel, to use code snippets they find on the internet but have a good understanding of what they found before they use it. The kids learn a lot when they have to tear apart someone else’s code.
Hmmm. I'm not convinced that mapping good advice from one field to another is always a win. Some aspects of programming are a bit like writing, but by no means all. I can why short methods might be a good idea, but not to the point that programs are broken into chunks just to obey this rule. And rule 6 is disasterous, very few beginning programmers would understand it at all. And by the time they did understand it, it would not be required.
Writing a list of rules like this might make people worried about more than they should. In my experience people learning to program often fret about whether they are doing the right thing or not. Adding more rules (and then saying that they can forget some of them when they become "proper" programmers) is not really doing them a favour.
My preference when teaching is to get them to write something that mostly works and then go through it with them making all the salient points above in a context that they understand. The other thing to remember is the sad fact that the customer won't care a hoot whether or not these rules are broken in the solution as supplied. If it works and does what he/she wants then that's a win.
@Rob Miles - Your last two lines say it all. Code should be clean and supportable by others, but in the end you must satisfy the customer with working software.