Interesting user mistake
Jonathan M Davis via Digitalmars-d
digitalmars-d at puremagic.com
Fri Sep 4 07:05:06 PDT 2015
On Friday, 4 September 2015 at 13:55:03 UTC, Jonathan M Davis
wrote:
> On Thursday, 3 September 2015 at 16:46:30 UTC, Andrei
> Alexandrescu 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 +=.
[snip]
Actually, I may have misunderstood the suggestion. I do _not_
think that we should require that someone who writes code like
a=+b;
should be forced to put whitespace in their code, as ugly as it
arguably is that they don't (which is what I thought was being
suggested). However, if they've written their code like
a =+ b;
then it would make sense to warn about it, since the odds of that
being legitimate are nearly zero, and the same goes for any other
unary operator. Someone might be weird and choose to put
whitespace before the unary operator, but I don't think that
that's very common, and if someone is doing that, they're not
likely to then _not_ put a space before the unary operator. So, I
don't think that we'd really be cramping anyone's style (be it
ugly or otherwise) if we warned about =+ when there's whitespace
on both sides of =+ but not between them.
Now, I tend to think that anything should either be an error or
not and that everything else should be left to a linter, since
it's subjective, so I'm still not a big fan about having
something like this be a warning, but I very much doubt that
it'll really cause any problems if it is, since I have a hard
time believing that anyone is even going to _want_ to write
a =+ b;
- Jonathan M Davis
More information about the Digitalmars-d
mailing list