Skip to content

3.1 Coding guidelines

AlexanderZender edited this page Oct 19, 2022 · 1 revision

Python

In this project, we follow the PEP 8 -- Style Guide for Python Code Deviations or concretizations from the PEP8 will be listed below

  • Use Tab to intend
  • Variable and function names are writen in the lower_case_with_underscoresstyle, example: user_id or get_dataset()
  • Class names are writen in CapWords style, example: AdapterManager
  • One file per class normally, the file is to be named the same as the class, example AdapterManager class => AdapterManager.py file name
  • private variables use the double _ as prefix, and are access protected by getter setter methods if required outside of the class, example: __training_id
  • Function signature and variables shall declarative datatypes, example __training_id: str
  • Every class and function is to be commented with a docstring. When using """ below a class or method, the autoDocstring plugin will auto-generate the docstring
    • Class use a summary docstring

img_0.png

  • Function docstring, document a summary of the function functionality and what enters (parameter) and exits (return values, exceptions,..) a function

img_1.png

Logging

Every class/function must implement logging of important states within the code. During the class init create a new logger and set the level to the appropriate environment variable. Currently, we support four different logging modules:

  • PERSISTENCE_LOGGING_LEVEL: Sets logging level within the persistence modules
  • SERVER_LOGGING_LEVEL: sets the general server logging level
  • ONTOLOGY_LOGGING_LEVEL: sets the logging level within the Ontology module
  • BLACKBOARD_LOGGING_LEVEL: sets the logging level within all components related to the blackboard

Usage

During the class init get the logger for the specified class (Always use the class name), and set the appropriate level using one of the above variables: image

Within each function add logging commands when they are helpful for debugging or errors/warnings: image

It is important to always first name the function which produced the log and then the logging message!

C#

The C# components of this project follow the C# Coding Conventions A summary will be listed below

  • Classes, Properties and Methods names are written in PascalCase style, example: GetDataset()
  • One file per class normally, the file is to be named the same as the class, example AdapterManager class => AdapterManager.cs file name
  • private variables use the camelCase style and add _ as prefix, example: _training_id
  • Every class and function is to be commented following the commenting convention. Using /// above a class or method will automatically generate the comment block.
    • Class use a summary comment

img_2.png

  • Methods comment documents everything that enters and exits a method

img_3.png