News for hackers. Stuff that matters.
Re:C++ coroutines: Initial implementation pushed to master by imron on Sunday January 19, 2020 @04:22AM (#22090361)
> yet instead of fixing anything they just pile up more features in an effort to compete with Rust and Go

I used to be a C++ diehard, but modern C++ is why I started learning Rust. If I'm going to have to learn a whole bunch of new idioms and rules, I might as well do it with a language that has the new features and safety built-in, rather than bolted on.

Re:C++ coroutines: Initial implementation pushed to master by lenkite on Sunday January 19, 2020 @06:17AM (#22090781)
I am completely the other way. Coming from Java, I am finding modern C++ pretty amazing tool for design. There are some amazing compile-time API's I can design which is impossible in other languages. Maybe the shiny will wear off after some time but so far I am loving it. I am truly looking forward to C++ 20.
Re:C++ coroutines: Initial implementation pushed to master by simias on Sunday January 19, 2020 @07:33AM (#22091088)
C++ is pretty great in single player mode, you have so much power at your fingertips. It's the epitome of "and the kitchen sink too".

It's when you switch to online multiplayer and end up having to maintain and modify code written by other people who have different opinions on how kitchen sinks should be installed and used that things tend to sour a bit.

Re:C++ coroutines: Initial implementation pushed to master by 72deluxe on Sunday January 19, 2020 @08:39AM (#22091361)
This is true for all languages and projects you inherit though. Eg I am trying to use Magento in PHP land and it is truly grotesque.
Re:C++ coroutines: Initial implementation pushed to master by guggle on Sunday January 19, 2020 @03:21PM (#22093765)
Magento was grotesque from day one.
Re:C++ coroutines: Initial implementation pushed to master by rumanator on Sunday January 19, 2020 @04:35AM (#22090420)
> I used to be a C++ diehard, but modern C++ is why I started learning Rust. If I'm going to have to learn a whole bunch of new idioms and rules

You don't. Just because you bump a version number it doesn't mean you are forced to use all the bells and whistles.

Re:C++ coroutines: Initial implementation pushed to master by Rizz on Sunday January 19, 2020 @04:54AM (#22090479)
That stops working once you're no longer a solo developer, but part of a team, then you need to learn everything any of your fellow developers might use. You might as well focus on learning a new language and having access to new jobs where you don't have to deal with legacy languages.
Re:C++ coroutines: Initial implementation pushed to master by rumanator on Sunday January 19, 2020 @05:09AM (#22090543)
> That stops working once you're no longer a solo developer

It doesn't. If you have any experience working on C++ projects you will be very aware that deciding which feature is and is not used is the kind of stuff which is defined in the project's coding guidelines docs, along with naming conventions and choice of build system.

With C++ you only have to use a feature introduced after C++11 if you decide you really want to use it. Some projects even in this very day still don't use smart pointers or exceptionsor std::array. Some people still do the old C with classes thing.

Moreover, the world does not come to an end if you arrive at a project and need to learn a feature provided by a programming language.

Re:C++ coroutines: Initial implementation pushed to master by simias on Sunday January 19, 2020 @07:46AM (#22091153)
That's a very optimistic way of looking at things. More than a decade ago (pre-C++11) I used to be a pretty proficient C++ developer. I had a bunch of books about C++ designs, I would use Boost left and right, I knew my design patters, I knew advanced templating tricks etc...

Then I kind of grew frustrated by the complexity and super long build times and for a few years I left C++ on the side, going back to C and other languages. Now I'm a big fan of Rust.

These days when I see a modern C++ codebase using "auto" all over the place, lambdas, the new constructor/initializer syntax, std::move and more, it can be very tricky for me to understand what some code is doing. I feel like I'm reading a new C-based language where I can understand most of it but I feel like some key components are eluding me. Generally I end up figuring it out but I really don't feel comfortable modifying the code because I don't understand all the implications. Very few languages, especially as old and huge as C++, change so drastically and so fast.

And again, I considered myself an advanced C++ user not so long ago.

>With C++ you only have to use a feature introduced after C++11 if you decide you really want to use it.

If you're the original developer who makes the decisions. If you end up working on a project using a different subset than the one you're used to then you're screwed. That's what the parent is talking about.

Re:C++ coroutines: Initial implementation pushed to master by jcelerier on Sunday January 19, 2020 @08:46AM (#22091389)
> Now I'm a big fan of Rust.

> These days when I see a modern C++ codebase using "auto" all over the place, lambdas, the new constructor/initializer syntax, std::move and more, it can be very tricky for me to understand what some code is doing.

But what if you had spent 1/10th of the time you spent learning Rust looking at these features (frankly looking at the wikipedia pages for each revision is enough most of the time I think :

https://en.wikipedia.org/wiki/C%2B%2B11

https://en.wikipedia.org/wiki/C%2B%2B14

https://en.wikipedia.org/wiki/C%2B%2B17

https://en.wikipedia.org/wiki/C%2B%2B20

)

Re:C++ coroutines: Initial implementation pushed to master by imron on Sunday January 19, 2020 @10:00PM (#22095925)
> But what if you had spent 1/10th of the time you spent learning Rust looking at these features

You can write object-oriented code in C too (e.g. gtk, glib etc). It just involves much more boilerplate, and it doesn't offer the same amount of built-in safety guarantees.

So I know enough Modern C++ to use it, but why would I when there are far better alternatives?

Re:C++ coroutines: Initial implementation pushed to master by pjmlp on Monday January 20, 2020 @09:50AM (#22099146)
Because those alternatives, while better at syntax + semantics part, are still quite immature at IDE + libraries + eco-system part.

For example, try to use Rust to implement a UWP component callable from .NET, interacting with the Visual Layer, while using mixed mode language debugging inside Visual Studio.

Re:C++ coroutines: Initial implementation pushed to master by jcelerier on Monday January 20, 2020 @09:30AM (#22099004)
those alternatives don't always offer what C++ has - for instance template<int I> is damn useful in many cases and not many languages have that
Re:C++ coroutines: Initial implementation pushed to master by rumanator on Sunday January 19, 2020 @05:18PM (#22094523)
> That's a very optimistic way of looking at things.

It's the way a professional software developer who actually works with C++ projects looks at C++.

> More than a decade ago (pre-C++11) I used to be a pretty proficient C++ developer. (...) Then I kind of grew frustrated by the complexity and super long build times

Honestly, that comes out as utter bullshit. It sounds like you tried to find out which were the cliche criticisms and mindlessly repeated them, without noticing none of it makes any sense.

The main "complexity" that C++11 added was smart pointers and threading. It is simply unbelievable how someone who parrots they switched to Rust claims that stuff such as smart pointers and threading is too complex to learn. It's the sort of stuff that any developer quickly picks up with a cursory glance through the docs.

Your whole statement is even less believable if we were to believe your claim that you were somekind of Boost wizard who "considered myself an advanced C++ user", because Boost is the staging ground for whatever was added to the C++ standard.

Quite honestly, I find it hard to believe any of your claims.

Re:C++ coroutines: Initial implementation pushed to master by cowsandmilk on Sunday January 19, 2020 @07:09AM (#22090960)
> If you have any experience working on C++ projects you will be very aware that deciding which feature is and is not used is the kind of stuff which is defined in the project's coding guidelines

And you will find that you have to learn these features once they are allowed in the guidelines. Some workplaces stick to the old features. Some regularly update with pushes toward use of modern features. When your coding guidelines prefer modern C++, you have to learn it.

Re:C++ coroutines: Initial implementation pushed to master by tcbawo on Sunday January 19, 2020 @07:44AM (#22091142)
The sentiment of dreading having to learn new language features (as in being forced to) does not compute to me. Being a software developer, you should always be learning new things.
Re:C++ coroutines: Initial implementation pushed to master by armitron on Sunday January 19, 2020 @09:56AM (#22091715)
The complexity that emerges out of C++ with most/all of its features is immense to the point where it's clearly not worth the investment when there are so many alternatives out there. Nobody should be expected to deal with a language so complex that it takes a decade or more of effort before one can say with confidence he truly understands it.

Which is why C++ is dying and those other alternatives are finding so much appeal with new generations of programmers.

Re:C++ coroutines: Initial implementation pushed to master by vips7L on Sunday January 19, 2020 @09:17AM (#22091525)
Let's not pretend there are jobs in Rust or whatever you think replaces C++.
Re:C++ coroutines: Initial implementation pushed to master by 72deluxe on Sunday January 19, 2020 @08:40AM (#22091367)
True to some extent but education is good and knowing the language you are using can only be a good thing.

The same could be said of English. Would you switch to another language because someone uses a word you have never used before?

Re:C++ coroutines: Initial implementation pushed to master by imron on Sunday January 19, 2020 @10:13PM (#22095997)
> Just because you bump a version number it doesn't mean you are forced to use all the bells and whistles.

But I want to use those features. I want memory safety and a way to say this variable owns the memory, vs that variable which is only borrowing it. I want move semantics in some cases and copy semantics in others. I want lambdas so I don't need to define new functions (or classes) to handle simple visitor patterns (or other cases where passing a 'function' makes sense).

These are good, useful features that I'd like to use to make my code more safe, more performant and more readable, and while C++ can do these things to some degree, there's boiler plate and new rules (rule of 5 vs rule of 3) and gotchas, compared to a language like Rust that has these things built in, with more safety and without compromising performance, and for me it made sense to start using it instead.

I still have projects in C++ that I'll maintain with modernish C++ rather than re-writing them, but for new things where I have a say in the matter, I'll choose Rust.

Re:C++ coroutines: Initial implementation pushed to master by ncmncm on Monday January 20, 2020 @11:00AM (#22099713)
I see that you have not kept up. Since C++17 it's "rule of zero": you don't need to write any of them, because the compiler does it. As the language gets more capable, the code you write gets simpler.

I don't think that is happening in Rust.

Re:C++ coroutines: Initial implementation pushed to master by imron on Monday January 20, 2020 @11:20PM (#22104278)
> I see that you have not kept up.

I have not (C++14 onwards was roughly where I started paying less attention), and that was partly my point. C++ has gone through dramatic change, and if I'm going to go through that dramatic change, I might as well do it with a language that has modern features and safety built in, and doesn't require extra boilerplate to do it.

Looking up the rule of zero, it seems there's still some debate about whether it's a good thing or not [0] (don't know if it's been resolved yet), and it still doesn't preclude you from knowing about the rule of 5 and the side-effects of declaring or not declaring certain operators/constructors/destructors.

> As the language gets more capable, the code you write gets simpler.

> I don't think that is happening in Rust.

This happens quite often in Rust, see for example error handling and the evolution of the ? operator, and the recent addition of async/await, and unlike c++, as the language gets more capable the changes required in terms of coding style and updating your mental model of how things work is usually not so dramatic.

0: http://scottmeyers.blogspot.com/2014/03/a-concern-about-rule...

Re:C++ coroutines: Initial implementation pushed to master by ncmncm on Friday January 24, 2020 @12:40AM (#22135693)
2014 was a long time ago.

Scott has retired. The better alternative to his suggestion was noted right there in the comments. Rules of 3 or 5 concern only designers of a library, and if you are designing a library, you may ignore them now.

Re:C++ coroutines: Initial implementation pushed to master by gumby on Sunday January 19, 2020 @03:46PM (#22093943)
Think about it the opposite way: the modern language gives you a much safer and more expressive way to express your algorithms and still gives you access to the large library of existing code.
Re:C++ coroutines: Initial implementation pushed to master by nmca on Sunday January 19, 2020 @06:15AM (#22090772)
On the flip side, I learned low-level programming in rust, and am thankful that $bigcorp uses modern c++ so the initial gap was smaller. Rust is still better though.
Re:C++ coroutines: Initial implementation pushed to master by ncmncm on Sunday January 19, 2020 @05:14AM (#22090559)
Do not feed the trolls.

The net number of people adopting C++ in any unit time dwarfs by orders of magnitude the number adopting Rust; and the number already using C++ exceeds that of Rust by many more. That will remain true for a long time. As a consequence, any improvement to C++, either core language or library, has overwhelmingly larger lasting real-world benefit than any corresponding feature in Rust.

Rust pursues benefits by making a class of low-level errors hard to express, at some cost to expressiveness, and at quite substantial cost to adopters who must learn to work around the limitation (which they do). Against such cost it provides some convenient new control flow features, and leaves behind many C and C++ misfeatures that C++ cannot.

C++, instead, pursues benefits by making the language increasingly able to capture semantics in libraries, and thereby deliver thoroughly optimized and tested semantics to users without compromise. The result is that C++ users, by using such libraries, are able to code at a level high above that where the bugs prevented by Rust would manifest, and write less code that could harbor bugs of any kind, overall.

It is not clear whether adoption of high-level coding practices by coders using or switching to C++ will produce more benefit than those adopting Rust, and coding without access to such libraries. I have placed my own bet, and we will see.

But we can say with certainty that every coder who switches to modern, safe C++ from C or C-like C++, or to Rust, is a net win for humanity. And, if Rust in the end fails to grow out of its boutique niche (which is still absolutely possible), everyone later leaving Rust for C++ will bring to it high expectations that will incrementally raise the quality level of new C++ code.

Bad-mouthing of C++ by Rust fans may feel good, but it causes a net harm to humanity by the degree to which it reduces the number of coders who switch to modern C++ from C. The number of C coders who switch to Rust, instead, is far, far too small to compensate for such harm.

So the only defensible, responsible behavior is for C++ and Rust users to promote C++ and Rust (not necessarily in that order) and concentrate on getting coders off C.

Re:C++ coroutines: Initial implementation pushed to master by LessDmesg on Sunday January 19, 2020 @05:46AM (#22090670)
You have some strange ideas about why people use C instead of C++ these days. People continue using C not because C++ lacks coroutines or something else (a strange argument for C which has almost no features to speak of), and not because they hate safety. No, people use C dor the sake of portability, for the sake of embedded systems, and for the sake of utter simplicity where that is required. Weaning them off C to C++ is impossible because C++ already doesn't fit their requirements. In fact, Rust is better suited to embedded devices than C++, so there's no real need to proselytize C++ to C programmers. Or to anyone, I would argue, because C++ is a terrible language nearly impossible to write safe software in, as well as an ergonomical, developmental and compilational pain in the ass.

In fact, I believe that in terms of developer time wasted as well user frustration, C++ is the most harmful language in the history of humanity. Someday I'll put together a page listing the dozens of C++'s design daults. Here's just a single article demonstrating how incompatible with simplicity and correctness C++ is: http://www.icu-project.org/docs/papers/cpp_report/the_anatom...

Re:C++ coroutines: Initial implementation pushed to master by nemetroid on Sunday January 19, 2020 @09:04AM (#22091469)
The article is from 1997. Every C++ developer will agree that the area surrounding owning raw pointers is chock-full of footguns, but that area is avoided in modern C++, both in theory and in practice.
Re:C++ coroutines: Initial implementation pushed to master by ncmncm on Sunday January 19, 2020 @01:17PM (#22092895)
It is a fact that people still do graduate from C to C++, for a wide variety of reasons. Some discover that their embedded system can be coded with C++ as easily as C. Some learn that C++ is faster than C. Some just gain more confidence and adopt a new feature that is only in C++.

The large number of remaining C coders, and the ease of switching incrementallty, means that the number switching to C++ is always overwhelmingly larger than the number adopting Rust from all starting points.

We may lament that they do not start writing modern, high-level C++ immediately, but the number of CppCon (and similar) talks hosted on Youtube, and rocketing attendance at, and number of, such events, shows that there is great interest in learning good modern C++.

Re:C++ coroutines: Initial implementation pushed to master by EliRivers on Sunday January 19, 2020 @06:20AM (#22090793)
In my experience, the majority of C that is used is actually by people who think they're working in C++, because they were taught to use manual memory management, raw pointers and other such C-like constructs. Some keywords about classes were thrown in towards the end of "C++ 101" or whatever they learned from, and away they go, writing C with classes like the last 30 something years never happened.
Re:C++ coroutines: Initial implementation pushed to master by jefftk on Sunday January 19, 2020 @07:52AM (#22091176)
That's still C++, just not modern C++.
Re:C++ coroutines: Initial implementation pushed to master by EliRivers on Sunday January 19, 2020 @10:12AM (#22091806)
Technically, in that the C++ spec allows it, yes, it's C++. However, I find such definitions to be of little practical use, although frequently in the workplace I sit and wait while someone satisfies their need to carefully divide the world up into precise, clear, exacting and useless definitions before we can get on with doing something useful - the industry just seems to attract that; often they don't care about trashing all those lines immediately afterwards, so long as everyone acknowledged the lines. That said, the discussion about how many layers there are in a model of networking and what they're named rendered some people unable to do anything for the rest of the day.

Colloquially and practically, I might suggest that it demonstrates that the programmer may be dangerously thinking in C with little lumps of data as their classes. The programmer is thinking and coding in C, with some classes, that they then feed to a C++ compiler.

People were doing it like that back in the nineties, when what we think of as "modern C++" didn't exist.

Re:C++ coroutines: Initial implementation pushed to master by rossmohax on Sunday January 19, 2020 @08:11AM (#22091253)
AFAIK this very problem is addressed with introduction of move semantic and the goodness, which comes with it, such as unique_ptr instead of raw pointers. With that default move assignment operator does the right thing by default. So C++ langauge development actually improves simplicity and correcness as least for this particular example.
Re:C++ coroutines: Initial implementation pushed to master by tsimionescu on Sunday January 19, 2020 @04:50PM (#22094360)
> Someday I'll put together a page listing the dozens of C++'s design daults.

It's pretty old and somewhat outdated by now, but you might enjoy the C++ FQA (Frequently Questioned Answers):

https://yosefk.com/c++fqa/

Re:C++ coroutines: Initial implementation pushed to master by gdy on Sunday January 19, 2020 @08:32AM (#22091336)
"Here's just a single article demonstrating how incompatible with simplicity and correctness C++ is"

I don't see where is the problem. Perhaps, you could give an example of the equivalent code in your favorite language?

Re:C++ coroutines: Initial implementation pushed to master by stjohnswarts on Monday January 20, 2020 @04:30PM (#22102239)
Almost no one is using Rust in embedded. C++ has a much higher uptake among that crowd.
Re:C++ coroutines: Initial implementation pushed to master by tsimionescu on Sunday January 19, 2020 @05:06PM (#22094443)
I'm not sure modern C++ has proven to be safer than C (old C++ most certainly has not). Also, I'm not as sure as you that there is an overwhelming number of people adopting modern C++, given the slow speed at which I've seen at least my company being able to move to C++11 and then C++14.

The reality is that C++ is still an extremely unsafe language, where any slight deviation from strict discipline (discipline that itself has only really been ergonomical since C++14 or so) will lead to memory corruption errors. Even with modern C++ features you can get memory corruption: null references, references to moved objects, no way to signal errors from destructors, and there is still no good way to check whether an operation on ints will overflow. Moreover, the insistence on optimizing around undefined behavior, specific to C and C++ I believe, coupled with large reliance on undefined behavior in the standard, leaves C++ in a very poor position as far as guarantees of safety are concerned.

In general, the responsible thing if we want a more secure world would be to discourage the use of manual memory management as much as possible, whether it be in C, C++ or Fortran. That does include trying to get people to use smart pointers if they absolutely have to use C++, but it should also include getting people to use other languages if at all possible (Java, C# or Go would be the more mature ones for large business).

Re:C++ coroutines: Initial implementation pushed to master by inDigiNeous on Monday January 20, 2020 @05:40AM (#22097908)
You're saying that switching to "safe" modern C++ is just something you could do at a whim. Learning how to write safe C++ is a hell of a task to undergo, and still you are at the mercy of your program crashing even though you have taken careful approach to memory management etc.

Modern C++ is just not a safe language to program with. It is very easy to produce errors that result in segmentation faults, and it takes great care to produce code that works properly even with shared_ptrs and unique_ptrs and so on.

But you are correct that adoption of C++ is higher than Rust, and will continue to be so until some mission critical framework or for example game engine starts to support Rust in as a first citizen language.

Until then, we have modern C++, with all it's quirks and difficulties and lost developer time in figuring out where the hell was that dangling pointer or why the heck was an object not freed correctly, or why did the array access or vector access go off by some value.

Not saying C++ isn't good, it is, but a lot of time is wasted figuring with C++ currently when a lot safer alternative could be used. Unfortunately that is not very realistic in many scenarios yet, although I carefully evalulated Rust also for my current project, the requirement of supporting a C++ game engine just outweighs easily the hassle of having to figure out bridges and bindings and such.

Re:C++ coroutines: Initial implementation pushed to master by ncmncm on Monday January 20, 2020 @11:04AM (#22099744)
Writing safe modern C++ is much easier, and much less work than the old ways. So it is easy to switch, and easy to tell if you are Doing It Right: if it's not clean, safe, and easy, there is a better way.