1. Home
  2. 1. Project best practices
    ❱
    1. 1.1. Structure your code
    2. 1.2. Naming conventions
    3. 1.3. Format the code
    4. 1.4. Logging
    5. 1.5. Documenting the source code
    6. 1.6. Configuration management
    7. 1.7. Dependency management
  3. 2. Language best practices
    ❱
    1. 2.1. Represent optionality
    2. 2.2. Handle nil values
    3. 2.3. Use precise types
    4. 2.4. Work with value ranges
    5. 2.5. Avoid unnecessary type casts
    6. 2.6. Using included record parameters
    7. 2.7. Use expression-bodied functions
    8. 2.8. Use tuples to return multiple values
    9. 2.9. Return errors and use the check
    10. 2.10. Avoid unnecessary usage of panic
    11. 2.11. Use open vs closed records
    12. 2.12. Simplify mapping constructor
    13. 2.13. Avoid unnecessary objects
    14. 2.14. Using constants
    15. 2.15. Handle unions of string constants
    16. 2.16. Handle unions of integer constants
    17. 2.17. Generate string by concatenating values
    18. 2.18. Avoid parentheses in if statement
    19. 2.19. Using match statement
    20. 2.20. Using query expressions for iterations
  4. 3. Common best practices guide
    ❱
    1. 3.1. Use early returns
    2. 3.2. Avoid redundant variables
    3. 3.3. Avoid unnecessary comments
    4. 3.4. Wrap code at 120 characters
    5. 3.5. Use proper commit messages and PR titles
  5. 4. Learning resources
  6. 5. Ballerina FAQ
  7. 6. Ballerina library samples
    ❱
    1. 6.1. Twilio

Ballerina Programming Language Best Practices Guide

Language best practices

List of common Ballerina language best practices to follow.

Optionality and nil values

  • Represent optionality
  • Handle nil values

Values and types

  • Use precise types
  • Work with value ranges
  • Avoid unnecessary type casts

Functions and parameters

  • Using included record parameters
  • Use expression-bodied functions
  • Use tuples to return multiple values

Error handling

  • Return errors and use the check
  • Avoid unnecessary usage of panic

Records

  • Use open vs closed records
  • Simplify mapping constructor

Objects

  • Avoid unnecessary objects

Working with constants and strings

  • Using constants
  • Handle unions of string constants
  • Handle unions of integer constants
  • Generate string by concatenating values

Conditionals

  • Avoid parentheses in if statement
  • Using match statement

Query expressions

  • Using query expressions for iterations