Is D really that bad?
Ali Çehreli
acehreli at yahoo.com
Sun Oct 30 02:10:44 UTC 2022
On 10/28/22 10:17, Ali wrote:
> I think many languages, provide the benefits of metaprogramming, without
> necessarily calling it metaprogramming
The way I understand it, metaprogramming in languages like D are decided
at compile time. That's why C++ has been shown to be faster than C.
Bjarne Stroustrup has an example here:
https://www.stroustrup.com/new_learning.pdf
In short, sort() in C++ is faster than C because there is no dispatching
through a function pointer at runtime. In languages like D, the deal is
sealed at compile time.
D allows optimizations with compile-time introspection as well.
> for example:
> 1. Tcl everything is a string, and you have the eval function
Which means, everything is parsed at run time, right? Perhaps they use
JIT to amortize some compilation away.
> 2. Any dynamic language, that have an eval function, and where you can
> add a config file in code to your programs
Same as Tcl: Must be slow.
> 3. lisp, every this is a list, and you can easily pass a function as a
> parameter
At least the passed function needs to be called. There is a function
call dispatch there.
> 4. any language that have functions as first class objects and allow you
> to pass functions as parameters
Same: Function pointer dispatch.
> 5. any object oriented language, and it all really depend on how good
> your object model is
Same. Or worse: Even objects need vtbl dispatch there. In contrast, D's
range algorithms nail the implementation down to exact types that you
have. No dynamic dispatching of any kind.
There is on contest really...
> 6. languages with metaobject
I don't know that but perhaps they are better is some sense. (?)
> So can you give examples, of how D does those things better, or does
> things that others cant, code examples
I don't need to give any example at this point. Maybe you have further
questions?
Ali
More information about the Digitalmars-d
mailing list