Skip to content
This repository was archived by the owner on May 25, 2022. It is now read-only.

Coding Standards and Requirements

Kyle Martin edited this page Jun 2, 2017 · 16 revisions

Because Cam2 is such a large project with many people working on it we need to ensure that the code we write is understandable to people who may need to use it in the future. If you leave the project will someone else be able to recreate your work? If the answer is no you need to do everything you can to change that. If nobody can understand what you did, your work may be deleted in the future. We have outlined a few coding standards and requirements below to help make your code more readable.

  • There is a template header located in:
    CAM2RetrieveData/Discovery/Template_Script_Header
    Use this header at the top of all scripts you write as it will help give a quick overview of what your script does, how to use it, and how to get in contact with the author if there are any further questions.
  • You will notice the template header file has a line underneath the header that reads:
    if __name__ == "__main__":
    
    This is to remind you to use this whenever possible. This allows you to make your code more reusable by allowing the file to be run as a program rather than just calling the classes and functions separately.
  • Do not hard code file paths as different people may have different file paths. This would prevent someone else from running your code on their own machine.
  • Do not hard code usernames and passwords into your scripts. You don't want someone else using your credentials, and we don't want things such as our database password online. There are two ways you can solve this problem if you are trying to do something that requires a login. Either way make sure you note what you did in the header.
    1. You can prompt the user to enter their credentials in the command line
    2. You can put credentials in a separate file and read that file in your script
  • Separate your code into functions and classes depending on what the code is doing. This makes your code more readable and reusable.
  • Use meaningful variable, function and class names
Clone this wiki locally