osdir.com


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Python-Dev] Examples for PEP 572


On 04.07.2018 4:26, Tim Peters wrote:
> [INADA Naoki]
> > ...
> > On the other hand, I understand PEP 572 allows clever code
> > simplifies tedious code.? It may increase readability of non-dirty 
> code.
>
> The latter is the entire intent ,of course.? We can't force people to 
> write readable code, but I don't understand the widespread assumption 
> that other programmers are our enemies who have to be preemptively 
> disarmed ;-)
>
> Use code review to enforce readable code.? If you want a coding 
> standard here, use mine:? "if using an assignment expression isn't 
> obviously better (at least a little so), DON'T USE IT".? That's the 
> same standard I use for lots of things (e.g., is such-&-such better as 
> a listcomp or as nested loops?).? It only requires that you have 
> excellent taste in what "better" means ;-)
>
> As I noted in the PEP's Appendix A, I refuse to even write code like
>
> i = j = count = nerrors = 0
> because it squashes conceptually distinct things into a single 
> statement .? I'll always write that as
>
> i = j = 0 count = 0 nerrors = 0
> instead - or even in 4 lines if `i` and `j` aren't conceptually related.
>
> That's how annoyingly pedantic I can be ;-)? ?Yet after staring at 
> lots of code, starting from a neutral position (why have an opinion 
> about anything before examination?), I became a True Believer.
>
> I really don't know what Guido likes best about this, but for me it's 
> the large number of objectively small wins in `if` and `while` 
> contexts.? ?They add up.? That conclusion surprised me.? That there 
> are occasionally bigger wins to be had is pure gravy.
>
> But in no case did I count "allows greater cleverness" as a win.? The 
> Appendix contains a few examples of "bad" uses too, where cleverness 
> in pursuit of brevity harms clarity.? In fact, to this day, I believe 
> those examples derived from abusing assignment expressions in 
> real-life code are more horrifying than any of the examples anyone 
> else _contrived_ to "prove" how bad the feature is.
>
> I apparently have more faith that people will use the feature as 
> intended.? Not all people, just most.? The ones who don't can be 
> beaten into compliance, same as with any other abused feature ;-)
>

It's not about if a syntax can be used right or wrong. It's about how 
easy it is to use it right vs wrong.

A syntax, any syntax, naturally nudges the user to use it in specific 
ways, by making these ways easy to write and read.
One of Python's hightlights is that it strives to make the easiest 
solutions the right ones -- "make right things easy, make wrong things 
hard".

How many of the users are "professional" vs "amateur" programmers is 
irrelevant. (E.g. while newbies are ignorant, pros are instead 
constantly pressed for time.)
Python Zen rather focuses on making it easy to write correct code for 
everyone, beginners and pros alike.

(As St?fane Fermigier righly showed in message from 4 Jul 2018 11:59:47 
+0200, there are always orders of magnitude more "amateurs" than 
"professionals", and even fewer competent ones.)
>
>
> _______________________________________________
> Python-Dev mailing list
> Python-Dev at python.org
> https://mail.python.org/mailman/listinfo/python-dev
> Unsubscribe: https://mail.python.org/mailman/options/python-dev/vano%40mail.mipt.ru

-- 
Regards,
Ivan

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-dev/attachments/20180705/430ab9e0/attachment.html>