Interesting user mistake

Marco Leise via Digitalmars-d digitalmars-d at puremagic.com
Sun Sep 13 11:42:25 PDT 2015


Am Fri, 04 Sep 2015 13:38:26 +0000
schrieb "Jonathan M Davis" <jmdavisProg at gmx.com>:

> I didn't realize that a unary + operator existed. I would have 
> assumed that +a as an expression would be illegal. It doesn't 
> even mean anything.
> 
> - Jonathan M Davis

Often (mostly with linear algebra) you have e.g. a sum of 4
products that differ only in some index and the sign. I use to
put superfluous + signs there and put each product on a
separate line just to make the similarities stick out more.

Sure they do nothing, but I'd miss them when there is ++/--/-
as prefix operators but no +.

About the proposal I'm undecided. Rare mistake, stuffing more
fuzzy logic into the compiler front-end where I don't know
how maintainable this is on the long run and how much in fact
they start to annoy as they target mistakes that newcomers
make, but may actually be legit. For example assuming you
learned the operator precedence rules, warnings about adding
parenthesis where the code was already correct can be annoying.
"=+ " goes in the same direction.
We could end up with DMD and SDC implementing a different set
of somewhat fuzzy, well meant restrictions on what is correct
code, that most of the time avoid errors and sometimes annoy.
A compiler front-end is complex and such language patches may
actually make the code less readable by adding snippets of
code all over the front-end code bases.
I like the "did you mean ..." messages though as the last step
of symbol resolution. They happen when the code already
doesn't compile and as such don't alter what is valid code and
they have good visibility.

So my opinion is to collect such snippets in a proper linter
like https://github.com/Hackerpilot/Dscanner instead of
burdening the front-end with them and creating a de-facto
new DMD specific spec different from other emerging D
implementations.

-- 
Marco



More information about the Digitalmars-d mailing list