[Tutor] Quick Pythonic Style Tips
alan.gauld at yahoo.co.uk
Sat Jul 22 09:46:26 EDT 2017
On 22/07/17 12:20, Abdur-Rahmaan Janhangeer wrote:
> As a user switching between some languages, it took sometimes before i
> discovered that there was a styling guide in python
There are style idioms in most languages although not always
written down as clearly as in PEP8. That having been said
they should be viewed as guides not rules. In addition there
are often local style guides that must be followed in
a particular company.
> i'd like to know if there was a specific C++ or java> style of doing things which should be avoided ?
Mostly it's not layout style things that should be avoided
but actual programming styles - such as using Java style
getXXX/setXXX type methods for attribute access. Or getting
overly hung-up on trying to make data "private".
Some people get excited about naming (xxx_yyy v xxxYyy v XxxYyy)
but in practice these things make very little difference in
comprehensibility of code, which is the most important
consideration. Much more important is clarity of intent
in naming (such as the plurals-for-collections rule you
mentioned, or not using types as names - eg. anInt - unless
it truly is a completely generic place-holder).
The exception to all of this is code submitted to the
standard library. It really should have PEP8 applied
fairly rigorously both for the sake of consistency and
because the library is often cited as a style template.
Author of the Learn to Program web site
Follow my photo-blog on Flickr at:
More information about the Tutor