Comments

Writing comments in Chasm source files.

Chasm uses # for single-line comments. Everything from # to the end of the line is ignored by the compiler.

# This is a full-line comment

x = 42   # This is an inline comment

# Comments can go anywhere:
def on_tick(dt :: float) do   # dt is seconds since last frame
  @score = @score + 1         # increment every tick
end

There Are No Block Comments

Chasm has no /* ... */ or multi-line comment syntax. To comment out a block of code, prefix each line with #:

# def debug_draw() do
#   draw_rect(@player_x, @player_y, 32.0, 32.0, 0xff0000ff)
#   draw_text("#{@player_x}", 10, 10, 16, 0xffffffff)
# end

Most editors have a keyboard shortcut to toggle line comments on a selection (usually Cmd+/ or Ctrl+/).

Documentation Style

By convention, function documentation comments go directly above the function:

# Returns the distance between two points.
# Both points are given as separate x/y components.
defp dist(ax :: float, ay :: float, bx :: float, by :: float) :: float do
  dx = bx - ax
  dy = by - ay
  sqrt(dx * dx + dy * dy)
end

Using Comments for Disabled Code

During development it is common to comment out an alternative implementation or a debug call:

def on_tick(dt :: float) do
  move_player(dt)
  # move_player_debug(dt)   # uncomment to use slower debug version
  check_collision()
end