Live data from Hacker News

C++ Should Be C++

open-std.org

121–130 of 191 posts

Re: C++ Should Be C++

#121

Earlier quoted context omitted.

Your specific gripes seem reasonable (I suspect design-by-committee plays a big part), but: > I really wish the std would drop this pretense and focus on C++'s strong point: Continue being the fastest systems language possible. You've essentially described C, not C++. C++ has a different philosophy and makes different trade-offs. C++ is at least still pretty committed to the you only pay for what you use principle. A…

> You've essentially described C I'd disagree pretty strongly with that. C is more focused on being relatively simple to implement and backwards compatibility with the past 50 years. (I read a blog post by a C committee member talking about that recently, wish I could find the link) Just look at the garbage fire which is the standard library. qsort. strtok. rand. C++ should (in theory at least) be able to match or su…

Yeah, I think a degree of complexity is required to achieve being the fastest compiled language.

To achieve that, you need stuff like monomorphized templates, actual arrays and slices being distinguished from pointers, well-defined rules on pointers (like Rust's rules about references and mutable references, or strict aliasing in C++), and the freedom to let the compiler reorder structure fields for better alignment and space usage. Runtime polymorphism, like virtual functions in C++, are better as a core language feature rather than something implemented as a struct of function pointers, because that way the compiler can devirtualize some calls.

All of these things, I think most C programmers would be against adding to C. And pointer rules are historically controversial; for example, Dennis Ritchie was against adding noalias to C in 1988[1].

[1]: https://www.yodaiken.com/2021/03/19/dennis-ritchie-on-alias-...

Re: C++ Should Be C++

#122

Earlier quoted context omitted.

> As I understand it, C++’s slow compilation comes from the fact that it usually parses all of your header files n times instead of once. That's one of the things that can slow compilation down but it's definitely not the only one. It helps that precompiled headers (and maybe modules?) can go a long way towards reducing and possibly eliminating these costs as well. I think some (most?) of the larger remaining costs r…

> due to the fact that the linker needs to do extra work to eliminate redundant instantiations. Yeah, I see this as another consequence of C++'s poor compilation model: - Compilation is slow because a template class in your header file gets compiled N times (maybe with precompiled headers). The compiler produces N object files filled with redundant code. - Then the linker is slow because it needs to parse all those o…

I'm not sure I'd call the design "bad". At the very least it's a product of the design constraints, and I'm not sure there's an obviously better implementation without sacrificing something else. I think separate compilation and monomorphization are the biggest contributors, but I wouldn't be surprised if there was something I was forgetting.

Somewhat related, there was some work in Rust about sharing monomorphized generics across crates, but it appears it was not a universal win at the time[0]. I'm not sure if anything has changed since that point, unfortunately, or if something similar could be applied to C++ somehow.

[0]: https://github.com/rust-lang/rust/issues/47317#issuecomment-...

Re: C++ Should Be C++

#123
post #8

Nevermind the language itself, we need a way to pull compilers and project dependencies, pinned to their specific versions, with a single, ergonomic tool. vcpkg seemed really promising but the fact that they didn't start with library versioning from the get go was a very stupid decision, and nowadays versions are pinned to specific commit hashes rather than actual dependency versions, and libraries that weren't previ…

vcpkg was dead in the water because they altered source packages. Completely unacceptable in many situations.

vcpkg are forced to alter source packages because in the majority of cases upstream doesn't have working cross platform builds. They have weird broken CMakeLists.txt, incomplete compiler support, weird build incompatibilities with other libraries etc.

Re: C++ Should Be C++

#124
post #12

> It is easy to see that C++ is fit as a general-purpose programming language–adoption by millions is a testament to that. No, that is false. It is akin to arguing that Christianity must be true because 2.4 billion Christians can't be wrong. The fallacy is easy to see because the argument can be applied equally to the world's 1.9 billion Muslims and 1.2 billion Hindus and 500 million Buddhists, etc. And yet these gro…

> "to show that it is possible for large groups of people to hold false beliefs"

The claim from the article is not about their beliefs, it is about their activity. If a million people say that one can live many different lifestyles from a tent but those people actually live in suburban houses, they can potentially all be wrong. If a million people actually do live in tents while living many different lifestyles, QED, it is demonstrated - they aren't holding false beliefs, full stop. It's not a belief anymore, it's a fact. The fact that they are doing it shows it can be done at all, and the large numbers show it's not an extreme claim that only one or two weirdo obsessives could contort themselves enough to use, it's general enough for millions to do over many lifestyles.

> "Everyone is doing it" is absolutely no indication that "it" is a good idea.

It is too; "When in Rome" is advice because whatever the Romans are doing, it isn't killing them or getting them into fights or mugged or annoying someone powerful. If you don't have any reason to do otherwise, eating what the Romans eat, drinking what they drink, behaving how they behave, is a far far better starting point than almost any other. As a guest in someone's house, trying behave how the homeowners behave is a good idea; 90+% of starting points will be worse, most things you could try to eat will make you ill or kill you, most of the world's thousands of programming languages are toys or niche domain systems or wildly outdated or proprietary and gone out of business. The ones millions of people use? Pretty good idea to use one of those, unless you have very good reasons for doing otherwise.

Re: C++ Should Be C++

#125
The C++ community has some of the best brains around. Absolute geniuses.

If C++ is ok with being a small language used by and for geniuses - I have no problem with that.

If C++ wants to be popular - we need a breaking change between the world of 2023 and 1990 - they don't know what we know now.

I like some parts of C++... it's too bad the "good language" is shackled to a mountain of razor blades.

Re: C++ Should Be C++

#126
post #12

> It is easy to see that C++ is fit as a general-purpose programming language–adoption by millions is a testament to that. No, that is false. It is akin to arguing that Christianity must be true because 2.4 billion Christians can't be wrong. The fallacy is easy to see because the argument can be applied equally to the world's 1.9 billion Muslims and 1.2 billion Hindus and 500 million Buddhists, etc. And yet these gro…

> " to show that it is possible for large groups of people to hold false beliefs " The claim from the article is not about their beliefs , it is about their activity . If a million people say that one can live many different lifestyles from a tent but those people actually live in suburban houses, they can potentially all be wrong. If a million people actually do live in tents while living many different lifestyles,…

> The claim from the article is not about their beliefs, it is about their activity.

No, the claim is about a property of a programming language. The activity is cited as evidence in support of the claim of the fitness of C++ as a general-purpose programming language.

The problem with C++ is that it is a legacy language, and so the fact that a zillion people use it today might be because it's a good language, but it might also be because it has so much institutional inertia behind it that this is enough to override the fact that it's a totally shit language. The Catholic Church has been around for 2000 years, but that doesn't necessarily mean that its factual claims have any merit. The Church's success might be because it is in communion with the truth, or it might be because it has so much institutional and societal inertia that it keeps chugging right along despite having no actual merit. The success of the Church might also be due to people subscribing to the logical fallacy that because a lot of people subscribe to it that it must have some merit, which after a while becomes a self-sustaining cycle. (Note that a self-sustaining cycle is different from a self-fulfilling prophecy because the latter actually becomes true if enough people subscribe to it.)

Re: C++ Should Be C++

#127

Earlier quoted context omitted.

No, C is not the same as it is less expressive. C++ templates allow for declarative nested inlining into a single compilation unit that is extremely difficult to achieve with C macros. See elsewhere in this thread for discussion of boost, it's not applicable.

In this thread: all the people that have never looked at C++ disassembly. Maybe the C++ "language server" of your choice should have a mode where it prints all the constructors destructors copy constructors and what not on top of your code? "Zero cost abstraction" is a big fantasy. C++ is the king of hidden control flow and the costs are everywhere.

Thanks for the shitty attitude but it sounds more like you're looking at the disassembly of debug builds or don't understand how constexpr/consteval work.

Re: C++ Should Be C++

#128

Earlier quoted context omitted.

No, C is not the same as it is less expressive. C++ templates allow for declarative nested inlining into a single compilation unit that is extremely difficult to achieve with C macros. See elsewhere in this thread for discussion of boost, it's not applicable.

In this thread: all the people that have never looked at C++ disassembly. Maybe the C++ "language server" of your choice should have a mode where it prints all the constructors destructors copy constructors and what not on top of your code? "Zero cost abstraction" is a big fantasy. C++ is the king of hidden control flow and the costs are everywhere.

> In this thread: all the people that have never looked at C++ disassembly. Maybe the C++ "language server" of your choice should have a mode where it prints all the constructors destructors copy constructors and what not on top of your code?

That tool is called Godbolt at gcc.godbolt.org. This is common enough that Godbolt is a verb with a lot of C++ programmers.

Re: C++ Should Be C++

#129
TFA cites a much more satisfying since technically substantial distillation of "what C++ is", especially regarding technical goals and technical philosophy: the "Direction for ISO C++" document, 2022, by core members of the ISO C++ committee. [1]

[1] https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2022/p20...

Re: C++ Should Be C++

#130
post #16

I like that this doc at least says that C++ is unergonomic. I'm always saying that good way to learn language patterns and idioms is to look into standard libraries implementations. And when you look into C++ libraries/stdlib, they often look like they're written in another language entirely. This is not normal.

> I'm always saying that good way to learn language patterns and idioms is to look into standard libraries implementations. Why would that be true? When you write a library, you are writing code to cover all possible uses; everything within the scope of your library should at least be considered, even if you personally have no need of that particular bit of functionality. But when you write a program it only has to d…

I think you're right, and perhaps I think the underlying issue uncovered by OP might be: the lack of a single core set of features to achieve a sense of mastery with, that feeling like you've understood an implementation stdlib might have given.

(I will admit I've felt profoundly stupid when I go from "how hard could it be to implement std::optional/reference counted pointers/etc., anyway?", to say GNU's implementation of it in libc++.)

What the feeling of security that new features giveth, having to work with large idiosyncratic codebases and a wide variety of toolchains taketh.

Post reply on HN