[jokosher-devel] Coding style & class member visibility



Hi all,

Having looked through quite a few of the project files on Cleanup
Sunday, I thought it might be a good time for the project to think about
a coding standard for the files, as I don't believe that there currently
is one.

My personal preferred Python coding style is;
    CamelCase for class names.
    CamelCase for function names.
    Bars between class/function defs.

e.g.

#==============================================================

class MyFunkyClass():
    """ A class that brings back the FUNK!!
    """

    CLASS_CONST = 20.f

    #__________________________________________________________

    def __init__(self):
       pass

    #__________________________________________________________

    def DoSomethingUseful(self):
       pass

    #__________________________________________________________

    def MakeACupOfTea(self, teabag, cup, putMilkInFirst=False):
       pass

#==============================================================

but I'm sure there are other preferences! One such is the Python.org PEP;
http://www.python.org/dev/peps/pep-0008/


Is it worth formally documenting a style?

On a related note, I thought it might be an idea to introduce more data
hiding into the code. By this, I mean the use of single- and
double-underscore name prefixes for private class members/functions. I
believe that the common methodology is to use a single underscore for
the C++ equivalent of protected members, and the double underscore for
the c++ equivalent of private members.

e.g.

class MyFunkyClass():
    def __init__(self):

       # A subclass might want to change the length of trouser we have,
       # as fashions change over time.
       self._trouserLength = 150

       # But no-one (not even sub-classes) should mess with the hair!!
       # The Afro will always represent the true source of The Funk (TM)
       self.__hairstyle = Afro()

Ideas/comments/flames welcome :)

Cheers,

J



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