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

Comments

reading/comments.livemd

Comments

Mix.install([
  {:jason, "~> 1.4"},
  {:kino, "~> 0.9", override: true},
  {:youtube, github: "brooklinjazz/youtube"},
  {:hidden_cell, github: "brooklinjazz/hidden_cell"}
])

Navigation

Home Report An Issue Github CollabArithmetic

Review Questions

Upon completing this lesson, a student should be able to answer the following questions.

  • How do you write a comment in Elixir?
  • What keyboard command can you use in both Livebook and Visual Studio Code to comment one or more lines of code in Elixir?

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

# 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

Further Reading

Throughout this course we will often recommend trusted resources for further study.

Some of our favourite platforms to recommend include:

  • HexDocs A hosting platform for documentation
  • Elixir School An education platform for learning Elixir.
  • Exercism An education platform with a great number resources and exercises. You can signup for an account if you would like further practice with a concept beyond the exercises in this course.
  • Elixir-lang The official Elixir website which includes guides, documentation, and other Elixir resources.

Commit Your Progress

DockYard Academy now recommends you use the latest Release rather than forking or cloning our repository.

Run git status to ensure there are no undesirable changes. Then run the following in your command line from the curriculum folder to commit your progress.

$ git add .
$ git commit -m "finish Comments reading"
$ git push

We’re proud to offer our open-source curriculum free of charge for anyone to learn from at their own pace.

We also offer a paid course where you can learn from an instructor alongside a cohort of your peers. We will accept applications for the June-August 2023 cohort soon.

Navigation

Home Report An Issue Github CollabArithmetic