4 ms·
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 s
by skrebbel 7y ago
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_error https://en.wikipedia.org/wiki/Substitution_failure_is_not_an...
- gumby 7y agoAny 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.
- TeMPOraL 7y agoI 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.
- otabdeveloper2 7y ago> ...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.)
- TeMPOraL 7y agoHaving 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.
- TeMPOraL 7y agoAFAIR 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.