News for hackers. Stuff that matters.
Re:C++ Is the New Python by eatonphil on Wednesday July 14, 2021 @01:44PM (#27835892)
I would _love_ to see a book on modern (like C++2021 modern) programming in C++ for Python developers.
Re:C++ Is the New Python by munchbunny on Wednesday July 14, 2021 @03:12PM (#27837110)
As someone who learned C++ when it was C++03 and followed the language as it went through 0x all the way to 20, I have no idea how you would be able to avoid crippling a newcomer with the sheer volume of permutations of symbols and language behaviors that a C++ developer might regularly encounter. As a consequence of the ecosystem of older libraries, I've never had the pleasure of fully stepping away from old C++-isms. There's always a naked pointer or a malloc floating around somewhere in code I have to be able to read.

I still occasionally write C++ when I need to, but it's been a long time since I actually enjoyed doing it.

Re:C++ Is the New Python by matthewaveryusa on Wednesday July 14, 2021 @01:52PM (#27836016)
The closest you'll get to that is probably Scott Meyer's effective modern c++ which is for c++14. Scott has retired around in 2015 so don't expect an updated book.
Re:C++ Is the New Python by roxaaaane on Wednesday July 14, 2021 @02:00PM (#27836134)
Actually there is a recently released book[1] by No Starch that gives a tour of modern C++ with details about implementations and librairies and even has a great chapter on unit testing.

[1]:https://www.amazon.com/C-Crash-Course-Josh-Lospinoso/dp/1593...

Re:C++ Is the New Python by Wonnk13 on Wednesday July 14, 2021 @02:34PM (#27836629)
+1 Lospinoso is the real deal
Re:C++ Is the New Python by tialaramex on Wednesday July 14, 2021 @02:03PM (#27836175)
One problem for trying to just learn "modern C++" (so, C++ 20 and explicitly preferring the modern "right" way to do things, Kate Gregory talks about teaching C++ this way) is that C++ got this influential partly by having a lot of libraries. But for a library author, choosing C++20 over C++11 (or worse) means fewer users.

So, sure, all the code from people learning "modern C++" is smart pointers and ranges, but to get work done you have to call this library that takes raw pointers and you're immediately out of your depth.

Re:C++ Is the New Python by vnorilo on Wednesday July 14, 2021 @02:09PM (#27836269)
raw pointers.. or homegrown strings, vectors and hash tables.

C++ soldiers on because it can support such things and adapt to decades of changing hardware and philosophy. But the pain of using and composing libraries in C++ is not just about not having cargo or npm - it's the lack of consensus on data types for anything beyond C primitives.

Re:C++ Is the New Python by TillE on Wednesday July 14, 2021 @02:12PM (#27836315)
This sounds like you're describing C++ from 20 years ago. Or maybe some ugly monstrosity like Qt.

Everything uses/supports standard library containers or interfaces now.

Re:C++ Is the New Python by dekhn on Wednesday July 14, 2021 @02:22PM (#27836467)
There's nothing ugly about Qt. In particular, the core system defines a way to add features to classes that were missing (MOC) and provides a full foundation of types up to network and other event-driven multi-threaded servers. Frankly I think it's one of the best examples of C++ I've seen.
Re:C++ Is the New Python by vnorilo on Wednesday July 14, 2021 @02:20PM (#27836419)
Some counterexamples that I've dealt in the recent years include LLVM, Abseil and Windows COM APIs.
Re:C++ Is the New Python by TillE on Wednesday July 14, 2021 @02:10PM (#27836284)
Smart pointers are a weird example because they're ancient. I'd say the majority of C++ libraries expect C++11, many C++14.

Also it's still completely normal to use raw pointers or references when a function doesn't care about ownership.

Re:C++ Is the New Python by tialaramex on Wednesday July 14, 2021 @03:21PM (#27837226)
> Smart pointers are a weird example because they're ancient.

I am an old man, and to me 2011 doesn't feel ancient, but fair. C++ 11 has unique_ptr and shared_ptr (if your library uses a previous generation of smart pointers you're in worse trouble than if it had raw pointers) and that's what you'd probably teach in class today.

> Also it's still completely normal to use raw pointers or references when a function doesn't care about ownership.

This is true. So you can't tell. And, with a different hat on it's also something that Kate Gregory has given talks about. As the new maintainer for several MLOC of C++ what can I conclude about this function that takes a raw pointer to a foo ?

Maybe, it just wants to look at a foo, immediately and then has no further interest in it.

Maybe, it will mutate the foo, immediately, and then loses interest.

Maybe, it will hang on to this pointer and use it later, who knows when. Thus, now it "owns" the foo, I hope it will clean up after it ceases using it because I can't now.

Maybe, I'm supposed to provide an "empty" foo and the contents of it afterwards are the primary result of the function.

Those are pretty different, so it's disappointing that we don't learn which it is from the function signature.

Re:C++ Is the New Python by saurik on Wednesday July 14, 2021 @02:51PM (#27836849)
Huh. There simply aren't that many C++ compilers in the world that matter... who is working with a C++11 compiler, but doesn't have at least C++17? (The core problem with C++20 is that support is still spotty: like, I am waiting with baited breadth for clang to finally get around to P1091R3/P1381R1... they list it as "partial", but it feels like "not even started".)
Re:C++ Is the New Python by markus_zhang on Wednesday July 14, 2021 @02:23PM (#27836480)
I'm on the same line. I'd love to see a book focused on practical C++/11/17 with non trivial projects. Effective Modern C++ explains a lot of things, but concrete examples are a lot better.

Some projects in mind:

C++/SFML/SDL2 game programming using modern C++

Interpreter/compiler construction in modern C++

Explains how to implement things in modern C++ (e.g.unique_ptr) without modern C++ (maybe just use C)

Re:C++ Is the New Python by eatonphil on Wednesday July 14, 2021 @02:33PM (#27836623)
Yes, just talking about the language isn't enough.

Solving somewhat complex problems with standard data structures (maps, trees, hashtables, etc.) and doing it in the modern, efficient way is the kind of thing I'm really looking for.

In Python it's easy (which isn't to say everything should use Python) because you don't have to do anything but use the builtin datastructures and solve your problem.

Maybe modern C++ works the same way but if it does, I still need someone to show it since that isn't how it used to be (to my knowledge).

Re:C++ Is the New Python by markus_zhang on Wednesday July 14, 2021 @02:48PM (#27836810)
Yeah the thing is I don't know if there is any _good_ small-medium modern C++ code base to read.

Eventually I just gave up and use raw pointers. My theory is that since people don't care about JVM not returning memory to system, they should also not care a bout a few MBs of memory leak in my small game.

Re:C++ Is the New Python by monkeybutton on Wednesday July 14, 2021 @02:22PM (#27836454)
What about a book or resources for someone who already knows C++? I haven't used it in 10 years and even then, where I worked at the time, using C++11 features was "off-limits". Just from a cursory glance, a lot seems to have changed since then?
Re:C++ Is the New Python by Zababa on Wednesday July 14, 2021 @02:07PM (#27836239)
I would love to see a book on modern C++ (11 and beyond) in general, for people used to other languages. I'd like to learn it at some point but it's honestly really intimidating.