Adapter Programming Styles

Adapter is written in Python, and therefore developers of Adapter should adhere to Style Guide for Python Code.

Besides, to improve code quality and readability of the program, developers of Adapter should adhere to the conventions defined in this section as well.

Naming Conventions

  1. Use camel case to name the class, as shown below:

    class AdapterWidget
  2. Use lowercase letters connected with underscores to name the member variables and member functions, as shown below:

    self.pick_count # Note that variables are generally nouns
    def start_viz(self): # Note that the function name is generally a verb + object
        pass
  3. An underscore before the name of a member variable or member function suggests that it is recommended to use these variables and functions only inside the class. However, you can still use the member variables and functions outside the class if necessary, as shown below:

    self._socket = socket() # Indicates that the _socket variable is only used inside the class
    def _init_widget(self): # Indicates that the _init_widget function is only used inside the class
        pass
  4. Use uppercase letters connected with underscores to name constants, as shown below:

    ADAPTER_DIR = "D:/adapter_for_communication"

Comment Conventions

Please only add comments when the logic is complex or the information in the comment is critical.

  • Single line comments

    Use the # to start the comment.

  • Multiline comments

    Use triple quotes (""") to quote the multiline comments. Please note that the """ that ends a multiline comment should be on a line by itself.

  • The introduction of a function, class, or package

    The introduction of a function or class should be put at the end of the function or class, while the introduction of a package should be put in the front, as shown below:

    def viz_is_running(self):
    
        """
        Will be called when find viz is running during starting viz.
        """
    
    class Adapter(QObject):
    
        """
        Base class which encapsulates Viz/Vision/Hub/Robserver interfaces.
        """
    
    """
    Service base classes.
    """
    
    import logging

Log Conventions

Logs can be used for troubleshooting when an error occurs. The log should be output at a proper time, for example, when a key function is called and the reference data is returned.

Adapter supports two methods to output the log:

  • print: This method can only output the log in the console, which is convenient to view the running status of the project in real time. However, the log messages will be lost if an error occurs, and therefore it is not recommended to use this method in actual production.

  • logging: This method is more recommended as it allows setting the display format of the log and saving the log messages in a file (optional).

We Value Your Privacy

We use cookies to provide you with the best possible experience on our website. By continuing to use the site, you acknowledge that you agree to the use of cookies. If you decline, a single cookie will be used to ensure you're not tracked or remembered when you visit this website.