Re-read through Mike Acton's "Typical C++ Bullshit" last night, and noticed a weird comment near the end:

"References? Useless cruft"

So... what's the problem with c++ references? Is it just that you don't get to control when the pointer deref happens?

@khalladay At a guess, references are for 'the one', pointers are often arrays of 'the many' and a key point of the talk is that you design for the latter, not the former condition

@bobvodka huh, never thought about references that way, that's really interesting. I'm going to ask @ work today how people interpret a function signature with references.

We always use them to communicate that an arg can't be null, but I wonder if people also expect it to communicate single vs array.

@khalladay i don't think this is mike's point, but the fact that a mutable reference looks just like a normal copy at a callsite but can modify your variable is nuts and makes me not want to use c++.

Mainly because nobody seems to think this is a problem.

@norado it's a problem, but c++ has so many problems that I think people just gloss over this one. It would be nice to see a language addition for something like the ref keyword in c# to make the callsite explicit about reference vs copy

I think 'useless cruft' does not mean there is anything _wrong_ with them, but that (some think) they add nothing of value. I tend to agree. I don't think whatever small benefit they may add outweigh the problem of having two ways of passing something indirectly.

@Istarnion It's interesting to hear all the negative sentiment around references! The code bases I've worked on have used them extensively as a way to communicate that "you shall not pass null to this argument," and no one has batted an eye.

Sign in to participate in the conversation
Gamedev Mastodon

Game development! Discussions about game development and related fields, and/or by game developers and related professions.