5 ms·
Ah that's interesting, didn't know D had goto case statements. Btw, what are some projects you've used D for? What are other surprising lesser known features of
by jadbox 6y ago
Ah that's interesting, didn't know D had goto case statements. Btw, what are some projects you've used D for? What are other surprising lesser known features of it to you?
- WalterBright 6y agoThe biggest project is implementing the D compiler itself in 100% D. Don't have much time for other projects. Nested functions are a little gem. I stole the idea from Pascal. I've since discovered that they can nicely clean up spaghetti code that C engenders, without losing efficiency. Nested functions would fit into C seamlessly, I sometimes wonder why the C people don't adopt it. I can only assume they just don't realize how sweet they are, which is understandable because you just have to use them a bit to see it.
- salgernon 6y agoHow do D’s nested procedures differ from the Obj-C block extension? The original pascal based Mac toolbox APIs encouraged nested procedures in modal contexts - but Nested procedures couldn’t escape their outer frame.
- WalterBright 6y agoI have no idea what Obj-C block extensions are. D's nested functions (like Pascal's) have two frame pointers - a dynamic frame pointer (like C has), pointing to the caller's stack frame, and a static frame pointer pointing to the enclosing function's stack frame. This allows the nested function to access the enclosing function's variables. It's a bit tricky to set up, but works a treat.
- jedbrown 6y agoGNU C has had nested functions for quite a long time. I would use them a lot if they were standardized. https://gcc.gnu.org/onlinedocs/gcc/Nested-Functions.html https://gcc.gnu.org/onlinedocs/gcc/Nested-Functions.html
- WalterBright 6y agoD's differs in that: 1. you cannot "goto" out of the nested function 2. you can declare them "static", which means they don't have a static link and cannot access the enclosing function's variables 3. if garbage collection is enabled, you can pass a pointer to the function out of the enclosing function's scope and still safely access its variables 4. they work in `extern (C++)` functions, too
- skocznymroczny 6y agoI don't know if you are aware, but you are replying to the creator of D, so it's unlikely there will be many surprising features for him :)
- WalterBright 6y agoThere could be emergent behavior in the distinct possibility that D becomes self-aware. I've had to reduce D's power at least once to thwart that.
- Gibbon1 6y agoThere was a self aware version of lisp. You could feed it the program specification and it would write a 100% conforming program itself and run it. Unfortunately first time they fed the spec for a real project it outputted the words 'dear god no' and deleted itself. And so here we are.