News for hackers. Stuff that matters.
Re:A quick primer on type traits in modern C++ by gumby on Saturday February 29, 2020 @01:24PM (#22452039)
> …when sfinae opened the Turing hatch it doomed c++…

I think that’s unfair. While “sfinae’ itself is a mouthful, what it says in practice is that template expansion observes the principle of “least surprise” which is inherently user friendly.

You certainly don’t need to know the acronym, or even of the idea, to benefit from it. I stead, the developer won’t be presented with a confusing error message when the thing they want to happen is supported but not the first possibility examined.

Re:A quick primer on type traits in modern C++ by skrebbel on Saturday February 29, 2020 @03:23PM (#22452818)
I just learned about sfinae by googling it, so correct me if I'm wrong, but I think you're misreading the GP's comment.

The argument is I think, that because sfinae effectively added an "if" statement to C++ templates, it made templates turing complete. It made it possible to write all kinds insane, undebuggable programs purely at compile-time, in the most terrible purely functional language imaginable. People did exactly that, which went fine until their colleagues (or users of open source libraries) did something unexpected and got screenfuls of errors.

Wikipedia's sfinae page has a nice story about how it added compile-time introspection and conditionals to the language: https://en.wikipedia.org/wiki/Substitution_failure_is_not_an...

Re:A quick primer on type traits in modern C++ by gumby on Saturday February 29, 2020 @03:44PM (#22452969)
Any powerful language (lisp, c++) has plenty of sharp knives in its toolbox. My point was that this tool made it easier to write code that behaves the way the end user expects. Primarily library writers (c++ is full of weirdo constructs that I never use in my code but which people writing libraries use to valuable effect — and which make my code better). While people complain that “c++ has this hard to understand feature” the real question is “does that feature make writing user code easier” and the committee (in ‘17 and ‘20) I hunk have taken that approach.

Sure you can write spaghetti code, but you can do that in almost any language. And there are popular languages that had explici design goals of limiting expressiveness in the hope of reducing spaghetti code (Pascal, in its time, and go today). I consider it like a balloon: without that power you end up with more boilerplate and repeated code, which to me makes following the code harder. But other people reasonably disagree.

Re:A quick primer on type traits in modern C++ by TeMPOraL on Tuesday March 03, 2020 @06:36PM (#22479801)
I think there's a point in rjeli's and skrebbel's comments though. This wasn't designed in from the get go; it started as a hack that got papered over with abstractions and accepted as a standard practice. Despite later improvements, the whole thing still has the aftertaste of a clever hack.

Using a modern example, the way template metaprogramming started feels like return-oriented programming, or those "MOV is Turing-complete" or "MPU error handling is Turing-complete tricks". Someone figured out the standard unintentionally lets you make a conforming compiler do computations, and it ended up becoming an accepted feature, instead of updating the language to something resembling modern constexprs, or Common Lisp's compiler macros.

Re:A quick primer on type traits in modern C++ by otabdeveloper2 on Sunday March 01, 2020 @02:27AM (#22455643)
> ...all kinds insane, undebuggable programs purely at compile-time ... in the most terrible purely functional language imaginable

It's a clean, minimal, purely functional Lisp-like language. Nothing 'insane' or 'undebuggable' about it.

(Well, maybe if you're the kind of person who only ever coded Qt-style OOP C++98 in your life you might be shocked, but for the rest of us there is nothing surprising or special about C++ templates.)

Re:A quick primer on type traits in modern C++ by TeMPOraL on Tuesday March 03, 2020 @06:21PM (#22479699)
Having worked a lot in both C++ and Lisp, I object to calling C++ templating "clean" and "minimal". C++ is a mess. I still love it though.
Re:A quick primer on type traits in modern C++ by TeMPOraL on Tuesday March 03, 2020 @06:29PM (#22479757)
AFAIR Turing hatch was opened before SFINAE; I remember playing with early template metaprogramming examples as a kid (computing a factorial, etc.) which amounted to what the adult me now recognizes as Lisp's cond, that is generalized if-elseif-else. SFINAE only added more places into which you could shove compile-time conditionals.