Thread overview | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
February 14, 2010 disabling unary "-" for unsigned types | ||||
---|---|---|---|---|
| ||||
ulong x0; static assert(!__traits(compiles, -x0)); uint x1; static assert(!__traits(compiles, -x1)); ushort x2; static assert(!__traits(compiles, -x2)); ubyte x3; static assert(!__traits(compiles, -x3)); Sounds good? Andrei |
February 14, 2010 Re: disabling unary "-" for unsigned types | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrei Alexandrescu | Andrei Alexandrescu wrote:
> ulong x0;
> static assert(!__traits(compiles, -x0));
> uint x1;
> static assert(!__traits(compiles, -x1));
> ushort x2;
> static assert(!__traits(compiles, -x2));
> ubyte x3;
> static assert(!__traits(compiles, -x3));
>
> Sounds good?
>
> Andrei
Sounds excellent. Who would have thought of that?
Cheers
Justin Johansson
|
February 14, 2010 Re: disabling unary "-" for unsigned types | ||||
---|---|---|---|---|
| ||||
Posted in reply to Justin Johansson | Justin Johansson wrote:
> Andrei Alexandrescu wrote:
>> ulong x0;
>> static assert(!__traits(compiles, -x0));
>> uint x1;
>> static assert(!__traits(compiles, -x1));
>> ushort x2;
>> static assert(!__traits(compiles, -x2));
>> ubyte x3;
>> static assert(!__traits(compiles, -x3));
>>
>> Sounds good?
>>
>> Andrei
>
> Sounds excellent. Who would have thought of that?
>
> Cheers
> Justin Johansson
>
Actually Walter just talked me into forgetting about it. -x is conceptually rewritten into ~x + 1 for all types and typed accordingly. I'm dropping this in order to keep focused on more important changes.
Andrei
|
February 14, 2010 Re: disabling unary "-" for unsigned types | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrei Alexandrescu | == Quote from Andrei Alexandrescu (SeeWebsiteForEmail@erdani.org)'s article > ulong x0; > static assert(!__traits(compiles, -x0)); > uint x1; > static assert(!__traits(compiles, -x1)); > ushort x2; > static assert(!__traits(compiles, -x2)); > ubyte x3; > static assert(!__traits(compiles, -x3)); > Sounds good? > Andrei The more you bring up features to give the axe to, the more I find it funny that, not being a very good language lawyer, I wasn't aware that half of these features existed in the first place. This is one of them. Yes, definitely get rid of it. It makes absolutely no sense. If you want to treat your number like a signed int, then it should require an explicit cast. |
February 14, 2010 Re: disabling unary "-" for unsigned types | ||||
---|---|---|---|---|
| ||||
Posted in reply to dsimcha | dsimcha wrote:
> The more you bring up features to give the axe to, the more I find it funny that,
> not being a very good language lawyer, I wasn't aware that half of these features
> existed in the first place.
D is a very ambitious language, and we are definitely shooting for the stars with it. That means that there are many features that missed or otherwise failed to find a target. So we're doing a little pruning for D2, and a big part of posting these possible prunes here is to make sure we aren't missing an important use case for them.
One problem C/C++ has is there are several failed features in them that the C/C++ community has repeatedly tried to excise, but they just won't die. Trigraphs are an example.
|
February 14, 2010 Re: disabling unary "-" for unsigned types | ||||
---|---|---|---|---|
| ||||
Posted in reply to Walter Bright | Walter Bright wrote:
> dsimcha wrote:
>> The more you bring up features to give the axe to, the more I find it funny that,
>> not being a very good language lawyer, I wasn't aware that half of these features
>> existed in the first place.
>
> D is a very ambitious language, and we are definitely shooting for the stars with it. That means that there are many features that missed or otherwise failed to find a target. So we're doing a little pruning for D2, and a big part of posting these possible prunes here is to make sure we aren't missing an important use case for them.
>
> One problem C/C++ has is there are several failed features in them that the C/C++ community has repeatedly tried to excise, but they just won't die. Trigraphs are an example.
And custom operator new is another :o).
Andrei
|
February 14, 2010 Re: disabling unary "-" for unsigned types | ||||
---|---|---|---|---|
| ||||
Posted in reply to dsimcha | dsimcha wrote:
> == Quote from Andrei Alexandrescu (SeeWebsiteForEmail@erdani.org)'s article
>> ulong x0;
>> static assert(!__traits(compiles, -x0));
>> uint x1;
>> static assert(!__traits(compiles, -x1));
>> ushort x2;
>> static assert(!__traits(compiles, -x2));
>> ubyte x3;
>> static assert(!__traits(compiles, -x3));
>> Sounds good?
>> Andrei
>
> The more you bring up features to give the axe to, the more I find it funny that,
> not being a very good language lawyer, I wasn't aware that half of these features
> existed in the first place. This is one of them. Yes, definitely get rid of it.
> It makes absolutely no sense. If you want to treat your number like a signed
> int, then it should require an explicit cast.
I said the same. Walter's counter-argument is that 2's complement arithmetic is an inescapable reality that all coders must be aware of in D and its kin. Negation is really taking the two's complement of the thing. The fact that the type was unsigned is not of much import.
Andrei
|
February 14, 2010 Re: disabling unary "-" for unsigned types | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrei Alexandrescu | == Quote from Andrei Alexandrescu (SeeWebsiteForEmail@erdani.org)'s article > Walter's counter-argument is that 2's complement > arithmetic is an inescapable reality that all coders must be aware of in > D and its kin. Negation is really taking the two's complement of the > thing. The fact that the type was unsigned is not of much import. > Andrei Ok, but you could still do it just by using an explicit cast. When you're thinking of how things are represented at the bit level, this is basically type punning. It should be allowed in a systems language, but it should require an explicit cast. Using unary - to get the two's complement of a number is a way of getting around they type system and is probably a bug more often than an intentional idiom. |
February 14, 2010 Re: disabling unary "-" for unsigned types | ||||
---|---|---|---|---|
| ||||
Posted in reply to Walter Bright | Walter Bright:
> D is a very ambitious language, and we are definitely shooting for the stars with it. That means that there are many features that missed or otherwise failed to find a target. So we're doing a little pruning for D2, and a big part of posting these possible prunes here is to make sure we aren't missing an important use case for them.
D2 is a mix of some different kind of features:
- C features. Some of them are not perfect, but we know their ups and downs, their risks and their qualities.
- Some features are patches/fixes over C features that are known to be dangerous, not handy, bug prone, etc. Walter has enough experience with C that they are probably all good things.
- Some new features that come from years of D1 development/usage or from other languages. They are not perfect (for example you can by mistake put the underscore in a wrong place in a number literal, and this can produce a deceiving number. Ideally in base 10 underscores can be syntactically allowed only every 3 digits and in base 2 or 6 every 4,8,16,32,16 digits only), but they are generally known enough to be safe enough bets.
- And finally in D2 there are several new features that are sometimes only half-implemented, and generally no one has tried them in long programs, they seem to come from just the mind of few (intelligent) people, they don't seem battle-tested at all. Such new features are a dangerous bet, they can hide many traps and problems. Finalizing the D2 language before people have actually tried to use such features in some larger programs looks dangerous. Recently I have understood that this is why Simon Peyton-Jones said "Avoid success at all costs" regarding Haskell, that he has slowly developed for about 15 years: to give the language the time to be tuned, to remove warts, to improve it before people start to use it for rear and it needs to be frozen (today we are probably in a phase when Haskell has to be frozen, because there is enough software written in it that you can't lightly break backward compatibility).
So I am a little worried for some of the last features introduced in D2. I don't know if D3 can solve this problem (maybe not).
Bye,
bearophile
|
February 14, 2010 Re: disabling unary "-" for unsigned types | ||||
---|---|---|---|---|
| ||||
Posted in reply to bearophile | > Ideally in base 10 underscores can be syntactically allowed only every 3 digits and in base 2 or 6 every 4,8,16,32,16 digits only),
Sorry, I meant:
Ideally in base 10 underscores can be syntactically allowed only every 3 digits (starting from the less significant) and in base 2,8 or 16 every 4,8,16,32,64, etc, digits only),
Bye,
bearophile
|
Copyright © 1999-2021 by the D Language Foundation