this post was submitted on 15 Sep 2025
79 points (87.6% liked)
Programmer Humor
38614 readers
138 users here now
Post funny things about programming here! (Or just rant about your favourite programming language.)
Rules:
- Posts must be relevant to programming, programmers, or computer science.
- No NSFW content.
- Jokes must be in good taste. No hate speech, bigotry, etc.
founded 6 years ago
MODERATORS
you are viewing a single comment's thread
view the rest of the comments
view the rest of the comments
I see. I think auto gets overused a lot by people just being lazy about writing out the full type, but constexpr is good practice in my opinion. Never had a compiler issue with them, but then I don't think I've ever used a nested lambda either.
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 haveusing vectord = std::vector<double>
if I'm using a lot of them, because I think it makes the code more readable. Just don't throwauto
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!https://herbsutter.com/2013/08/12/gotw-94-solution-aaa-style-almost-always-auto/
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.To be frank: You gain the information that
MyConcreteType::get<uint32_t>
returns auint32_t
, which I otherwise couldn't infer from the docs. Of course, I could assume it, based on the template parameter, but I don't want to go around assuming a bunch of stuff in order to read docs.Take an example like
auto x = my_var.to_reduced_form()
, it's very clear thatx
is the "reduced form" ofmy_var
, which could be meaningful in itself, but what type is it? I need to know that if I want to do anything withx
. Can I dox += 1
? If I do, will that modifymy_var
? Let's say I want to make avector
of whateverto_reduced_form
returns... and so on.All these questions are very easily answered by
MyConcreteType x = my_var.to_reduced_form()
. Now I immediately know that everything I can do withmy_var
, I can also do withx
. This makes me happy, because I need to do less digging, and the code becomes clearer to read.The problem is that lambdas with a capture ~~aren’t strongly typed~~ are uniquely typed, so you have to use decltype/auto. And if you pass such a lambda to a function you’ll have to use auto as well.
If you write a lambda with a capture that calls itself recursively you’ll have to pass it to itself as an auto argument as part of the call signature.
I think this article explains it better: https://artificial-mind.net/blog/2020/09/12/recursive-lambdas
Edit: fixed wrong terminology
This is an entirely new way to misuse "strongly typed" that I was not aware of before. Amazing.
Thank you!
You’re welcome. Just don’t blame me when your brain starts cursing in foreign languages you don’t even know. ;)