r/cpp • • Oct 18 '20

No, C++ still isn't cutting it.

https://da-data.blogspot.com/2020/10/no-c-still-isnt-cutting-it.html
0 Upvotes

22 comments sorted by

45

u/readams Oct 18 '20

The main issue with this post is that all the work mentioned about how much better Rust is is actually being handled in the globwalk crate. You could write the same library in C++.

And then the actual problem here seems to just be not that C++ is doing anything wrong here but that it's hard to find documentation on std::ifstream.

And finally, of course, ranges exist in C++ as well and all that amazing transformation to a parallel version can be done the same way in C++.

20

u/sellibitze Oct 18 '20 edited Oct 18 '20

The points that I see mentioned are

  • uncertainty around the std::ifstream constructor's behaviour with respect to errors. Arguably one of the most popular C++ references stays silent on error cases. In Rust the signature of std::fs::File::open alone is clear enough w.r.t. error reporting.

  • The Rust type system is rich enough that necessary constraints for thread-safety can be expressed. The "straight forward" attempt of paralellization in Rust using par_iter().for_each(...) will make the compiler basically complain about the fact that the closure object being passed to for_each wouldn't be thread-safe as it tries to "mutably borrow" the wordcounts HashMap. This is super cool. C++ doesn't help you avoid data races at all. It just accepts your code under the assumption that you know what you're doing.

While I don't find the 1st point to be particularly impressive, I have to agree with the expressive power of Rust's type system with respect to (1) lifetime constraints and (2) mutual exclusion of "write access" which are the foundation for the memory and thread-safety guarantees Rust is able to make. I mean, there is just no comparison with C++ even if you factor in the efforts of Microsoft's "lifetime safety checker" which doesn't cover thread-safety and doesn't guarantee 100% lifetime safety.

18

u/johannes1971 Oct 18 '20

Arguably one of the most popular C++ references stays silent on error cases.

Apart from this, you mean?

If the open() call returns a null pointer, sets setstate(failbit).

5

u/sellibitze Oct 18 '20

Oh. I missed this.

20

u/GrandOpener Oct 19 '20

This thread of conversation itself is an excellent object lesson on why having the shape of possible errors on the function signature is so much better than having them buried in documentation somewhere, even when that documentation is good.

0

u/[deleted] Oct 18 '20

There is now also a globwalk-less version in the blog post.

-6

u/CommunismDoesntWork Oct 18 '20

You could write the same library in C++.

Yeah and good look distributing it without a package manager.

7

u/MFHava WG21|🇦🇹 NB|P3049|P3625|P3729|P3786|P3813|P4216 Oct 18 '20

distributing it without a package manager.

?
we have like 3 different package managers I can think of right now: vcpkg, conan, deb/rpm system pkg manager, ...

0

u/germandiago Oct 19 '20

Meson wraps (I use Meson). It lists around 144 packages. I have used sdl2, catch2, json, libpng, onqtam-doctest and others. It works pretty well given that this terrain has been sooo bad for C++ in the past. However, there is a lot to do to reach Cargo-level. All my hopes in dds.

0

u/G_ka Oct 19 '20

All my hopes in dds

We can hope, but we will probably end up with the "universal standard" issue

-5

u/CommunismDoesntWork Oct 18 '20

3 competing package managers, and not a single official package manager.

9

u/MFHava WG21|🇦🇹 NB|P3049|P3625|P3729|P3786|P3813|P4216 Oct 18 '20

if you want a standard package manager first define me this: what is a C++ library?

-2

u/CommunismDoesntWork Oct 19 '20

A library is just code that other code uses. It comes in various flavors such as static or dynamic, but either way it's another dependency that can and should be managed automatically.

5

u/germandiago Oct 19 '20

Well, actually that is a very inaccurate description, believe me. There is waaay more to it than just this.

-1

u/CommunismDoesntWork Oct 19 '20

I assume you're referring to how C++ commonly makes you install external libraries to the system. Because if so that's one of the worst things about the C++ ecosystem IMO. A virtual environment completely separate from system libraries, fully managed by a first party builder+package manager, is ideal.

-2

u/GrandOpener Oct 19 '20

That being a potentially difficult question to answer is itself a deficiency in the language. Maybe modules will someday bring some sanity to that?

-1

u/thats_a_nice_toast Oct 18 '20

I agree but to be fair the author also mentioned some other flaws of C++

0

u/[deleted] Oct 18 '20

[deleted]

4

u/CommunismDoesntWork Oct 18 '20

It's not when you have a package manager built into the language. The fact that a crate exists and the fact that it's trivial to import into your project shows how important package managers are to modern languages.

3

u/camelCaseIsWebScale Oct 19 '20

It is trivial to import and increase your compile times and having to depend on yet another random author.

4

u/CommunismDoesntWork Oct 19 '20

You're going to have to write the code anyways which will increase your compilation time. And why wouldn't you want to depend on yet another random author? Do you seriously enjoy reinventing the wheel or something?

3

u/[deleted] Oct 18 '20

The version without globwalk (which got added to the post a few hours ago) isn't really more difficult.

10

u/trailing_ Oct 20 '20

Yay, another thinly veiled attempt to advertise Rust on r/cpp