News for hackers. Stuff that matters.
Re:Will Carbon Replace C++? by opportune on Monday February 27, 2023 @10:54PM (#34965422)
Heh this is normally why I tell my new teammates to be careful about using auto in non-test code outside of well established patterns like iteration. Auto will bite everybody in the butt at some point!
Re:Will Carbon Replace C++? by LaLaLand122 on Monday February 27, 2023 @11:17PM (#34965557)
And yet "Almost Always Auto" is "Modern C++"...
Re:Will Carbon Replace C++? by UncleEntity on Monday February 27, 2023 @11:53PM (#34965777)
Your local style guide can’t override this?

Just turn people loose on your codebase without supervision and be really surprised that the hackers make off with your data?

You, sir, are arguing from bad faith as your obvious mission is to promote “rust in all the places”.

Re:Will Carbon Replace C++? by hot_gril on Tuesday February 28, 2023 @12:42AM (#34966064)
Our style guide says "almost never auto," but most people auto everything. They can make the linter replace auto with the actual type if it's really that big a deal. Explicit type wouldn't have avoided this bug.
Re:Will Carbon Replace C++? by LaLaLand122 on Tuesday February 28, 2023 @01:03AM (#34966202)
Arguably an explicit type would have made the bug a little bit more obvious. You basically expect, by default, this kind of string manipulation functions to return a std::string. Obviously in this specific case you can return a view, and that makes it more performant; but it's kind of unexpected and using auto leaves the surprise a bit more hidden.

But sure, you can still make the error with expiclit types.

Re:Will Carbon Replace C++? by hot_gril on Tuesday February 28, 2023 @02:03AM (#34966485)
I agree, the string_view on the LHS might make you think more about the lifetime, but I'm pretty sure we all would've missed it.
Re:Will Carbon Replace C++? by afc on Tuesday February 28, 2023 @12:08AM (#34965856)
Citation needed? My team generally avoids auto and tends to spell out the types most of the time, which we find makes everything more readable. Code is written once but read many times...
Re:Will Carbon Replace C++? by hot_gril on Tuesday February 28, 2023 @12:23AM (#34965943)
imo types don't make things more readable. You know the "fluent programming" thing where you do obj.doThis().doThat().doThis().doAnotherThing() and probably 20 more lines of this? That's entirely because people didn't want to bother writing out LHS types, but whatever version of the language only let you avoid that if you chained things (there was no auto or var). Maybe it's more of a Java practice, though.
Re:Will Carbon Replace C++? by LaLaLand122 on Tuesday February 28, 2023 @12:51AM (#34966119)
A citation of what's "Modern C++"? The term is a made up concept with no proper definition...

But "Herb Sutter says you should use it, he even gave it a catchy name/acronym" is as good as it gets. And he does so AFAIK in the same place he created the "Almost Always Auto" name: https://herbsutter.com/2013/08/12/gotw-94-solution-aaa-style...

Notice that he says "the main reasons to declare variables using auto are for correctness, performance, maintainability, and robustness—and, yes, convenience, but that’s in last place on the list.". He is arguing literally the opposite of what you do, that using auto avoids bugs ("for correctness").

I'm not going to argue in favour or against "Almost Always Auto". But I see no problem calling it "Modern C++".

* Herb Sutter being the convener of ISO WG21

Re:Will Carbon Replace C++? by iknowstuff on Monday February 27, 2023 @11:05PM (#34965489)
Classic C++
Re:Will Carbon Replace C++? by hot_gril on Tuesday February 28, 2023 @12:18AM (#34965915)
We don't got time for non-auto. Better yet, we should've just written all our stuff in Python or Java. We have no legitimate need (performance etc) for C++, Rust, or even Golang.

Even if you use string_view on the LHS instead of auto, pretty easy to miss the bug here.

Re:Will Carbon Replace C++? by FpUser on Tuesday February 28, 2023 @06:14AM (#34968069)
Same here. I avoid auto in my code except iterations. Just a mental pattern. I understand that people coming from "typeless" languages might not like it at all, but it is like with guns. You can play with water pistol but you do not play with real guns, you follow some rules if you want it safe. Modern C++ in my opinion supplies enough features and tooling to help with making reasonably sure the rules are followed.
Re:Will Carbon Replace C++? by hot_gril on Tuesday February 28, 2023 @03:27PM (#34974359)
auto is the least of your worries when it comes to memory safety in C++.