-
Notifications
You must be signed in to change notification settings - Fork 41
Code Style Guide
Michael edited this page Dec 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
-
Don't use spaces around parentheses, or braces
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)
. - Normal variables are lowercase and use underscores like functions, e.g.
convex_set
- 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
- Files are named like functions, e.g.
my_new_file.jl
- Use
1.0
instead of1.
- Branch names should be prepended with the initials of the creator and a forward slash, e.g.
mg/newIdea
instead ofnewIdea
- Commit messages should have the following format:
<#IssueId> Short (72 chars or less) summary
More detailed explanatory text. Wrap it to 72 characters. The blank
line separating the summary from the body is critical.
Imperative style for the commit message: "Fix bug" and not "Fixed
bug" or "Fixes bug."
The issue id can be ommitted if the commit does not related to a specific open issue