Confusion/trying to understand CTFE keywords
gdelazzari
giacky98.mail at gmail.com
Sun Jun 3 21:32:06 UTC 2018
Hello everyone, I'm new here on the forum but I've been exploring
D for quite a while. I'm not an expert programmer by any means,
so this one may be a really silly question and, in that case,
please forgive me.
With the premise that I've still not looked a lot into "complex"
compile time "stuff" (whether it's templates, CTFE, compile-time
constants, etc...), so that may be the reason I may be missing
the point... I'm trying to understand why keywords such as
"static" or "enum" are used to denote compile time "things". What
I mean is that those keywords are also used for other purposes,
so I find it a bit confusing. Couldn't a keyword like "ctfe"
(just making it up right now) exist? So that, when seeing
something like
ctfe myNumber = 5;
ctfe if (myNumber + 2 == 7)
{
// ...
}
one could immediately understand that the code is
executed/evaluated at compile time. True, after someone knows
that "static" and "enum" mean (in the above example) that some
compile-time things are happening, it's fine. I just find it a
bit confusing not having a dedicated keyword but re-using
existing ones that also serve other purposes...
Note that this is not an attack to the language or anything (I
actually really love it), I'm just trying to understand the
reasoning behind this choice.
Thank you very much in advance.
More information about the Digitalmars-d-learn
mailing list