is(x = module) vs. __traits(isModule, x)

H. S. Teoh hsteoh at quickfur.ath.cx
Wed Oct 7 19:07:34 UTC 2020


On Wed, Oct 07, 2020 at 02:46:07PM -0400, Steven Schveighoffer via Digitalmars-d wrote:
[...]
> We currently have 2 ways to check if a symbol is a module:
> 
> import std.stdio;
> 
> pragma(msg, is(std.stdio == module)); // true
> pragma(msg, __traits(isModule, std.stdio)); // true
[...]
> I really think we should remove one of these, I would recommend
> removing the `is` form, since it's the only exception to the rule that
> the parameter must be a type.

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.

OTOH you have a very good point about is(...) being intended to work
only for types.

So I dunno.


> BTW, same with packages:
> 
> is(std == package) == __traits(isPackage, std);
[...]

Ditto.


T

-- 
Knowledge is that area of ignorance that we arrange and classify. -- Ambrose Bierce


More information about the Digitalmars-d mailing list