Spacing conventions

Peter Otten __peter__ at web.de
Wed Sep 27 05:37:08 EDT 2017


Bill wrote:

> Ever since I download the MyCharm IDE a few days ago, I've been noticing
> all sort of "spacing  conventions (from PEP) that are suggested.  How do
> folks regard these in general?
> 
> For instance,  the conventions suggest that
> 
> if x>y :
>       pass
> 
> should be written
> if x > y:
>      pass
> 
> Personally, I like seeing a space before the colon (:).   And then in
> 
> my_list = [ i for i in range(0, 10) ]
> it complains about my extra space inside of the brackets.

Of late I've joined the "foolish consistency" camp and made the pep8 tool 
(now called pycodestyle to make it clear it is non-normative) a check-in 
hook. I agree with most of its complaints anyway and find it wasteful to 
fine-tune my code in that regard.

> If you are teaching beginning students, do you expect them to try to
> follow these sorts of conventions?

At least mention the advantages to blend in rather than stand out as far as 
coding style is concerned. The reader can concentrate on functionality and 
is not distracted by the writer's ideosyncratic ideas about formatting.

> Is it perfectly fine to let "taste"
> guide you (I'm just trying to get a feel for the philosophy here)?   I
> also notice "break" and exception handling is used much more in Python
> than in C++, for instance.  I was taught "break" and "continue" led to
> "unstructured code"--but that was a while back.  I can still see their
> use  causing potential trouble in (really-long) real-world code.

What actually causes the trouble is the really-long -- i. e. unstructured -- 
code. "real-world" is but an excuse here ;)




More information about the Python-list mailing list