Live data from Hacker News

C++ : if constexpr isn't broken

brevzin.github.io

31–40 of 83 posts

Re: C++ : if constexpr isn't broken

#31

Earlier quoted context omitted.

That sounds like concepts, as used extensively in the OP.

One significant difference with concepts is that they are optional.

Gradual typing is mostly a good thing for metaprogramming I think. Even if it was just a compromise for backwards compatibility I'd still take it over C#'s rather limited generics.

Re: C++ : if constexpr isn't broken

#32
post #19
post #16

Earlier quoted context omitted.

Probably because you are used to the paralysed C++ pre C++11. Nothing happens for years and now we have new functionalities every three years supported by all major compilers. But, also, many new functionalities are not for global consumption. The audience of many meta programming functionalities are library developers for example.

Isn't every developer in a non-trivial software project a library developer? As soon as you have a common piece of functionality you want to reuse - that's a library.

> Isn't every developer in a non-trivial software project a library developer? As soon as you have a common piece of functionality you want to reuse - that's a library.

A library, specially a C++ library, is way more than reusable code. Developing a library requires the developer to spend time making fundamental design decisions that he doesn't have to make when developing a module lost somewhere within a project tree, such as how to organize the project into interface and private source files, how the lib should be deployed, how to meet upstream dependencies, how to not break compatibility with previous releases while making your code resilient to subsequent changes, how to add metadata to your project, how to handle optional features, etc etc etc.

Re: C++ : if constexpr isn't broken

#33
post #26

Earlier quoted context omitted.

And that's exactly what's different in D, where the audience for meta-programming is "everyone". It's not just about more power, but how accessible this power is. To think you need to suffer to have this power is not true.

Nothing stops "everyone" from using the features which suit library developers.

Except ever increasing time to learn all the language features and associated best practices.

Re: C++ : if constexpr isn't broken

#34
post #19

Earlier quoted context omitted.

Isn't every developer in a non-trivial software project a library developer? As soon as you have a common piece of functionality you want to reuse - that's a library.

I think that's dependent on language culture. Because the C++ community doesn't take language simplicity or comprehensibility seriously, there are lots of C++ developers who can't use or reason about surprisingly large parts of the language. So the community has rallied around the notion that "library" developers need to understand everything and that most developers will just glue together bits that the library devs…

[deleted]

Re: C++ : if constexpr isn't broken

#35
post #26
post #16

Earlier quoted context omitted.

Probably because you are used to the paralysed C++ pre C++11. Nothing happens for years and now we have new functionalities every three years supported by all major compilers. But, also, many new functionalities are not for global consumption. The audience of many meta programming functionalities are library developers for example.

And that's exactly what's different in D, where the audience for meta-programming is "everyone". It's not just about more power, but how accessible this power is. To think you need to suffer to have this power is not true.

D vs. C++ in this list of examples looked equivalently complex and equivalently power-user focused. static if not introducing a new scope seems like the sort of confusing, error-prone edge case that trips up newcomers, for example. We are taught very early on that in C-style languages curly braces means a scope. Except here in D in this particular case for some reason it's not that isn't clear why until you are very deep into understanding the language.

Similarly operator overloading via a string that tells you what you are overloading seems... insane? Very error-prone & complex?

Not that C++ is great here or anything, but it seems disingenuous to claim D's complex thing is for everyone while C++'s nearly equally complex thing is too complex for everyone.

Re: C++ : if constexpr isn't broken

#36

Earlier quoted context omitted.

One significant difference with concepts is that they are optional.

Gradual typing is mostly a good thing for metaprogramming I think. Even if it was just a compromise for backwards compatibility I'd still take it over C#'s rather limited generics.

I think C# is a good language, but I also am not sure that it's a poster child for this particular language feature. (I mean this literally; I don’t have enough experience to really know how it compares to the usual suspects in this area.)

Re: C++ : if constexpr isn't broken

#37
post #7

Why is it every time I see a new article about C++ features my eyes glaze over? Am I just getting old, or has C++ jumped the shark?

It's because C++ is coming up with more complex ways to solve emergent problems from C++'s own complexity. So to appreciate why a proposal exists in the first place, first you have to catch up on the context that current C++ practitioners already have.

Re: C++ : if constexpr isn't broken

#40
post #26

Earlier quoted context omitted.

And that's exactly what's different in D, where the audience for meta-programming is "everyone". It's not just about more power, but how accessible this power is. To think you need to suffer to have this power is not true.

Nothing stops "everyone" from using the features which suit library developers.

Indeed, but as a large, general-purpose system programming language there are many features that support certain important and special cases, with no application of the language, even library development, using them all.

As an example, we needed locked containers, so wrote a little template and specialized it over the couple of containers we needed. It supported just what we needed. If this same functionality were extended to the standard container library it would not only have need to be thought out to handle every non-locking case, but would have either needed a lot of repetitive boilerplate (and repetitive specializations) or else additional hair that was not worth our while to learn/use. We were able to avoid the problem by adding some documentation in the local style guide.

Post reply on HN