Skip to content
AgileLogics
4 min read

Comments and Style

Prerequisites: Functions

Comments

# A single-line comment
tax_rate = 0.2  # after code

#=
  A block comment
  spanning several lines
=#

"""
    with_tax(price)

Return `price` including tax at the global `tax_rate`.
"""
with_tax(price) = price * (1 + tax_rate)

println(with_tax(100))
120.0

A string placed directly before a function is its docstring. It's written in Markdown, shown by ?with_tax in the REPL and in VS Code, and used by Documenter.jl to build documentation websites. The convention is to start with the function's signature, indented four spaces.

Style guidelines

The official Julia manual has a style guide; the main points are:

  • Four spaces per indentation level.
  • lowercase or snake_case for functions and variables, CamelCase for types and modules, UPPER_CASE for constants.
  • End names of functions that modify their arguments with !.
  • Write functions, not scripts: put work inside functions and keep global code short.
  • Prefer small functions that do one thing; they're easier to test and Julia compiles them well.
  • Don't over-annotate types. Add them when they document intent or choose between methods, not "for speed" — Julia infers types itself.

Tools

  • JuliaFormatter.jl — formats code automatically (several styles, including the popular Blue style).
  • The VS Code Julia extension — linting hints, go-to-definition, and documentation on hover.
  • Aqua.jl and JET.jl — check packages for common problems and catch errors before running (Level 3).

What's next

You now know the core of Julia. Try the Beginner Projects, then continue to Level 2 — Intermediate, which starts with the type system and multiple dispatch — the ideas that make Julia different from every other language you know.