The Transmission Analogy

It’s been said that memory management is like automotive transmission. I agree, but, unlike Joel Spolsky, I don’t think that implies that implies one should prefer languages that manage memory for you.

The analogy goes like this: Memory management is like a car’s transmission. C++ and similar languages are manual transmission. The developer must “shift” by hand, explicitly allocating and freeing memory. Languages like Java and C# manage memory for you, like an automatic transmission. Joel says that there is only one case in regular driving where a manual transmission gives the driver a real advantage. Therefore, one should prefer an automatic transmission and, similarly, a memory managed language.

But there’s something more subtle about it, both with driving and with programming. True, a standard does not give a direct, explicit benefit, but it does provide an indirect value. When I drive a standard I feel more connected to the road, more involved in driving. I have to pay more attention to the engine, to know when to shift. Since I’m paying more attention to the engine, I pay more attention to the road, to the other cars, to driving in general. I am more involved in driving, and that makes me a better driver when I drive a standard.

It’s the same way with programming. If I’m doing memory management myself, I pay more attention to which objects own which other objects, to object lifetimes, to the program in general. Managing my own memory forces me to pay more attention, and that makes me a better developer. Sure, I could let the language handle that for me, but that would let me be a little more detached.

Granted, automatics remove a whole class of errors. You can’t grind the gears, or shift into first on the highway. You can’t leak memory or access freed memory. But those are beginner errors. When you get good, you tend to not do that. And if you do, the car or the program tell you that you messed up. You can’t say that you know how to drive a standard until you stop grinding the gears. And that leads to the next advantage.

You have to be a better programmer to work in a language where you’re responsible for managing your own memory. When a C++ program is written wrong, it dumps core. When a Java program is written wrong, it runs slow. You can write Java that has all sorts if inefficiencies in it, and it works. But to be able to successfully write C++, you have to write it better.

So which should you use? Like everything else, it depends on the task at hand. But I strongly believe that all developers should learn C++ and Java or C#. Just knowing both will make you a better developer. But which is “better” to use? It depends. To paraphrase something that used to be said about C and Lisp, C++ developers think that memory management is too important to be left to the language, and Java and C# developers think memory management is too important to be left to the developer.

Tags: , , ,

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: