Remix.run Logo
▲ vinyl7 7 hours ago

The only sane usage of C++ is to only use a very small subset of its features.

▲ho_schi 7 hours ago | parent | next [-]

https://www.stroustrup.com/JSF-AV-rules.pdf

That’s what Stroustrup does and it works. I just too versatile. Luckily there is recently a push_back against adding new stuff for the sake of it.

My own rules, mine: * Templates are nice. * Template Metaprogramming is not. * Objects and Classes are nice * Inheritance is not.

I like composition and interfaces. I avoid inheritance, aside from some natural cases were it fits (UI Widgets).

I’ve seen in recent years projects switching from C to a mere plain C++. Stronger typing, containers, smart-pointers, simple APIs.

▲chuckadams 6 hours ago | parent | next [-]

Stroustrup does not write all of his code according to the JSF rules. Avoiding dynamic allocation for example isn't appropriate for all apps, especially if one ends up reinventing it poorly.

One thing he does do consistently, and it baffles me why most other C++ codebases do not, is `using namespace std`. It's the standard library, if there's any names that ought to be used unqualified, it's those.

▲tialaramex an hour ago | parent [-]

The C++ Core Guidelines simultaneously tell you that it's fine to do this and that doing it risks (as so often in C++) weird hard-to-understand compiler errors - because if there's any names that should be unqualified it's your names, not those from the stdlib.

Unlike say, Rust, C++ chooses to just shove most things directly in std. You were probably expecting vector, sort and list and if you're paying attention perhaps integral and format but did you expect get_money? invocable? hive? Because those are all defined too. On average your program probably uses several of these universally reserved identifiers, and more get added in each C++ version. Yay.

▲agosz 2 hours ago | parent | prev [-]

Maybe I've been doing this for too long, but I don't see why you'd want to stay away from template metaprogramming, especially with the more recent C++ versions. The type traits header makes heavy use of it (so you're probably using it with if constexpr), and C++14/17/20 make it a lot more readable than it used to be.

▲cogman10 7 hours ago | parent | prev | next [-]

The only sane usage of C++ is "This is a legacy project, needs to integrate with a legacy C/C++ project, or all our engineers are C++ experts and they don't want a new language".

For everything else, you should pick one of any number of other languages. Rust, swift, zig, go, java, python, javascript. Take your pick.

▲pjmlp 6 hours ago | parent | next [-]

Agree, however those other languages will have C++ on their infrastructure maybe forever, due to the costs of fully bootstraping a compiler toolchain and backend support for various kinds of operating systems and processors.

So it is more a kind of gray answer, with polyglot development approach in many cases.

▲ 7 hours ago | parent | prev [-]
[deleted]
▲lordnacho 7 hours ago | parent | prev | next [-]

Which makes various c++ repos look quite different. It's like learning Arabic and then finding out that you can't actually talk to all the other Arabic speakers.

▲pjmlp 6 hours ago | parent [-]

Or learning English proper as 2nd language, and then going to Scotland.

Yet we manage.

▲grg0 4 hours ago | parent [-]

Hoist the sails.

▲marcosdumay 6 hours ago | parent | prev [-]

I just hope whoever selected the subset knows all of the language, so that they can tell if there's something outside of that subset interfering with it or not.