News for hackers. Stuff that matters.
Re:In Defense of C++ by symlinkk on Monday February 06, 2017 @06:11PM (#13585228)
C++ is an insanely versatile language, and since you can use any C library with "extern C", it has a huge amount of high-quality libraries available for it. ffmpeg, openSSL, webkit, Qt. the problem is there is not a cross platform package manager to manage these libraries, and manually downloading and compiling libraries is a hugely painful and error-prone process. it's so bad that big C++ projects like Firefox and Chromium basically write their own scripts that download and build dependencies, and simply commit the source code of the libraries they use directly into their own tree.

I believe there is some thought being put into making a C++ package standard [0], which would do wonders for the language. in my opinion half of the reason Node took off is because npm is so easy to use, and people are getting excited about Rust partially because Cargo is so well thought out. Now I might be wrong here, but I think if you took modern C++ (no raw pointer manipulation) and combined it with a good package manager, I think you would pretty much erase any advantages Rust offers.

[0]: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2016/p023...

Re:In Defense of C++ by gcp on Monday February 06, 2017 @06:26PM (#13585335)
I think if you took modern C++ (no raw pointer manipulation) and combined it with a good package manager, I think you would pretty much erase any advantages Rust offers.

I've seen this opinion now twice in short succession on HN. Issues with C++ safety aren't just a matter of a dangling pointer that should've been a unique_ptr or shared_ptr. It's massively naive to think that this would in any way be comparable to Rust.

That's not even considering the reality that no real-life C++ codebase seems to survive on those modern C++ features alone. (If it did, I presume Mozilla would've rewritten Firefox in C++11/14/17 instead of Rust. Oh wait, they already use C++11...)

Re:In Defense of C++ by duneroadrunner on Monday February 06, 2017 @09:46PM (#13586555)
> Issues with C++ safety aren't just a matter of a dangling pointer that should've been a unique_ptr or shared_ptr. It's massively naive to think that this would in any way be comparable to Rust.

While I agree, I would point out that in the same way that "safe" Rust is a usable (if difficult to get used to) subset of "unsafe" Rust, there also exist usable safe subsets of C++ [1]. Tooling to enforce that Rust code strictly conform to the safe subset, of course, already exists (and is built into the compiler). Such enforcement tools do not yet exist for C++ code, but I think they're coming. And I think they'll probably support safe subsets that are more convenient/intuitive/easier-to-use than (the current version of) safe Rust.

I wonder if adopting Rust to avoid the pervasive unsafe code in C++ isn't a little bit akin to adopting Esperanto to avoid the pervasive cursing in English. I mean, there does exist a non-vulgar subset of the English language, even if it's difficult to persuade people to stick to it :) But then, if all the cool kids are talking Esperanto...

> (If it did, I presume Mozilla would've rewritten Firefox in C++11/14/17 instead of Rust. Oh wait, they already use C++11...)

I think this may be a missed opportunity by the Firefox developers. If you look at the code, they're still using new/delete and raw pointers targeting dynamic objects. I presume that a lot the code has survived from the pre-C++11 era. I think converting their code to a safe subset of C++ (like SaferCPlusPlus) would be quicker and require less effort than a rewrite in Rust.

[1] for example (shameless plug): https://github.com/duneroadrunner/SaferCPlusPlus

Re:In Defense of C++ by none_for_me_thx on Monday February 06, 2017 @10:11PM (#13586665)
> in the same way that "safe" Rust is a usable (if difficult to get used to) subset of "unsafe" Rust

Where did you get this idea that "safe" Rust is a subset of "unsafe" Rust? Your whole premise here perhaps qualifies as not even wrong: this is not how safety in Rust is conceived or conceptualized.

Re:In Defense of C++ by duneroadrunner on Monday February 06, 2017 @11:08PM (#13586928)
Yeah, that's my point. Even though, unlike C++, (safe) Rust was designed to be (memory) safe from the start, it's notable that Rust and C++ end up (or will soon end up) in the same place - a "usable" safe language and an unsafe superset of that language. It's notable because before C++11, memory safe subsets of C++ could be considered not really "usable". But since the advent of C++11, there are memory safe subsets of C++ that are comparable to Rust in usability and performance [1].

[1] https://github.com/duneroadrunner/SaferCPlusPlus#safercplusp...

Re:In Defense of C++ by none_for_me_thx on Monday February 06, 2017 @11:39PM (#13587081)
I should have said I think you are operating under false assumptions, are making invalid comparisons, and are therefore drawing unwarranted conclusions.

I think you might be confused about what Rust offers and from where Rust's safety is derived. There is no "safe subset" of Rust. As far as I know, that is a nonsense phrase.

Re:In Defense of C++ by dbaupp on Tuesday February 07, 2017 @12:45AM (#13587363)
I think nonsense is rather too strong: Rust-banning-`unsafe` is a subset of the full language accepted by the compiler, and is safe. It isn't rare that people talk about the subset of Rust ignoring `unsafe`.
Re:In Defense of C++ by steveklabnik on Tuesday February 07, 2017 @12:19PM (#13590860)
Usually, we describe unsafe rust as a superset of safe Rust. that is, unsafe Rust is exactly like safe Rust, but gives you extra things.
Re:In Defense of C++ by cousin_it on Monday February 06, 2017 @08:01PM (#13586001)
Does this one-liner count as modern C++?

    const string& s = max<string>("a", "b");
It makes a dangling reference that will crash when accessed. In Rust that's impossible.
Re:In Defense of C++ by symlinkk on Tuesday February 07, 2017 @05:22PM (#13593479)
good point, I had never heard of that.
Re:In Defense of C++ by pjmlp on Tuesday February 07, 2017 @03:37AM (#13588011)
Nice example.
Re:In Defense of C++ by fsloth on Monday February 06, 2017 @06:18PM (#13585270)
"manually downloading and compiling libraries is a hugely painful and error-prone process."

I think you are exaggerating. Most projects with any user base provide ready binaries which able to get going pretty fast.

"it's so bad that big C++ projects like Firefox and Chromium basically write their own scripts that download and build dependencies, and simply commit the source code of the libraries they use directly into their own tree."

I would not call this 'bad' but resilient.

"Replicating is bad" is a non value adding rule of thumb, imo.

That said, yes, it's very hard to start incorporating third party libraries to C++ when compared to any other language.

Re:In Defense of C++ by TillE on Monday February 06, 2017 @09:40PM (#13586521)
Every single C++ project of any significance I've worked on or seen in the wild has some awful dependency compilation script/process. It sucks. There are no good cross-platform solutions. Even if everybody is using CMake perfectly, you still have to glue all the pieces together.

But hey, modules are coming in the next couple years. Should really help with this.

Re:In Defense of C++ by gcp on Monday February 06, 2017 @06:29PM (#13585362)
Most projects with any user base provide ready binaries which able to get going pretty fast.

But what about the dependencies of those binaries/libraries? Manually playing that cat and mouse game just sucks.