Skip to main content

Coding Style

Indentation

Coco uses Python-style indentation to define code hierarchy. A colon (:) at the end of a line indicates that an indented block follows.

// Standard Block (Recommended: 4 spaces)
if x > 5:
throw "Too much"
else:
emit "Phew"

// One-Liner (Allowed for single statements)
if x > 5: throw "Too much"
else: emit "Phew"
Key Rules
  • Consistency — All lines in a block must use the exact same number of spaces
  • Tabs vs Spaces — A TAB counts as 1 space. Use spaces only and never mix tabs and spaces

Multiple Lines

Long statements can span multiple lines for better readability:

function NameSupply(
n String,
s U256,
) -> (name String,
supply U256):
return(name: n,
supply: s)

Lines may continue wherever a space could be written. Strings can span multiple lines, but indentation is included in the string:

s = "My spl
it string" // Result: "My split string"

s = "My spl
it string" // Result: "My spl it string"

Comments

Coco supports line comments with //. Multi-line comments require // on each line:

// Multi-line comments need
// a // sign in front of
// each line
x = 5 // inline comment

Unit Test Directives

Special comment prefixes // > and // < are used for testing. They are ignored by the compiler but processed by coco test.

Naming Conventions

ElementConventionExample
File namesnake_casemy_logic.coco
Module namePascalCaseMyLogic
Package namesnake_casemy_package
Endpoints/FunctionsPascalCaseGetBalance
Classes & EventsPascalCaseTokenInfo
Class methodssnake_caseget_value
Variables & Argumentssnake_caseuser_balance
State & Field namessnake_casetotal_supply
ConstantsALL_CAPSMAX_SUPPLY