4 ms·
as someone that has been using c++ since the late 1980s, can i observe that about 75% of c++'s features are aimed at library writers? most people writing applic
by zabzonk 4y ago
as someone that has been using c++ since the late 1980s, can i observe that about 75% of c++'s features are aimed at library writers? most people writing application code simply do not need to know the syntax or the semantics of this stuff - these are all features that make c++ libraries simpler, easier and more efficient to use, mostly transparent to the library user.
- FpUser 4y agoAgree 100%
- IshKebab 4y agoYeah this is definitely true. C++ clearly doesn't like "special" features like Go's map, which only the Go authors can implement. As a result it has a ton of features that are extra complicated in order to let you design easy to use APIs.
- zabzonk 4y agovery true. there is almost nothing in the c++ standard library that you cannot rewrite in standard c++. actually, i think nothing.
- dxuh 4y agoAfaik it is just some (quite a few) type traits, like std::is_class and such that you could not write yourself without compiler intrinsics.
- tialaramex 4y agoIt's not nothing, there are numerous intrinsics needed, and also "hacks" where the standard library does something that's labelled UB if you did it in your code but is magically blessed OK when the stdlib does it. That preference to solve things in "the" library leads to other horrible problems though, where C++ ought to have a first class language feature, but instead WG21 has enshrined a workaround in the library which is probably better than if you'd made your own, but rather poor compared to a first class feature. Take the array. Rather than provide a good array type in the actual language, C++ offers std::array, a library class in the standard library. But this standard library class isn't available in "freestanding" C++ while the builtin C-style array is available. So you end up with awkward syntax and the core language loses flexibility. Likewise strings, in Rust the type of an arbitrary literal "Hacker News" is &'static str, a reference to an immutable view of this text which lives as long as necessary. In C++ the type of "Hacker News" is char*, a pointer to bytes. C++ 17 at last provided std::string_view which is the thing you actually wanted for about two decades, but the type of "Hacker News" isn't string_view it's still char*.
- zabzonk 4y agoi have no idea why you think the standard lib is less blessed than the language. > In C++ the type of "Hacker News" is char * Nope it is at least const char , and if you want to assign it to a variable it is: const char * const hn = "Hacker News"; jesus, the hn formatting with this is driving me mad
- tialaramex 4y agoHN thinks asterisks mean you want to emphasise text (these days using italics) so you should in most cases escape them with a backslash. Much of the C++ standard library (including for example std::array) is not available in freestanding C++. Should it be? Perhaps. But it isn't. In contrast to Rust's conscious decision to provide core, alloc and std as separate layers, in the C++ there's a rather ad hoc process to decide what's freestanding.
- lenkite 4y ago> C++ 17 at last provided std::string_view which is the thing you actually wanted for about two decades Err..string_view was available in Boost for quite a while actually - at-least for a decade as far as I remember, possibly more. There are so many missing features in Rust that are only available in crates even today: sane error handling for one/custom allocators for another, but god forbid if you criticise Rust on that basis. You will get downvoted to oblivion.
- ladyattis 4y agoI remember somewhere in one of my undergrad courses textbook that had a quote to something of the effect that C++ was a federation of languages. And honestly, it still feels like that all these years later. It's both a blessing and a curse depending on what you need to do. Most folks probably never venture fair outside their specific subset of C++ to use anything else and probably an unlucky few have to have an esoteric level of understanding the language to do their work. I don't envy the latter.