September 03, 2015 Interesting user mistake | ||||
---|---|---|---|---|
| ||||
http://stackoverflow.com/questions/32369114/leap-years-not-working-in-date-and-time-program-in-dlang The gist of it is the user wrote =+ instead of +=. I wonder if we should disallow during tokenization the sequence "=", "+", whitespace. Surely it's not a formatting anyone would aim for, but instead a misspelling of +=. Andrei |
September 03, 2015 Re: Interesting user mistake | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrei Alexandrescu | On Thursday, 3 September 2015 at 16:46:30 UTC, Andrei Alexandrescu wrote: > The gist of it is the user wrote =+ instead of +=. I wonder if we should disallow during tokenization the sequence "=", "+", whitespace. Surely it's not a formatting anyone would aim for, but instead a misspelling of +=. Seems reasonable. I tried to search for that pattern (<https://searchcode.com/?q=%3D%2B>) and it says 9 results for D, but clicking the D filter doesn't seem to do anything, so I'm not sure what the actual cases are. |
September 03, 2015 Re: Interesting user mistake | ||||
---|---|---|---|---|
| ||||
Posted in reply to Luís Marques | On Thursday, 3 September 2015 at 17:03:26 UTC, Luís Marques wrote: > I tried to search for that pattern (<https://searchcode.com/?q=%3D%2B>) and it says 9 results for D, but clicking the D filter doesn't seem to do anything, so I'm not sure what the actual cases are. Ah, there was a button way on the top to apply the filter. (<https://searchcode.com/?q=%3D%2B&loc=0&loc2=10000&lan=45>). All results are irrelevant, so I guess it's unlikely to break anything. |
September 03, 2015 Re: Interesting user mistake | ||||
---|---|---|---|---|
| ||||
Posted in reply to Luís Marques | On Thursday, 3 September 2015 at 17:06:15 UTC, Luís Marques wrote: > Ah, there was a button way on the top to apply the filter. (<https://searchcode.com/?q=%3D%2B&loc=0&loc2=10000&lan=45>). All results are irrelevant, so I guess it's unlikely to break anything. Urg, too trigger happy today. Bug?: https://searchcode.com/codesearch/view/15360834/ for (int i = 0; i < m_mainWindows.length; ++i) { tabCount =+ m_mainWindows[i].tabWidget().count(); } |
September 03, 2015 Re: Interesting user mistake | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrei Alexandrescu | On Thu, Sep 03, 2015 at 12:46:29PM -0400, Andrei Alexandrescu via Digitalmars-d wrote: > http://stackoverflow.com/questions/32369114/leap-years-not-working-in-date-and-time-program-in-dlang > > The gist of it is the user wrote =+ instead of +=. I wonder if we should disallow during tokenization the sequence "=", "+", whitespace. Surely it's not a formatting anyone would aim for, but instead a misspelling of +=. [...] Is there a way for the lexer to check for the specific character sequence '=', '+', whitespace and not others (e.g. '=', whitespace, '+')? IOW, "a =+ b" will be prohibited, but "a = + b" will be allowed. If so, I agree with this. On that note, though, the unary + operator is totally useless in D... maybe we should get rid of that instead? (Then "=+" will automatically be an error.) T -- If it's green, it's biology, If it stinks, it's chemistry, If it has numbers it's math, If it doesn't work, it's technology. |
September 03, 2015 Re: Interesting user mistake | ||||
---|---|---|---|---|
| ||||
Posted in reply to H. S. Teoh | On Thursday, 3 September 2015 at 17:12:31 UTC, H. S. Teoh wrote:
> Is there a way for the lexer to check for the specific character sequence '=', '+', whitespace and not others (e.g. '=', whitespace, '+')? IOW, "a =+ b" will be prohibited, but "a = + b" will be allowed. If so, I agree with this.
>
> On that note, though, the unary + operator is totally useless in D... maybe we should get rid of that instead? (Then "=+" will automatically be an error.)
What about the generalization? E.g., '=', '-', whitespace?
|
September 03, 2015 Re: Interesting user mistake | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrei Alexandrescu | On Thursday, 3 September 2015 at 16:46:30 UTC, Andrei Alexandrescu wrote:
> we should disallow during tokenization the sequence "=", "+", whitespace. Surely it's not a formatting anyone would aim for, but instead a misspelling of +=.
>
>
> Andrei
Wasn't the original design for these operators in whichever language started them actually the swapped form? In any case, I'd personally choose to warn against any operator sequence without separating whitespaces if the sequence isn't in fact one operator (like "=!" (non-warn: "= !") vs "!=", and "=&", and a lot others, given operator overloading).
Looking again, it's mostly the fault of OpAssign operators, isn't it?
|
September 03, 2015 Re: Interesting user mistake | ||||
---|---|---|---|---|
| ||||
Posted in reply to H. S. Teoh | On 9/3/15 1:08 PM, H. S. Teoh via Digitalmars-d wrote:
> On Thu, Sep 03, 2015 at 12:46:29PM -0400, Andrei Alexandrescu via Digitalmars-d wrote:
>> http://stackoverflow.com/questions/32369114/leap-years-not-working-in-date-and-time-program-in-dlang
>>
>> The gist of it is the user wrote =+ instead of +=. I wonder if we
>> should disallow during tokenization the sequence "=", "+", whitespace.
>> Surely it's not a formatting anyone would aim for, but instead a
>> misspelling of +=.
> [...]
>
> Is there a way for the lexer to check for the specific character
> sequence '=', '+', whitespace and not others (e.g. '=', whitespace,
> '+')? IOW, "a =+ b" will be prohibited, but "a = + b" will be allowed.
> If so, I agree with this.
>
> On that note, though, the unary + operator is totally useless in D...
> maybe we should get rid of that instead? (Then "=+" will automatically
> be an error.)
>
>
> T
What about all other operations that may be typos from op= where op is also a unary operator? e.g. =-
FWIW, I think this is a good idea, even if it's just for =+.
-Steve
|
September 03, 2015 Re: Interesting user mistake | ||||
---|---|---|---|---|
| ||||
Posted in reply to H. S. Teoh | On Thursday, 3 September 2015 at 17:12:31 UTC, H. S. Teoh wrote:
> Is there a way for the lexer to check for the specific character sequence '=', '+', whitespace and not others (e.g. '=', whitespace, '+')? IOW, "a =+ b" will be prohibited, but "a = + b" will be allowed. If so, I agree with this.
>
> On that note, though, the unary + operator is totally useless in D... maybe we should get rid of that instead? (Then "=+" will automatically be an error.)
>
>
> T
Worse than useless; it doesn't even behave as you would expect.
import std.stdio;
void main()
{
auto a = -1;
writeln(+a); //Prints -1
writeln(-a); //Prints 1
}
At least unary - does something.
|
September 03, 2015 Re: Interesting user mistake | ||||
---|---|---|---|---|
| ||||
Posted in reply to Meta | On Thursday, 3 September 2015 at 18:31:59 UTC, Meta wrote:
>> On that note, though, the unary + operator is totally useless in D... maybe we should get rid of that instead? (Then "=+" will automatically be an error.)
>>
>>
>> T
>
> Worse than useless; it doesn't even behave as you would expect.
>
> import std.stdio;
>
> void main()
> {
> auto a = -1;
> writeln(+a); //Prints -1
> writeln(-a); //Prints 1
> }
>
> At least unary - does something.
I like to use the unary plus *in some cases* of tabular data, to reinforce the signess. Something like this:
auto foo = [
+1234,
-5678,
-4242,
+9999
];
|
Copyright © 1999-2021 by the D Language Foundation