90
you are viewing a single comment's thread
view the rest of the comments
[-] thebestaquaman@lemmy.world 8 points 3 weeks ago* (last edited 3 weeks ago)

I really like C++ (I know, shoot me), and I think auto should be avoided at (almost) all costs.

One of the things I love about a language like C++ is that I can take one glance at the code and immediately know what types I'm working with. auto takes that away while adding almost no benefit outside of a little convenience while writing.

If I'm working with some very big template type that I don't want to write out, 99/100 times I'll just have a using somewhere to make it more concise. Hell, I'll have using vectord = std::vector<double> if I'm using a lot of them, because I think it makes the code more readable. Just don't throw auto at me.

Of course, the worst thing ever (which I've seen far too often) is the use of auto in examples in documentation. Fucking hell! I'm reading the docs because I don't know the library well! When you first bother to write examples, at least let me know the return type without needing to dig through your source code!

[-] ugo@feddit.it 4 points 3 weeks ago
[-] thebestaquaman@lemmy.world 3 points 3 weeks ago

Thanks, that was a good read :)

However, my impression is that he's largely using the existence of templates and polymorphism as arguments that "we don't really care about type". I disagree: A template is essentially a generic type description that says something about what types are acceptable. When working with something polymorphic, I'll prefer ParentClass&, to indicate what kind of interface I'm working with.

Sure, it can be very useful to hide exact type information in order to generalise the code, but I think that's a weak argument for hiding all type information by default, which is what auto does.

this post was submitted on 15 Sep 2025
90 points (100.0% liked)

Programmer Humor

38642 readers
161 users here now

Post funny things about programming here! (Or just rant about your favourite programming language.)

Rules:

founded 6 years ago
MODERATORS