Code Styles#

This document outlines the code styles and conventions used in the NervAI Engine project. Following these guidelines will help maintain consistency across the codebase and make it easier for developers to read and understand the code.

Python Code Style#

The NervAI Engine project follows the PEP 8 style guide for Python code. This includes the following conventions:

  • Use 4 spaces for indentation.

  • Limit lines to 79 characters.

  • Use snake_case for variable and function names.

  • Use CamelCase for class names.

  • Use UPPER_CASE for constants.

  • Use spaces around operators and after commas.

  • Use docstrings to document functions, classes, and modules.

  • Use type hints for function arguments and return values.

We recommend using the following tools to ensure that your code follows the PEP 8 style guide:

  • isort: A tool that sorts and organizes your import statements according to PEP 8 guidelines.

  • Black: An opinionated code formatter that automatically formats your code to follow the PEP 8 style guide.

  • Flake8: A tool that checks your code for PEP 8 compliance and other code quality issues.

Before submitting a pull request, make sure to run these tools on your code to ensure that it follows the PEP 8 style guide.

# Install isort, Black, and Flake8
pip install isort black flake8

# Run isort to organize import statements
isort .

# Run Black to format your code
black .

# Run Flake8 to check your code for PEP 8 compliance
flake8 .

You should replace the . in the commands above with the path to the directory or file you want to check. You can also configure your code editor to run these tools automatically when you save a file. This will help you catch style violations early and ensure that your code follows the PEP 8 style guide.

JavaScript Code Style#

The NervAI Engine project follows the Airbnb JavaScript Style Guide for JavaScript code. This includes the following conventions:

  • Use 2 spaces for indentation.

  • Limit lines to 100 characters.

  • Use camelCase for variable and function names.

  • Use PascalCase for class names.

  • Use UPPER_CASE for constants.

  • Use single quotes for strings.

  • Use === for equality comparisons.

  • Use /** … */ for multi-line comments.

  • Use // for single-line comments.

We recommend using the following tools to ensure that your JavaScript code follows the Airbnb JavaScript Style Guide:

  • Prettier: An opinionated code formatter that automatically formats your code to follow the Airbnb JavaScript Style Guide.

  • ESLint: A tool that checks your code for JavaScript syntax errors and style issues.