(no title)
torlok | 22 days ago
Complaining about a language having features you don't want is silly. C++ doesn't take longer to compile if you don't abuse templates.
torlok | 22 days ago
Complaining about a language having features you don't want is silly. C++ doesn't take longer to compile if you don't abuse templates.
pron|22 days ago
It might be silly if you're working on your own. Software that delivers a lot of value is usually developed and evolved not only by team, but by a team with changing members and changing leadership over the project's lifetime. The features used will be the union of all features used over the years, and while it's easy for team leads to allow the use of more features than their predecessors, it's quite hard to reduce them.
Also, you may be forced to use language features you don't want if they're used by libraries whose functionality you do want. For example, when doing low-level programming, I don't like implicit calls that I can't clearly see on the page (e.g. destructors or overloaded operators). But if libraries I want use them, then I'll have those implicit calls. But if the language doesn't have those features, libraries obviously won't use them.
karamanolev|22 days ago
That's exactly the case when it's easiest. If you don't need a feature, just don't use it and case closed. With a team it's harder - you have to force/enforce others not to use a given feature.
> if they're used by libraries whose functionality you do want
If you're using C++ you can just use the C library you would've used otherwise, no?
Yokohiii|22 days ago
This is quite important and often overlooked. An annoying fallacy is that people think some features are optional, but once they get heavily used, they aren't anymore. Often they quickly become an requirement and if you don't follow suit, your code is legacy or you are an idiot. But well, I guess I create legacy code upfront and the cargo cultists create modern code that turns into legacy next day.
flohofwoe|21 days ago
It actually does though, unless you also drop C++ stdlib usage completely (have you looked at how many lines of code just <vector> alone pulls into each source file? - it's upward of 20kloc and growing with each new C++ version).
And at that point you get into discussions with various C++ camps about why you don't use the C++ stdlib and instead prefer to reinvent the wheel (and this friction with other C++ coders is the main problem of carving out your own subset - it works ok in complete isolation, but software development work hardly happens in splendid isolation and even then you'd might to want to use C++ libraries written by other people from time to time...)
And once you've been dragged into such C++-subset-discussion month after month, year after year, at that point it is much less exhausting to just write plain C. And the C community (if it can be called that) seems to be much less concerned about coding style dogma and generally a nicer bunch to interact with.
FWIW, I switched around 2017 and each time I have to interact with a C++ library for lack of alternatives it's usually not a pleasant experience (with the notable exception of Dear ImGui - but even there I started to prefer the C bindings so that I don't need to strictly separate the UI code from the rest of the code base, which sometimes makes sense, but often not, especially with an immediate mode UI framework).
tialaramex|22 days ago
C++ dynamic dispatch (your "virtual interfaces") is achieved by welding a vtable onto every type and providing a pointer to that vtable for instances of the type. If in 90% of your code you deal with specific types like Goose or Swan or Duck or Seagull, and only 10% needs to work with the broad Bird category well, too bad, every Goose, Swan, Duck and Seagull carries around that vtable pointer even if it goes nowhere near that 10% of the system. This way your Bird code "just works" in C++.
That's not the only way to crack this nut. Idiomatic Rust approach uses vtables only in the Bird code, elsewhere they don't exist, and thus don't take up space in a Duck or whatever that's always a Duck, but in exchange now you're spending more time thinking, because by default there aren't any vtables and so dynamic dispatch isn't possible at all.
So while that C programmer has to implement features by hand, they are at least able to specifically implement the feature they wanted, not whatever was easiest for Bjarne Stroustrup last century.
agentultra|22 days ago
C programs tend to nudge you into thinking in terms of arrays of data.
For game development you generally want to think this way. The cost of vtables and all the cache misses doesn’t have to be paid. A game has to stream bytes. Many things at once. Rarely single elements at a time.
Panzerschrek|22 days ago
It's not true. Virtual methods table is present only for classes with at least one virtual method. Learn C++ properly before doing such claims.
torlok|21 days ago
rramadass|21 days ago
You can get exactly what you are asking for in C++ using techniques of static polymorphism and CRTP pattern (https://en.wikipedia.org/wiki/Curiously_recurring_template_p... and https://en.wikipedia.org/wiki/Barton%E2%80%93Nackman_trick) along with traits and dynamic dispatch (if needed).
For great examples of the above, see the classic Scientific and Engineering C++: An Introduction with Advanced Techniques and Examples by Barton & Nackman (1994).
pjmlp|21 days ago
Now with reflection even more tools will be available.
Which is why despite all its warts and security flaws, many inherited from C source code compatibility, many domains will keep using it, because they will complain about their missing 1% that no one else uses.
petters|22 days ago
Surprisingly, this is not true. I've written a C++ file only to realize at the end that I did not use any C++ features. Renaming the file to .c halved the compilation time.
levodelellis|22 days ago
levodelellis|22 days ago
[deleted]
levodelellis|22 days ago
After writing that, I wrote my own standard library (it has data structs like vector, hashmap and sets; slices, strings, rng, print, some io functions, and more) which uses a lot of templates, and it compiles in <200ms on both clang and gcc. Many standard library headers take much longer to compile than that. It's not a terrible idea to have your own standard lib if you need quick compile times.
rustyhancock|22 days ago
direwolf20|22 days ago
randomtoast|22 days ago
mjburgess|22 days ago
uecker|22 days ago
sandpaper26|22 days ago
gf000|22 days ago
On top of likely having worse performance.
direwolf20|22 days ago
unknown|22 days ago
[deleted]
card_zero|22 days ago
direwolf20|22 days ago
vadersb|21 days ago
pjmlp|20 days ago
Have you bothered to look how GCC and clang are implemented?
feelamee|22 days ago
pjmlp|21 days ago
Drivers, and extension points for userspace.
lelanthran|21 days ago
If your criteria for a good language is "how many features does it have", then sure, C++ wins. OTOH, if you criteria is "How many footguns does the language have" then C++ loses to almost every other mainstream language, which includes C.
Sometimes the lack of footguns is a plus.
jamienicol|21 days ago
pansa2|22 days ago
The main difference from choosing a different subset, e.g. “Google C++” (i.e. writing C++ according to the Google style guide), is that the compiler enforces that you stick to the subset.
ninkendo|22 days ago
Oh, and smart pointers too.
And hash maps.
Vectors too while we're at it.
I think that's it.
pantalaimon|22 days ago
saidinesh5|22 days ago
krapp|22 days ago
I feel like if you need to implement modern language features, you shouldn't be using C. The entire point of C is to not be modern.
wasmperson|22 days ago
It's arguably irrational to evaluate a language based on this, but you can think of "this code could be better" as a sort of mild distraction. C++ is chock full of this kind of distraction.
etrvic|22 days ago
cogman10|22 days ago
A reason I can think of to not move to C++ is that it is a vast language and, if you are working on a team, it can be easy for team members ultimately forcing the whole team to become an expert in C++ simply because they all will be familiar with a different set of C++ features.
But for a solo dev? No reason not to use it, IMO. It's got a much nicer standard library with a rich set of datastructures that just make it easier to write correct code even if you keep a C style for everything.
whizzter|22 days ago
HoldOnAMinute|22 days ago
A lot of smart people pick and choose what they want from the language, just like religion, they keep the good parts and discard the bad.
direwolf20|22 days ago
Even with the recent extension where it looks like it isn't, the compiler adds one for you.
patrick451|21 days ago
bobajeff|22 days ago
direwolf20|22 days ago
Regrettably not every C++ feature is free if you don't use it. But there aren't many that aren't.
Suppafly|22 days ago
That's definitely harder.
tomcam|22 days ago
Mindread much?