Skip to content
Erin Hales edited this page Apr 19, 2021 · 6 revisions

Optics-monorepo Style Guide

Solidity

Layout

Whenever possible, try to keep Contracts, Libraries and Interfaces in their owns files. Additionally, they should go in their respective folders (contracts, interfaces and libs).

Order within Contract, Library or Interface

  1. type declarations
  2. state variables
  3. events
  4. functions

Function Order

Ordering helps readers identify which functions they can call and to find the constructor and fallback definitions easier.

Functions should be grouped according to their visibility and ordered:

  1. constructor
  2. initialize()
  3. modifiers
  4. external
  5. public
  6. internal
  7. private

Within a grouping, place the view and pure functions last.

Variable/Function naming

camelCase

  • events (and event params)
  • all state variables
  • public and external functions
  • internal functions in libraries

_underscoreCamelCase

  • function parameters
  • local variable names
  • internal and private functions in contracts

Note: Avoid naming variables with trailing underscore _var_.

Imports

Group by internal exports first, then external imports.