Coding Conventions and Standards
General Coding Standards
- Mimic code structure of older versions of ENERGY 2020, where possible.
- Use 2 spaces per indentation level, no tabs. (differs from Julia Style Guide of 4 spaces)
- Use verbose coding in policy files and more condense coding in Engine files.
- Include file name at top of all files; use same import block of code at top of all files.
- Try to adhere to roughly a 72-character line length, not to exceed a 92-character line length limit.
- Use title case (upper camel case) for naming of modules, functions, structs, variables, constants, and set names. Exception for naming subsets of set or specific element of a set, which are lower case
- Add spaces before and after binary operators, such as (=, ==, !=), and avoid padding brackets and other operators with spaces.
- Use custom macros where helpful: subset selections (Select), handling of division by zero (@Finite_math), and applying broadcasting to equations (@.).
- Use Select macro to select subsets, with the exception of the Year set. Use collect to select subset of years.
Other Coding Conventions
Other coding conventions are shown with examples in Common Julia Commands Used in ENERGY 2100, covering the following topics:
- Use of Brackets
- Title Casing Rules
- Interacting with Sets
- Selecting Elements of a Set
- Comparison Operators
- Use of Maps
- For Loops
- Broadcasting
- Conditionals
- Summations
- Handling Undefined Values (NANs)
- Read Disk/Write Disk
- Writing Values to Screen