Bitten by my C/Java experience

Steven D'Aprano steve+comp.lang.python at pearwood.info
Wed May 6 12:03:02 EDT 2015


On Wed, 6 May 2015 10:40 pm, BartC wrote:

> But I had in mind not implementing ++ and --, but detecting them and
> issuing a warning, 

That's a job for a linter, not the compiler. The compiler should be as
flexible as possible in what it accepts:


a   ,    b=12+3     *          4,"hello"          .      upper   ()


is perfectly legal code. The compiler shouldn't force you to write good
looking code, apart from what is prohibited altogether.

Both + and - are unary prefix operators, so you can apply + and - to any
expression -- even an expression that already has a unary prefix operator:

py> -     --- +++ + - - + -- +++ --- 999
-999


Is that ugly, horrible code that nobody in their right mind would use in
production? Absolutely. But the compiler can and should accept it, and
linters (or human reviewers) should warn about it.



-- 
Steven




More information about the Python-list mailing list