# Commenting Code

Programming languages allow for lines of text that get ignored by the interpreter or compiler. These are called `comments`. Typically there are two types, a single comment and a block comment. Below are some examples:

{% tabs %}
{% tab title="C++, Java, and Javascript" %}
These three languages use the same comment technique:

```cpp
// Two 'forward' slashes create a single line comment.

/* 
   Slash star allow for a block comment
   These are more versatile and allow you to put larger, multi-line comments.
   It is important to note that a comment or block comment can also be used
   to make code "invisible" to the compiler. This helps when testing or
   debugging.
*/

// The following line was removed because it breaks things
// System.out.something.that.breaks(someInput);

/* ************************************************************************
  * Some programmers even use the asterisk to highlight certain comments. *
  * Although most good coders find that annoying and unprofessional       *
  *********************************************************************** */
```

{% endtab %}

{% tab title="Python" %}
Python utilizes the number (#) or pound (no, not hashtag) symbol for a single-line comment. I prefer to call it the [octothorpe](https://en.wiktionary.org/wiki/octothorpe). Multi-line comments begin and end with three double-quotation marks. Ya, Python is ~~strange~~ quarky.

```python
# This would be a comment line
x = 17   # A nice prime number

"""
 This is a multi-line comment in Python. The triple-double, as I just
 started calling it in my head. Just now.
 Similar to other languages, it is useful for larger comments or commenting
 out a large chunk of code.
"""
```

{% endtab %}

{% tab title="HTML" %}
Even HTML has a comment tag. It is the `<!-- -->` tag. Anything between those tags will not be shown on the web page but are visible if the user inspects the HTML file.

```markup
<!DOCTYPE html>
<html>
<body>

<p>This text is normal.</p>

<p><b>This text is bold. You might say legen<!-- wait for it -->dary.</b></p>

<!-- This text is invisible! -->

</body>
</html>
```

{% endtab %}
{% endtabs %}

&#x20;A more current IDE will allow you to hide or *fold* the comments so as not to make the code too messy. This is dependent on your [dev environment](https://cs.brash.ca/unit-2/how-do-we-code).

Code comments should **briefly** explain the *purpose* of the code, not how the code works. A good comment will include a description of how inputs and outputs are related, and a list of any expected side effects. Comments should not explain every line, nor should they try to explain what the code is doing "in layman's terms". What ends up happening is you duplicate your code with English step-by-steps, essentially making your code file twice as long (or longer).

Comments can also be fantastic for learners and alpha versions of a program. You can leave yourself and collaborators a note, comment out some nasty code or test case, or even keep track of changes, like a change log. But those comments should get deleted before a final version is submitted.

Below is a link to a fantastic article on code commenting from FreeCodeCamp:

{% embed url="<https://medium.freecodecamp.org/code-comments-the-good-the-bad-and-the-ugly-be9cc65fbf83>" %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://cs.brash.ca/unit-2/how-do-we-code/commenting-code.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
