Powered by AppSignal & Oban Pro
Would you like to see your link here? Contact us

Comments

reading/comments.livemd

Comments

Mix.install([
  {:youtube, github: "brooklinjazz/youtube"},
  {:hidden_cell, github: "brooklinjazz/hidden_cell"},
  {:tested_cell, github: "brooklinjazz/tested_cell"},
  {:utils, path: "#{__DIR__}/../utils"}
])

Navigation

Return Home Report An Issue

Setup

Ensure you type the ea keyboard shortcut to evaluate all Elixir cells before starting. Alternatively, you can evaluate the Elixir cells as you read.

Comments

You can create inline comments in your code in Elixir using #. Anything after the # on the same line will be part of the comment

# You can use comments to leave messages in your code.

It’s sometimes handy for documenting what your code does. However, it’s often better to use comments sparingly. Leaving a comment often means that there’s something in your code that didn’t explain itself.

In these moments you might find it useful to consider how you can improve your code to be self documenting rather than leaving a comment in unclear code. There are better forms of documentation that you’ll learn about in future lessons.

Sometimes it’s handy to use comments to temporarily remove pieces of code and save them for later. However, comments can be misused. You’re also likely to encounter codebases that leave thousands of TODO comments everywhere. TODO comments can be useful, but when abused they can be worse than no comment at all!

# Use comments to leave notes on your code.

Depending on your code editor, You can comment out many lines of code at once. Highlight the code you want to comment then press the correct keybinding. The binding will be different depending on your editor and if you are using GNU/Linux, macOS, or Windows. In Livebook, it’s likely CTRL-/ or COMMAND-/ but you can double check in the keyboard shortcuts tab.

Click on the keyboard icon in the left sidebar of this page to see all of the keyboard shortcuts.

Your Turn

In the Elixir cell below, create a comment # hello world

In the Elixir cell below, comment all of the code out using the Toggle lines comment keyboard shortcut.

1 + 1
2 + 3
3 + 1 + 2
123 + 12 + 256

Commit Your Progress

Run the following in your command line from the beta_curriculum folder to track and save your progress in a Git commit.

$ git add .
$ git commit -m "finish comments section"

Up Next

Previous Next
Github Collab Arithmetic