The other day at work, I don’t know what re-opened the whole code generation tools discussion.
Personally, I have a strong conviction that no code generator, no matter how advanced or good it is, can match the quality of code well written by a good developer, full stop.
I’ve believed in that for years and years, and will believe in it for years to come. And I’m not talking theoretically, I’ve been in the field long enough to see the results of different code generation tools, varying from the disastrous to the quite good and pretty clean.
But the thing is that it’s a code generator after all, so it’s pretty much generic, which could be good enough if you’re just working on some simple form that won’t do much more than insert some contact info into a database or something of the sorts, but once you get a bit deeper, its generic solutions just aren’t enough, you need someone good to work out the logic and to optimize the code, …etc etc etc.
One thing to keep in mind though is the importance of having a good developer who can write good code.
Anyway, this morning while driving to work, the issue popped up in my head again, with a rather interesting analogy that I think really explains the difference between generated code and human written code.
The analogy is with cars; human written code is pretty much a stick shift car, and generated code is an automatic.
If you were to enter a race, you’d actually have more control over the car with a stick shift, over when you change gears, how much power it gives you and when, thereby giving you an edge that would help you win the race.
Automatic gear doesn’t give you all that flexibility, it just lets you drive, with different levels of control, according to how advanced the automatic gear is, but never equaling that of a manual gear.
The driver and how good he is is also a factor here, because it takes a good one to know how to control a car well and get the most out of it to win the race.
To me, this analogy perfectly illustrates the difference between developer-written code and generated code, and shows why the first is superior to the latter; it all lies in the results: quality, flexibility, optimization and robustness.