Skip to content

coding conventions

Lorenzo Busoni edited this page Sep 16, 2018 · 1 revision

Based on the ​style guide for the Python standard library. The file chaos_device.py demonstrates the plico code conventions:

"""A Device for controlling chaos

It is important to prevent chaos.  Therefore,  Argos has code conventions.
"""

import os
import sys

class ChaosDevice:
    """Device for controlling chaos.

    This class abstracts from the property tree of the chaos basda device.
    """

    def __init__(self, path):
	self._path= path

    def goToTheMatrix(self):
	if self._path.startswith("a"):
            os.chdir("b")
	elif "foo" == self._path:
	    os.chdir(sys.path[1])
	else:
	    os.remove(self._path)

        for i in xrange(0, 3):
	    self._say(i)
	
	j= 5
	k= 3
	l= []
	while k < 9:
	    l.append(j + k)
	    k= k + 1
	
    def _say(self, x):
        """A private method.

	A leading underscore denotes private methods.
	"""
	print(x)

Encoding of Acronyms

The goal of encoding of acronyms is readability:

class AoSquirrel(object):


    def __init__(self):
        self._httpProxy= None
        self._lgswCtrlClient= None


    def setHttpProxy(self, httpProxy):
        pass


    def setLgswControllerClient(self, lgswCtrlClient):
        pass


    def aoReconstructor(self):
        return None


    def setAoReconstructor(self, aoReconstructor):
        pass


    def setAArbConfiguration(self, config):
        pass


    def setTipTiltDevice(self, device):
        pass

Rules

  • Line indentation is 4 spaces.
  • Tabs are forbidden!
  • Maximum line length is 79 characters.
  • Comments should be complete sentences.
  • Python coders from non-English speaking countries: please write your comments in English, unless you are 120% sure that the code will never be read by people who don't speak your language.
  • Modules should have short, all-lowercase names. Underscores can be used in the module name if it improves readability.
  • Class names use the CapWords (medial capitals) convention.

Eclipse Support

The Python plugin PyDev? for Eclipse has a tool for checking source code on conformity with PEP8 standard. Argos can reuse most of the functionality of this tool except that:

Restriction of only one blank line between class methods (E303) Implicit indication of source and destination during assignment operation (E225) Thus, the following argument for pep8.py has to be added:

--ignore=E225,E303,E251,E402

Credits

Everything I know about coding comes from the SW guys of ARGOS @ MPIA. The one above is their list of recommendations

Clone this wiki locally