-
Notifications
You must be signed in to change notification settings - Fork 41
Code Style Guide
Michael edited this page Oct 8, 2018
·
11 revisions
The code in this repository follows the naming and style conventions of Julia Base with a few modifications. This style guide is heavily "inspired" by the guides of John Myles White and JuMP.
-
Use one tab when indenting a new block (except
module
) -
Use spaces between operators, except for
^
and:
-
Use single space after commas and semicolons
Bad: f(x,y) = [5*sin(x+y);y']
Good: f(x, y) = [5 * sin(x + y); y']
- Use spacing with keyword arguments
Bad: foo(x::Integer=1)
Good: foo(x::Integer = 1)
- Don't parenthesize conditions
Bad: if (a == b)
Good: if a == b
- Modules and Type names use capitilization and camel case, e.g.
module LinearAlgebra
,struct ConvexSets
. - Functions are lowercase and use underscores to seperate words, e.g.
has_key(x)
,is_valid(y)
. - Constants are uppercase, e.g.
const MY_CONSTANT
-
Always append
!
to names of functions that modify their arguments. - Function arguments that are mutated come first. Otherwise follow the rules layed out in Julia Base Argument ordering
- Use
1.0
instead of1.