top | item 29487475

(no title)

whatroot8 | 4 years ago

I’m using it for the first time and have been wondering what all the horror stories are about.

But then realize those horror stories were from 15+ years ago.

Did we need Rust?

Or did we need to build out the C and C++ ecosystems to make them easy and safe?

How many hours spent on all these languages for a few folks to build fiefdoms upon? Every human endeavor has a group of swindlers that tell you they’re helping but in hindsight often looks like they just got in the way.

discuss

order

rootlocus|4 years ago

Under every modern, shiny, abstract, high-level feature of the language or the standard library there are layers and layers of legacy cruft. Every aspect the language has experimented with has to be supported by the new features, making simple things like the Variant type for example, very difficult to implement correctly [1].

C++ is nice and good until you hit a bug that leaks an abstraction and you realise you barely understand 10% of the language, and you'll never understand it completely, because people spend their entire careers trying to track down how language features interact and where they explode, and they're never finished.

[1] https://www.youtube.com/watch?v=JUxhwf7gYLg

belter|4 years ago

What a tour de force! Thanks for the link. It beats my previous favorite C++ presentation:

"CppCon 2018: Nicolai Josuttis “The Nightmare of Initialization in C++” https://youtu.be/7DTlWPgX6zs

Next Halloween I will dress up as std::variant

tialaramex|4 years ago

Also, I'm fairly convinced that when they chose not to take Epochs for C++ 20 they sealed the long term fate of the language.

Epochs was the only halfway practical way to attempt the ever elusive step B of the "Smaller, better C++" idea, the part where you toss away all the stuff nobody needs. For many years now, the protestation has been that it's a great idea but first a few more things must be added. And then a few more. And a few more. Bjarne himself has a laundry list. Adding things to C++ is extremely ugly but it can be done and is still being done. However removing things is hard, and Epochs proposed a practical way to begin that work. It was shot down and I think years from now a C++ post mortem will pronounce that as at least contributing to the outcome if not outright the primary cause.

Epochs would have been really hard to do in C++ 20. But it isn't getting easier and the will to attempt such a thing seems to me to be finite.

DSingularity|4 years ago

Like std::vector<bool>. Damn you std::vector<bool>.

whatroot8|4 years ago

Yes so again then; why Rust?

Surely shining light on and fixing those issues would have resulted in C/C++ essentially becoming what Rust hopes to be.

But western kids needed to found new big business and institutionalize math.

Seems the west has a real issue with oligarchs needing to manage the masses. No one can be rich unless an institution has decided they are correctly rich.

Kototama|4 years ago

Multithreaded C++ programming without bugs is still very hard. There was an interview on Mozilla and why they started Rust and everytime they had some path in the code with threads, they found some concurrency issue. I can't find the link right now.

Edit: I think it's in this podcast https://corecursive.com/013-rust-and-bitter-c-developers-wit...

PaulDavisThe1st|4 years ago

> Multithreaded C++ programming without bugs is still very hard.

Multithreaded programming without bugs is hard in any language, unless the language completely cripples your ability to do certain things that tend to be where the bugs can creep in.

If you religiously stick to the rules (e.g. mutexes around all variable use, mutexes and condition vars used correctly), you will not have bugs. The problems come because people do not religiously stick to the rules, because their language doesn't require them too.

The problem is that if you are forced to follow all the rules, then certain things become impossible, such as lock-free programming (even the simple single-reader, single-writer FIFO). The use of memory barriers to create provably safe lock-free code is outside the scope of regularized multithreaded programming, and since it's very very hard to get that write, but people want to try it anyway, that's where things go wrong.

Just use things the way you're supposed to and you won't have bugs with this.

belter|4 years ago

mempko|4 years ago

You do realize Chrome's code has a lineage that is over 24 year old, based on khtml.

If you are starting a project from scratch with C++, you can avoid a lot of the pitfalls chrome's team has. Additionally Google has an arguably poor C++ coding style that is also completely out of date.

A company that uses C++ more effectively is arguably Adobe, who has the great Sean Parent.

emmanueloga_|4 years ago

One thing that is still horrific (imho) is unicode support. Last time I found that in order to print unicode strings with cross platform support on a simple way I required a boost library [1]. The dichotomy between standard and "wide" string APIs is kind of a mess.

Also, construction, destruction and move semantics makes everything really complicated and even simple baseline code requires a bunch of boilerplate [2].

1: https://www.boost.org/doc/libs/develop/libs/nowide/doc/html/...

2: https://gist.github.com/EmmanuelOga/12e1da5aedd9f6dc50e742cd...

AnimalMuppet|4 years ago

Modern C++ lets you be safe (or at least close).

Rust does much more to force you to be safe. (Or, to put it differently, C++ still has all the unsafe ways available, and not locked away behind the "unsafe" keyword.)

bombela|4 years ago

Note that the unsafe keyword of Rust unlock only few things. But that what makes it powerful.

unsafe mainly allows you to dereference pointers. References are guaranteed to be safe at all time, with an associated lifetime, while pointers can hold any possible memory address, valid or not (like in C++).

unsafe also let you promote a pointer to a reference by assigning a lifetime.

And finally, unsafe allows you to call functions themselves marked unsafe. One notable function is called transmute, and is very similar to how the the C style cast works in C++. It's the one that automatically selects between static_cast and reinterpret_cast depending on the context.

tialaramex|4 years ago

> Or did we need to build out the C and C++ ecosystems to make them easy and safe?

If so, the C++ committee wasn't interested in doing so. Preferring instead to say that new features don't have safety if there was any possibility that doing so might provide opportunity for improved performance.

Don't worry, when inevitably you blow your feet off with any of the new footguns provided, they'll be happy to tell you that it's your fault, a true C++ programmer would have known not to do that. "Git gud" as the gamers say.

MR4D|4 years ago

Yes, I believe we needed Rust.

Backward compatibility is valuable, but so is letting go of old habits. With C++ and Rust, we can have our cake and eat it too. Plus, arguments about which language is better! ;)

woah|4 years ago

Yes, all the Rust developers are cackling evilly in their underground lairs

bborud|4 years ago

Give it some time. If you don't think C++ is complex, you don't know C++ yet.

FpUser|4 years ago

It is insanely complex. Yet modern C++ is easy to use. Just don try to be Alexandrescu. I am very far from being C++ expert yet I have zero problem using it to write stateful multithreaded business servers that run for month at a time (maybe able to run for longer but I update with new features more often).