7 ms·
D's Mir does the same sort of thing, and metaprogramming in D is much nicer, because it was designed from the ground up instead of the bug elevated to feature t
by jordigh 9y ago
D's Mir does the same sort of thing, and metaprogramming in D is much nicer, because it was designed from the ground up instead of the bug elevated to feature that metaprogramming is in C++.
http://docs.mir.dlang.io/latest/index.html http://docs.mir.dlang.io/latest/index.html
http://blog.mir.dlang.io/glas/benchmark/openblas/2016/09/23/glas-gemm-benchmark.html http://blog.mir.dlang.io/glas/benchmark/openblas/2016/09/23/...
- acdha 9y ago> instead of the bug elevated to feature that metaprogramming is in C++. That inflammatory wording doesn’t add anything to your comment. If you wanted to compare D with C++ it’d be a lot more useful to link to something which does that rather than just the documentation index.
- jordigh 9y agoC++ metaprogramming was an accident. Expression templates are a huge, obscure, and very surprising hack. I don't know about you, but I find them really hard to understand. SFINAE wasn't meant to be used for compile-time branching, but when people realised that it could be used that way, it was just about the only tool for metaprogramming in C++. It certainly wasn't designed for that purpose, though. C++ has for a long time embraced metaprogramming and given new tools for it (I think there's `static if` now? Or will be soon?), but it really all started out as an accident: https://softwareengineering.stackexchange.com/questions/125314/in-c-were-sfinae-and-metaprogramming-intentional-or-just-a-byproduct-of-templ https://softwareengineering.stackexchange.com/questions/1253... > If you wanted to compare D with C++ My second link does that, compares Mir to a bunch of other numeric libraries, most in C++. Edit: (Replying to comment below by acdha because HN does not allow me to post new comments right now.) I don't have that kind of example handy. I can point you to the D Gems section of the D tour to give you a taste of what is possible in D. Click on "Gems" in the navigation menu above to see them. https://tour.dlang.org/tour/en/gems/uniform-function-call-syntax-ufcs https://tour.dlang.org/tour/en/gems/uniform-function-call-sy... If you want a detailed blog post comparing D and C++ metaprogramming, I don't have it ready yet. If you're curious to learn about it, look in more depth at the links I've provided. I'm sorry I don't have the resources to give you the detailed answer you require.
- acdha 9y agoAgain, I'm not defending C++ or disparaging D but saying that this style of abrasive advocacy doesn't leave the reader knowing anything more about D than they already knew. Your last sentence is a great example: > My second link does that, compares Mir to a bunch of other numeric libraries, most in C++. This is technically correct but not helpful because it just shows a bunch of benchmark results. If the point is to demonstrate how D is more powerful for this kind of programming what would be useful is something which shows the same function written in modern C++ and D so you could see how they differ.
- godbolt_com 9y agoc++ is a hack
- flatline 9y agoI know that SFINAE exploited the preprocessor's template overload resolution rules. It was later standardized and expanded on. https://books.google.com/books?id=i7M1DwAAQBAJ&pg=PT564 https://books.google.com/books?id=i7M1DwAAQBAJ&pg=PT564
- tzahola 9y ago>and metaprogramming in D is much nicer, because it was designed from the ground up instead of the bug elevated to feature that metaprogramming is in C++ Yet neither of them are as elegant as LISP macros.
- deleted 9y ago[deleted]
- jordigh 9y agoVery true! I wish D's metaprogramming was slightly more structured instead of relying on raw string concatenation. However, it's not so bad, and it's miles ahead of C++ metaprogramming in terms of ease of use. It's nice that it's so much more deliberately conceived. There's static if, static for, compile-time function evaluation, template and string mixins, and more! I think D's metaprogramming is very close to lisp, possibly as close as possible without having sexps.
- beojan 9y ago> relying on raw string concatenation > it's not so bad You can always use the C preprocessor in C++ if raw string manipulation is enough. Seriously, though, constexpr means C++ also has static if, compile time loops, function eval, etc.
- jordigh 9y agoRaw string manipulation in D's mixins is much more limited than in CPP, and it's also not the only tool available for metaprogramming. https://dlang.org/mixin.html https://dlang.org/mixin.html > constexpr means C++ also has static if, compile time loops, function eval, etc. It's still not quite the same. I'm sorry to not bring examples, but if you look for them yourself, I think you'll find that D's metaprogramming looks nicer than C++'s constexpr.
- nicwilson 9y ago> C++ also has static if Not even close. You can't conditionally insert a member.