News for hackers. Stuff that matters.
Re:C++26: A Placeholder with No Name by asveikau on Saturday January 11, 2025 @11:44AM (#42667020)
There's so much redundancy built into the language if you don't. Imagine:

    std::shared_ptr<T> p = std::make_shared<T>();
Then replace T with a very long type. And that's not the most verbose example, just an early one that popped into mind.

Then you have lambdas. Imagine assigning a lambda into a stack variable without auto, also keeping in mind that std::function adds overhead.

Re:C++26: A Placeholder with No Name by secondcoming on Saturday January 11, 2025 @12:32PM (#42667395)
That example isn't what OP is talking about, because it's obvious what the type of p is because it's on the same line:

    auto p = std::make_shared<T>();
whereas the following isn't clear and isn't necessarily correct without looking up what the return type of foo() actually is:

    auto p = foo();
Re:C++26: A Placeholder with No Name by asveikau on Saturday January 11, 2025 @12:46PM (#42667510)
I'll agree that your second example is less readable than the first..

This could be mitigated with the name of foo() being more descriptive.

If the return type is particularly wordy, auto could still be appropriate.

Re:C++26: A Placeholder with No Name by unleaded on Saturday January 11, 2025 @02:37PM (#42668370)
> This could be mitigated with the name of foo() being more descriptive.

welcome back Hungarian notation

Re:C++26: A Placeholder with No Name by asveikau on Saturday January 11, 2025 @04:02PM (#42668903)
lpwszThanks.

In seriousness, no, that's not what I'm suggesting, and I find it an unusual thing to read from my comment. I'm saying a descriptive name for foo() can give you a hint about what the type is, even if it doesn't literally and directly tell you what the type is.

Re:C++26: A Placeholder with No Name by jeremyjh on Saturday January 11, 2025 @02:50PM (#42668471)
auto conn = createConnection();

What does this have to do with hungarian notation?

Re:C++26: A Placeholder with No Name by pests on Saturday January 11, 2025 @02:57PM (#42668507)
You’re thinking of it wrong.

This works better:

auto uasStudents = getClassList()

In this case, “uas” prefix standing for an unsafe array of strings.

Then say you validate the list

auto sasStudents = validate(uasStudents)

(Now it’s a safe array of students!)

Re:C++26: A Placeholder with No Name by dullcrisp on Saturday January 11, 2025 @03:37PM (#42668732)
I feel like I’m missing a joke.
Re:C++26: A Placeholder with No Name by powercf on Saturday January 11, 2025 @04:35PM (#42669095)
Alone this looks like a reasonable use of auto. In a real codebase, there may be two (or twenty) different connection-like things, multiple of which may be reasonably to call in this context.

The "Hungarian notation" comment is correct - it's not strictly Hungarian notation, but annotating function (or variable) names when the language has a type system representing this same information is the same idea with the same problems as Hungarian notation.

Re:C++26: A Placeholder with No Name by shaklee3 on Sunday January 12, 2025 @12:37AM (#42671551)
this is required for writing generic code when the function may return different types
Re:C++26: A Placeholder with No Name by another2another on Monday January 13, 2025 @10:20AM (#42684355)
Lambdas I would agree with and iterators, but in many other situations, e.g. templated collections it's easy enough to make a descriptive typedef.

And... I have seen this in the wild: 'auto isFalse = true;'