ranges of characters and the overabundance of traits that go with them

Jonathan M Davis via Digitalmars-d digitalmars-d at puremagic.com
Thu Mar 16 15:42:21 PDT 2017


On Thursday, March 16, 2017 21:50:18 Sebastiaan Koppe via Digitalmars-d 
wrote:
> On Thursday, 16 March 2017 at 17:12:05 UTC, Jonathan M Davis
>
> wrote:
> > Unfortunately, the nature of traits is such that altering them
> > in a fashion that includes a deprecation cycle really doesn't
> > work. You can deprecate the whole trait, but you really can't
> > change its behavior without risking code breakage.
>
> While not a nice solution, a pragma(msg,"deprecated") inside a
> static if would do the trick. You could also argue for a
> static-deprecated language feature.

The problem is that that then catches when an enum is passed to
isSomeString, not when the template constraint or static if that
isSomeString is being used in should have checked for enums and didn't. And
checking isSomeString with an enum is perfectly valid. It's just that we'd
like it to be false, whereas right now it's true. Code could quite
legitimately be doing something like

auto foo(T)(T str)
    if(isSomeString!T)
{
    static if(is(T == enum))
        return foo!(StringTypeOf!T)(str);
    else
    {
        ...
    }
}

> Maybe a little bit off-topic, but would it be possible to scrape
> github and use dcd or dscanner to count the usages of enums and
> isSomeString? Just to measure how big the playing field is.
> Sometimes a little measuring brings up surprising insights and
> turns choices into no-brainers.

That could give us some insights into what some of the code out there is
doing - certainly it's probably our best resource for examining D code in
the wild - but it also is only going to be a portion of the D code out there
- possibly even a small portion. And it's generally going to miss corporate
users, who are arguably the most important, since messing them up could cost
them money rather than simply annoying them. So, if someone did that, it
could certainly be informative, but it wouldn't be conclusive. If anything,
it would help us see some of what people are definitely doing, but it
wouldn't let us see for sure what they aren't doing or necessarily how
common any particular practice is in the D community as a whole.

As for how hard it is to actually do it, I don't know, because I don't know
how advanced dcd or dscanner are, but if I had to guess, I'd say that
checking much more than how much isSomeString gets used wouldn't be
possible. Checking for when it is or isn't used in conjuction with a check
for enums could get pretty complicated when you take into account that one
part of the check could be in a template constraint while the other is in a
static if, or how something like isInputRange won't pass for enums, but it
doesn't explicitly check for enums - they just don't semantically work with
the code that isInputRange requires to compile. So, probably, all we could
do is figure out how often isSomeString is used in the D code that's
publicly up on places like github or bitbucket and not much about how it's
used. I don't know for sure though.

- Jonathan M Davis



More information about the Digitalmars-d mailing list