Skip to content

Instantly share code, notes, and snippets.

@aras-p
Last active January 26, 2016 19:58
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aras-p/600eb7c762700a3ece94 to your computer and use it in GitHub Desktop.
Save aras-p/600eb7c762700a3ece94 to your computer and use it in GitHub Desktop.
I have a problem with "Garbage Collection as Training Wheels" analogy

So this tweet: "Garbage collection helps programmers the way training wheels help cyclists. The analogy is pretty much exact." (https://twitter.com/cmuratori/status/569223413677494272)

Tobias: "is that because you consider "training wheels" insulting or because you disagree with the analogy?"

Good question. Twitter isn't terribly good at subtlety, so I don't know what Casey originally meant. Also I don't know Casey, so hard to even guess what he meant exactly. I suspect it's a bit of both: 1) "once you learn you throw away training wheels", and 2) "training wheels are for kids". I disagree with both; I think there are places where GC does make sense, even if you are an experienced programmer.

I find the "manual vs automatic transmission" analogy much better really (manual memory management = manual transmission; GC = automatic transmission). Now, I know next to nothing about cars (I do drive, but that's about it), so take this all with a grain of salt. That said, I'm not a cyclist either.

Benefits of manual:

  • You can be faster than automatic (transmission | memory mgmt).
    • Yeah the analogy is not terribly good wrt GC pauses.
  • Generally is more economical: uses less (fuel | resources).
  • You can go Manly Man on the others using automatic and say they are not real (drivers | programmers).
  • Cheaper (I guess) | smaller code infrastructure.

Benefits of automatic:

  • Does some of the usually boring work for you. In many cases it's one less thing that you have to worry about.
    • If you're in (racing | high performance software), there are reasons why (semi)manual is used.
  • While you're learning, it's massively easier (you have to learn to much all at once; one less thing to worry about is a bonus)
  • Prevents you from some mistakes (wrong gear | leaks/doublefrees/...). These aren't a big problem once you have experience though.
  • You can say the ones using manual are dinoaurs who know nothing about the modern world.

My point? It's a tool. Don't like it? Fine, don't use it. Like it? Fine, use it. In both cases, does not automatically mean the other side is stupid.

Note 1: Daniel's suggestion: "as with any tool, don't treat it like magic. know how it works". Which is true, but does not play well with car transmission analogy. I guess majority of drivers have no idea how transmission works (either kind).

Note 2: Tobias below makes good points about training wheels analogy. Sheet. You ruined my rant, Tobias! :)

@tberghoff
Copy link

Thanks for the write-up, man.

Fundamentally, the objection to “training wheels” as a metaphor for garbage collection feels deliciously meta to me. If you don’t particularly care about going fast on your bicycle, there really isn’t much of a reason to ever learn to ride without training wheels. You’ll get where you want to go, you’re protected against certain kinds of accidents, you don’t require a working sense of balance, and you don’t need to learn this specific skill that will cost you some amount of knee-skin before you master it. The only tradeoff is how fast you can go, and frankly the ridicule of those without training wheels.

But that’s the same as the garbage collection situation, isn’t it? The primary objection to garbage collection is either speed or shame.

We can even take this metaphor a bit further: As someone who’s lived in Cambridge, I’ve seen plenty of people with either elevated blood alcohol or exciting conversations fall of their bicycles. It would never occur to them to attach some training wheels to protect themselves, because that’s just not what a self-respecting adult would do.

In the same way, I’ve seen people go C-with-intrinsics where a python script would suffice.

Anyway, here’s a picture of a Honda Goldwing with training wheels: http://www.bikerplaza.com/image/bikers/Honda-Goldwing-Aspencade--98-315.jpg ;)

@krig
Copy link

krig commented Feb 22, 2015

I feel like maybe you are missing one aspect of GC with this analogy - or maybe it is covered, I'm not sure - which is that when writing a program, you have to make a performance-related decision before any code at all has been written. To later discover that the use of GC causes performance issues that are non-acceptable, and where the problem is not some inner loop or particular point in the program but the accumulated allocations over time, means rewriting from scratch.

Actually, maybe this is covered by the analogy - it's like deciding to participate in a rally competition with a car that has automatic transmission. At some point, it will be necessary to switch to manual to compete, which means switching to a new car. The cost of switching cars seems too small to really convey why this is an issue though...

@aras-p
Copy link
Author

aras-p commented Feb 22, 2015

@tobias: I should disagree because your points make my rant less valid but... hmm, fair points! damn!

@dmitshur
Copy link

I agree with both analogies, I think they're fairly close on target. One may argue on a more detailed level as to which of two analogies is better.

But I'd like to expand the analogies in another direction.

Consider concurrency/parallelism/multithreading. Suppose your target machine has 16 threads (maybe 8 physical, 16 virtual) or even more, which is a likely situation in the coming future/present.

I would say that each car/bike represents a single thread at your disposal. So now you have 16 cars/bikes.

Personally, at this point, I would prefer the 16 cars/bikes to have automatic transmissions and training wheels, because it's really hard for me to control all 16 cars at once if I also have to worry about manually changing their gears. It's also nice that the bikes with training wheels do not tip over when they come to a stop, which may happen when I get distracted by so many of them. After all, I'm only one person (programmer), having to control/drive so many things at once.

Well, that's my take on things. I think I'm okay with giving up some of that control if it saves me time/concern and frees it up to worry about using up all the cores in my target system. But if I wanted one core to go really fast, there's no doubt I'd opt for the manual transmission or bike without training wheels.

@backinside
Copy link

One thing, that I keep thinking about, when I read all this, is I really want to have a choice, and control
And this is missing from a lot of the languages.
I as an experienced programmer, when I know I need performance critical optimizations, I want to have full control, especially on the client side
I as a Technical Director, certainly don't want to give this control to a junior developer
I as a System Administrator with the bless of horizontally scalable systems, don't care as long as the response time and the server budget is enough
I as a newbie to a new system or language I certainly want to toy around with as much training wheel as possible
I think, there is a time and a place for everything, learn to code with GC, learn how GC works, learn when it hurts, and decide when you need it
But for this to work, we need the opportunity to choose, just as we can choose to do inline assembly in C, I think we need to be able to choose to not use GC in higher level languages

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment