6 ms·
I want to be clear about your meaning, because I don’t know if I’m reading your comment correctly. Are you referring explicitly to syntax based, preprocessor ma
by throwaway17_17 5y ago
I want to be clear about your meaning, because I don’t know if I’m reading your comment correctly. Are you referring explicitly to syntax based, preprocessor macros? Or does your comment extend to other metaprogramming techniques? I am inclined to think you mean the first considering the amount of emphasis on generic programming in D? Just curious.
- WalterBright 5y agoI'm referring to both syntax based (AST) macros, and text based (preprocessor) macros. The latter, of course, are much worse. An example of the former is so-called "expression templates" in C++. I've seen them used to create a regular expression language using C++ expression templates. The author was quite proud of them, and indeed they were very clever. However nice the execution, the concept was terrible. There was no way to visually tell that some ordinary code was actually doing regular expressions. C++ expression templates had their day in the sun, but fortunately they seem to have been thrown onto the trash pile of sounds-like-a-good-idea-but-oops. (I wrote an article showing how to do expression templates in D, mainly to answer criticisms that D couldn't do it, not because it was a good idea.)
- shaklee3 5y agoCan you link to it? We're using expression templates on a new library and I find it useful.
- WalterBright 5y agoOh man, you sure know how to drive a stake in my heart! What have I done! Some curses should just not be uttered. I'm not sure where it is on my backups. But it was done just like you'd do it in C++. The same thing, just with D syntax.
- shaklee3 5y agoWe're making a numerical computing library that expression templates are used for compile-time evaluation of expressions. It's a very niche hpc library, so it might be one of the few places it's appropriate.
- WalterBright 5y agoI wish you luck with it. If you send me an email, when I find what I wrote about it I'll pass it along to you.
- 1980phipsi 5y agoThey probably aren't the only people interested in that...
- acehreli 5y agoI don't know what code Walter is referring to but I had similar experiences during a presentation of the Boost Spirit library (at our Silicon Valley C++ Meeting; must be about a decade ago now). The speaker was proud and beaming for showing how powerful C++ is and the audience was in awe. I was incredulous! Jaw open! The "solution" was horrible with a bunch of workarounds for a bunch of shortcomings. It was a "the emperor does not have cloths" moment for me. Boost Spirit may be better today with newer C++ features; I don't know.
- shaklee3 5y agoThat's kind of the key. We require c++17. Without that it gets extremely ugly and more verbose.
- d110af5ccf 5y ago> Anytime macros are used for metaprogramming, it's time to reach for a more powerful language. > I'm referring to both syntax based (AST) macros ... This surprises me greatly. Various lisps are among the most powerful languages I know of and a large part of the reason is macros coupled with their ability to execute arbitrary code at compile time (which itself uses additional macros, which in turn invoke more code, and so on). What's your take on this? (Continuations are also pretty nice ...)
- deleted 5y ago[deleted]
- WalterBright 5y agoI'm a noob when it comes to Lithp. But I'm told what happens with their macros is the language is fairly unusable until you write lots of macros. The macros then become your personal undocumented wacky language, which nobody else is able to use. I've seen this happen with assembler macro languages, too. > most powerful It's like putting a 1000 hp motor in a car. It's main use is to wreck the car and kill the driver. BTW, D is the first language of its type (curly brace static compilation) to be able to execute arbitrary code at compile time. It started as kind of "let's see what happens if I implement this", and it spawned an explosion of creativity. It has since been adopted by other languages.
- d110af5ccf 5y ago> the language is fairly unusable until you write lots of macros This is not (typically) the case. It would be like saying that you need to write lots of templates to get things done in D. Metaprogramming is certainly very nice to have but it's not a requirement for the vast majority of tasks. It's important to note that Lisps are an entire family of languages; some implementations are batteries included while others are extremely minimal. Where things can get a bit confusing is that many macro implementations are so seamless that significant pieces of core language functionality are built in them. Schemes tend to take this to an extreme, with many constructs that I would consider essential to productive use of the language provided as SRFIs. > macros then become your personal undocumented wacky language That's Doing It Wrong™. You could as well argue to remove goto from a language because sometimes people abuse it and write spaghetti. C++ has operator overloading. D has alias this. If (for example) a DSL is the appropriate tool then being able to use macros to integrate it seamlessly into the host language is a good thing.