This is the multi-page printable view of this section. Click here to print.

Return to the regular view of this page.

Engineering

All our documentation around engineering processes.

    Coding styles

    At Balean we strive for readable and maintainable code. This requires all developers to adhere to a certain standard. This guideline will give details on that coding standard.

    Source code style

    When writing new source code at Balean, all code must be indented with 2 spaces. Lines should always end with the lf character to ensure the build runs successfully in linux-based containers. Windows developers should ensure that source code is pushed with the lf line-ending. The default character set is utf-8. Please ensure, before pushing, that your source file uses this character set.

    In oder to automatically apply this standard to your source code, a file called .editorconfig should be added to all repositories to ensure correct styleguides. See Editor config below for more information.

    Cross-platform compatibility

    It is up to the developer to develop on the system of their choice, whether it’s Windows, Mac or Linux. Deployment targets, build images and scripts tend to run on Linux systems though. It is therefore important that the code-bases are all compatible with Linux but should be usable on other platforms as well.

    There are certain scripts and config files that are specifically sensitive to the correct encoding and line-ending. Within Balean, the following settings are being used:

    • Text file encoding: UTF-8
    • Line ending: lf (equivalent to \\n)

    Git settings

    Git is the main source of truth and should contain the correct encoding and line-ending, regardless of what individual contributors may want to use. In order to ensure that files are in the right configuration, repositories should have a .gitattributes file that configures the expected line-ending. See also the git-attributes docs

    To configure your local system to normalize files to the proper line-ending, the core.autocrlf setting must be set: git config --global core.autocrlf true This does not force normalization of text files, but does ensure that text files that you introduce to the repository have their line endings normalized to LF when they are added, and that files that are already normalized in the repository stay normalized. See git docs

    By default, git supports files in UTF-8 encoding. Other encodings are handled as binary files.

    Example .gitattributes file

    # Automatically normalize all text files to lf
    * text=auto eol=lf
    
    # Exceptions and specific configurations
    *.bat text eol=crlf
    *.sh text eol=lf
    

    VS Code settings

    Use the following settings in VS Code for compatibility with Balean’s settings:

    "files.encoding": "utf8"
    "files.eol": "\n"
    

    IDE Config

    Editor config

    Adding a file called .editorconfig to your repository will help set the correct coding standard. The editorconfig file is based on an open standard maintained by editorconfig.org.

    An example .editorconfig is given below. When adding this file to the root of your repository will automatically apply the Balean standard to your repository.

    # editorconfig.org
    
    root = true
    
    [*]
    indent_style = space
    indent_size = 2
    end_of_line = lf
    charset = utf-8
    trim_trailing_whitespace = true
    insert_final_newline = true