d-programming-language.org

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Sun Jul 3 14:27:23 PDT 2011


On 7/3/11 4:23 PM, eles wrote:
>> various arguments. Please don't bring this up again. Thank you.
>
> I won't, but this is because I made that decision minutes ago.

Even better.

>>> Well, (almost) enough for now. I also maintain that unsigned types
>>> should throw out-of-range exceptions (in debug mode, so that
> release
>>> will run as fast as it gets) when decremented below zero, unless
>>> specifically marked as *circular* (i.e. intended behavior) or
>>> something like this. This will prevent some bugs. I see those
> quite
>>> often in my student's homeworks.
>> Safe on top of flexible is the best design. If there is anything
>> preventing you from defining a type with the behavior you mention,
> you
>> may want to file a bug.
>
> type information will disappear after compilation. defining a class
> over unsigned int (and overloading operators) on top of that will be
> way too much overhead. in fact, this is what compiler would do for
> the debug type.

D is not Java. You may want to define a struct instead of a class. Save 
for the overflow checks, speed of such a wrapper should stay largely 
unchanged.

> to not break the existing code: define "uncircular" types that will
> throw that exception. this could be implemented as a @keyword, since
> is more like a annotation.

I have an idea - how about the notation Uncircular!uint to designate 
such a type?


Andrei


More information about the Digitalmars-d mailing list