News for hackers. Stuff that matters.
Re:Ask HN: Best way to learn modern C++? by ronreiter on Wednesday March 07, 2018 @08:32AM (#16536196)
May I ask why do you want to learn modern C++?

You should check out Rust, it aims to replace C++ and do a better job in memory management, and developer experience in general (cross-platform compatibility, package management, etc)

Re:Ask HN: Best way to learn modern C++? by maxxxxx on Wednesday March 07, 2018 @08:40AM (#16536219)
One motivation to learn C÷÷ could be to find a job. Rust looks interesting but C++ is still vastly more popular.
Re:Ask HN: Best way to learn modern C++? by pjmlp on Wednesday March 07, 2018 @08:48AM (#16536258)
Rust still needs to catch up with C++ in a few domains.

SIMD, GPGPU, GUI, embedded platforms, iOS, Android, UWP, COM, certified compilers, ...

Re:Ask HN: Best way to learn modern C++? by steveklabnik on Wednesday March 07, 2018 @09:32AM (#16536580)
Incidentally, SIMD is just waiting on stabilization now; it’s RFC was accepted and the implementation landed. Soon!
Re:Ask HN: Best way to learn modern C++? by AnimalMuppet on Wednesday March 07, 2018 @12:25PM (#16537962)
Will Rust have idioms for really doing SIMD in Rust? If I understand correctly, C++ has to drop into assembly to do SIMD (at least so far).
Re:Ask HN: Best way to learn modern C++? by steveklabnik on Wednesday March 07, 2018 @12:47PM (#16538178)
I don’t believe that’s correct for C++.

Regardless, yes, that’s the whole point. What’s been accepted is https://doc.rust-lang.org/nightly/core/arch/index.html , that is, intrinsics that map 1-1 to the vendor APIs. (I belive this is the same in C++ but not my area of specialty so I may be wrong)

https://doc.rust-lang.org/nightly/core/simd/index.html is the first level up the abstraction chain; this hasn’t gone through an RFC process yet, but will eventually happen.

On top of that, you have stuff like https://crates.io/crates/faster , which is very high level. Looks like they need to fix up the README... but you get the idea.

Also, autovectorization has existed this entire time. This stuff is for when that falls down.

Re:Ask HN: Best way to learn modern C++? by pjmlp on Wednesday March 07, 2018 @12:37PM (#16538078)
C++ doesn't need Assembly for SIMD.

Most compilers do a reasonable job with auto-vectorization, and if more is needed, there are instrisics.

No need to write straight Assembly.

Re:Ask HN: Best way to learn modern C++? by AnimalMuppet on Wednesday March 07, 2018 @12:46PM (#16538164)
OK. (The one time I encountered SIMD in C++ was a decade ago; we had to use assembly then. And even then, we weren't playing with an up-to-the-minute compiler. (In my experience, your comments elsewhere on this article about embedded toolchains were accurate.)

Are the intrinsics standard? If so, what version of the standard were they in? How good is compiler support for them?

Re:Ask HN: Best way to learn modern C++? by AstralStorm on Wednesday March 07, 2018 @01:21PM (#16538501)
Not standard, unless you count "supported with the same semantics in multiple compilers" as good enough.

They are not portable between CPU architectures either way

For reference, C got real alignment support in C11 and C++ in C++17. Without this, even starting on SIMD is risky.

That said, you can go really far with a good C++ math library like Eigen which has singe vectorization in the operations themselves.

Re:Ask HN: Best way to learn modern C++? by xfer on Wednesday March 07, 2018 @09:05AM (#16536376)
what do you mean by "certified" compiler here?
Re:Ask HN: Best way to learn modern C++? by pjmlp on Wednesday March 07, 2018 @09:10AM (#16536404)
In certain industries, specially where human lives are at stake you can only use certified compilers, where the kind of code they generate is validated against specific safety standards.

For example,

https://www.iar.com/iar-embedded-workbench/certified-tools-f...

Re:Ask HN: Best way to learn modern C++? by hsivonen on Wednesday March 07, 2018 @09:53AM (#16536744)
As a programmer using the compiler, how does the IAR compiler quality feel in practice compared to GCC or clang?
Re:Ask HN: Best way to learn modern C++? by pjmlp on Wednesday March 07, 2018 @10:12AM (#16536881)
I never used IAR, given my focus on writing safe software I try to be up to date to these areas, and ways to somehow write secure software in C and C++. like MISRA and Frama-C.

Maybe someone else can jump in.

However, I can tell you that in general proprietary compilers for embedded devices make Visual C++ feel state of the art, let alone when compared with gcc or clang.

Many of them are stuck in partial support for C99 or C++98 (e.g. TI), with no clear roadmap of future improvements.

Re:Ask HN: Best way to learn modern C++? by sjapkee on Wednesday March 07, 2018 @08:47AM (#16536253)
>replace C++

No one can replace it, but everyone has to try.

Re:Ask HN: Best way to learn modern C++? by bigcheesegs on Wednesday March 07, 2018 @09:04AM (#16536370)
Rust is the first language I've seen that even has a chance though.
Re:Ask HN: Best way to learn modern C++? by ahartmetz on Wednesday March 07, 2018 @09:31AM (#16536578)
Yup. D had a shot, but they screwed it up with (effectively) mandatory garbage collection.

Ada also had a shot, I think, but they screwed it up with no C compatibility and expensive SDKs - or something. For some reason, Ada is just not perceived as "cool". It actually seems like a pretty good language!

Re:Ask HN: Best way to learn modern C++? by pjmlp on Wednesday March 07, 2018 @09:50AM (#16536717)
The issue with D is not mandatory garbage collection, rather its quality and anti-GC religion.

Joe Duffy mentioned on his Rustconf talk that Windows devs even with Midori running in front of them, it was still a very hard sell for them to psychology accept it as doable.

The problem with Ada was basically expensive SDK, Pascal-like syntax and not being part of OS SDKs.

Only systems programming languages that are bundled with OS SDKs survive on the market, others either get a niche (Ada - high integrity systems) or fade into oblivion/maintenance (Modula-2, Delphi, ...).

The main reason being, companies already payed for OS SDK or gotten it for free with the OS.

Any other language must add a very worthwhile set of benefits for them to look beyond the SDK and possible toolchain integration issues.

Re:Ask HN: Best way to learn modern C++? by jcelerier on Wednesday March 07, 2018 @01:41PM (#16538667)
> Windows devs even with Midori running in front of them,

There were GC'ed operating systems in the 80s. The point is not this. It's writing applications where you can maximize your CPU usage.

If it's a game, it means that you want to write your code so that the highest number of objects are visible on screen and are being updated on each tick. If its's a multimedia software, you want to be able to run most sounds / videos in parallel at the same time. If it's an interpreter, you want to have the highest instructions-per-second count.

etc etc... the point is not to have "good enough" performance, it never has been as soon as you use non-trivial apps. It's always "how fast can it be" / "how far can I push it", and an implicit language-level GC puts limits to this.

Re:Ask HN: Best way to learn modern C++? by pjmlp on Wednesday March 07, 2018 @02:22PM (#16539017)
Having a GC enabled OS doesn't mean the GC runs all the time or it is the only way of allocating memory.

The last generations of Oberon OS had support for video editing applications as an example.

There are real time GC applications in production being used to control weapons systems, including live targeting and soft real time factory automation systems.

Regarding D, using @nogc or -vgc allows the developer to control when the GC works, it at all. What the language lacks is a GC that can match real-time GCs used in soft real time systems.

Re:Ask HN: Best way to learn modern C++? by AnimalMuppet on Wednesday March 07, 2018 @12:36PM (#16538073)
> Only systems programming languages that are bundled with OS SDKs survive on the market...

Hmm. To Rust, this would seem to say "get bundled or die".

In your view, is it enough to be a free download?

Re:Ask HN: Best way to learn modern C++? by pjmlp on Wednesday March 07, 2018 @01:36PM (#16538626)
I don't see a free download as being enough.

At very least, there needs to exist painless interoperability with the SDK toolchain, debugging tools, IDE, platform libraries.

Every piece of the puzzle that doesn't quite work like the SDK tools, means additional development/debugging effort.

Naturally the big question is always if the added benefit of using language X outside the expected workflow outweighs the extra development costs.

Just look at C++, it was on the path of being widely adopted by desktop OSes, every C compiler vendor was adding support for it.

Then BSD and Linux large scale adoption happened with GNU manifesto favouring C as the language to write portable software, Java and .NET came into the scene.

Microsoft was probably the only major OS vendor still caring about it, until LLVM happened and the wind started blowing again with C++11.

The embedded space is still an area where C++ is hardly seen, with a few conference talks last year discussing on how to advocate for it.

Now all major C compilers are written in C++, but had Microsoft focused only on .NET or LLVM never happened, and history would probably followed another path.

Re:Ask HN: Best way to learn modern C++? by Fabien_C on Thursday March 08, 2018 @06:04AM (#16543636)
Ada has built-in C/C++ interfacing: https://gcc.gnu.org/onlinedocs/gnat_ugn/Interfacing-to-C.htm...

For instanced I used it here to write Ada programs for the C API of the Pebble smartwatch: https://blog.adacore.com/make-with-ada-formal-proof-on-my-wr...

Re:Ask HN: Best way to learn modern C++? by carlmr on Wednesday March 07, 2018 @09:50AM (#16536722)
ADA is really good, but too much word vomit and the compilers (used to?) cost a lot of money.
Re:Ask HN: Best way to learn modern C++? by yoz-y on Wednesday March 07, 2018 @09:30AM (#16536564)
Languages rarely get replaced though. We are just adding to the pile.
Re:Ask HN: Best way to learn modern C++? by ahartmetz on Wednesday March 07, 2018 @09:38AM (#16536628)
Only in a very strict interpretation that everything that is still used somewhere didn't get replaced. Perl was more or less replaced, for example, and I like that. The only kind of originality that is good in programming is "surprisingly simple". "Surprisingly weird" is terrible.
Re:Ask HN: Best way to learn modern C++? by oblio on Wednesday March 07, 2018 @10:00AM (#16536798)
You're going to get at least 1 angry Perl programmer explaining that Perl is actually thriving and it's never been better to be a Perl programmer :p

Which is actually partially true... the long tail of programming languages today is very, very big. There's probably 10-50x more programmers now than there were back in 1995. The programming world can probably sustain 10-20 mainstream languages these days, if not more.

Re:Ask HN: Best way to learn modern C++? by kamaal on Wednesday March 07, 2018 @10:51AM (#16537190)
>>Perl is actually thriving and it's never been better to be a Perl programmer :p

Don't know about that. But only yesterday afternoon I spent like 2 hours writing a Perl script to heavy lift some Unix file work, Which I factored would take a week at-least to do in any other language.

Perl is still largely a very useful language without any replacements. So are awk and sed.

Web development world seems to have moved on to something else now.

Re:Ask HN: Best way to learn modern C++? by oblio on Wednesday March 07, 2018 @11:16AM (#16537359)
> But only yesterday afternoon I spent like 2 hours writing a Perl script to heavy lift some Unix file work, which I factored would take a week at-least to do in any other language.

I'm guessing you're more familiar with Perl, because I personally find it hard to believe that Perl by itself is an order of magnitude more efficient to write than Python or Ruby.

Re:Ask HN: Best way to learn modern C++? by kamaal on Wednesday March 07, 2018 @10:58PM (#16542170)
>>I personally find it hard to believe that Perl by itself is an order of magnitude more efficient to write than Python or Ruby.

Ruby is ok. But Perl is million times a better language than Python.

Python is an extremely overrated language.

Re:Ask HN: Best way to learn modern C++? by oblio on Thursday March 08, 2018 @06:00AM (#16543620)
You haven't addressed my (implied) question,though. I don't think that the average Perl programmer is an order of magnitude more productive than the average Python programmer.
Re:Ask HN: Best way to learn modern C++? by vgy7ujm on Thursday March 08, 2018 @02:13AM (#16542877)
Well said!
Re:Ask HN: Best way to learn modern C++? by cmollis on Wednesday March 07, 2018 @11:33AM (#16537498)
+1
Re:Ask HN: Best way to learn modern C++? by Froyoh on Wednesday March 07, 2018 @12:44PM (#16538149)
Java?
Re:Ask HN: Best way to learn modern C++? by cpburns2009 on Wednesday March 07, 2018 @09:09AM (#16536395)
I'm not the OP, but I'm tempted to learn more C++ so that I can directly use Qt without relying on language bindings for it. I like the idea of Rust, and maybe some day I'll tinker with it, but it looks like it has quite the steep learning curve.
Re:Ask HN: Best way to learn modern C++? by steveklabnik on Wednesday March 07, 2018 @09:31AM (#16536574)
First of all, I should say that I feel like bringing up Rust in this thread is inappropriate, and I’m glad the OP was downvoted.

To comment briefly on the learning curve, the trade off is basically, C++ is easier to get started, but harder on the high end. Rust is a bit harder for C people to get started, but then the high end is much easier. Rust’s curve is flatter, in a sense.

Oh and also: learning one will certainly help you learn the other in many cases. I advocate learning many languages :)

This week I’m visiting a ~700 person company in London that’s moving away from C and towards Rust. They’re not doing a Big Rewrite, obviously, so they still have quite a bit of C too. They chose Rust over C++ though. It always depends!

Re:Ask HN: Best way to learn modern C++? by carlmr on Wednesday March 07, 2018 @09:54AM (#16536747)
>Oh and also: learning one will certainly help you learn the other in many cases. I advocate learning many languages :)

Especially the Rust borrow checker will make you mad in the first place, and then teach you something about memory management you will be able to use in C++. It really improves your mental model in places you didn't expect.

Re:Ask HN: Best way to learn modern C++? by cmollis on Wednesday March 07, 2018 @12:41PM (#16538123)
does Rust basically have the same 'move' semantics as C++ ?
Re:Ask HN: Best way to learn modern C++? by steveklabnik on Wednesday March 07, 2018 @12:51PM (#16538214)
Yes and no. The idea is the same, the implementation is very different.

Rust is “move by default, move always means memcpy (and they often can be elided), no move constructors,” to (possibly too) succinctly describe it.

Re:Ask HN: Best way to learn modern C++? by cmollis on Tuesday March 13, 2018 @07:40PM (#16580900)
cool.. I didn't realize that move meant memcpy.. does this operation destroy the original object?
Re:Ask HN: Best way to learn modern C++? by leetcrew on Wednesday March 07, 2018 @09:32PM (#16541813)
if you aren't already very familiar with c, i would say the learning curves for c++ and rust are pretty similar. it will take you longer to get stuff to compile in rust, but correcting instances of undefined behavior in c++ can also take a long time in c++.
Re:Ask HN: Best way to learn modern C++? by cpburns2009 on Wednesday March 07, 2018 @10:07PM (#16541981)
I know enough of the basics of C and C++, and their standard libraries to shoot myself in the foot with, and I'm sure invoke undefined behavior in the process (I do realize they are separate but related languages). Rust on the other hand appears to be a completely different paradigm from my primary experience which is in managed languages (e.g., Python, Java, etc.). In particular the borrow checker, while a marvelous idea, I think would pose a quite the challenge to get accustomed to.
Re:Ask HN: Best way to learn modern C++? by leetcrew on Wednesday March 07, 2018 @10:16PM (#16542027)
it's really not that bad. for a beginning programmer, the places where you would struggle with the borrow checker in rust have a lot of overlap with cases in c/c++ where you would struggle to fix all the errors reported by valgrind.
Re:Ask HN: Best way to learn modern C++? by jxub on Wednesday March 07, 2018 @08:40AM (#16536221)
Mostly because of adoption. Rust is great, but I'm not really into it (subjectively).