is(x = module) vs. __traits(isModule, x)
H. S. Teoh
hsteoh at quickfur.ath.cx
Wed Oct 7 19:44:59 UTC 2020
On Wed, Oct 07, 2020 at 07:15:30PM +0000, Paul Backus via Digitalmars-d wrote:
> On Wednesday, 7 October 2020 at 19:07:34 UTC, H. S. Teoh wrote:
> > I'm on the fence about this one. Having to type
> > __traits(isModule,xxx) is painful. Is it really necessary to make
> > it so hard just to check whether a symbol is a module?? It's not as
> > if it's something we want to discourage. Typing is(xxx == module)
> > is much easier, and more pleasant on the eyes.
>
> IMO this is one of those situations where your pain is trying to tell
> you something. If using __traits syntax is so painful that we're
> willing to add hacky special cases to other language features in order
> to avoid it, maybe the message we should take from that is "we need to
> improve __traits syntax."
[...]
Actually, I think that *was* the original intent of the __traits syntax.
It was meant to be a quick-n-dirty way of exposing various compiler
internal structures to Phobos so that it can implement various
meta-programming primitives. It was intentionally ugly in order to
discourage users from using it directly, and to prefer the nicer
packaging in Phobos instead.
However, the way things turned out, it appears that __traits has become
sorta a de facto standard for metaprogramming primitives, and Phobos has
kinda fallen behind on the job. So perhaps it's time to rethink this
decision?
T
--
Be in denial for long enough, and one day you'll deny yourself of things you wish you hadn't.
More information about the Digitalmars-d
mailing list