Is D suitable for my latest project?
Atila Neves via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Wed Sep 9 02:14:28 PDT 2015
On Sunday, 6 September 2015 at 14:36:53 UTC, chris stevens wrote:
> Hi All,
>
> I am considering using D for my latest project and there are a
> few features I would like and am not entirely sure at this
> point whether D has them. They are:
>
> - dynamic creation of classes/structs at runtime (think I can
> emulate this with variants/dynamic)
At runtime, no. However... if it doesn't actually need to be
runtime and is in the code itself you can have code be generated
at compile time.
> - dynamic compilation of code files at runtime
Only by running a compiler. But as above, if it doesn't strictly
have to be at runtime and everything is specified in the source
files, you can compute strings at compile-time and mix them in to
generate code.
> - some basic code creation tools
mixin, template mixin, CTFE.
> Are the above possible?
It really depends on what you want to do. A lot of the dynamic
code generation that goes on is done at runtime because that's
what other languages support. In my experience a lot of those
use-cases can be done at compile-time in D. A famous example is
compile-time regular expressions. Unless you're writing a tool
similar to grep, all regexes in your program are known at
compile-time. They don't _need_ to be parsed/interpreted/compiled
at run-time, that's just what every other language that isn't D
does.
So, if your use-case depends on information from the file-system,
user interaction, networking, etc. then your only choice is to
generate text files with D code and compile it. If, on the other
hand, it's all defined by the code you write, then D has
excellent compile-time code generation tools at your disposal.
Atila
More information about the Digitalmars-d-learn
mailing list