Home The Quantizer> Raspberry Pi> What does uncomment mean when using Raspberry Pis

What does uncomment mean when using Raspberry Pis

If you are new to Raspberry Pi, more specifically programming, than figuring out what uncomment meant in tutorials and forums may have confused you. Especially because all these places just assume you have a certain level of knowledge. Well my friend today I am going to bring it down to a level that should hopefully alleviate some of your frustration.

Uncommenting is a technique used to enable a line of code or configuration that has been turned off, aka ignored by the program or configuration. This is usualy done by removing the special character or characters that mark a line or group of lines to be ignored. Common comment symbols are // # and /* */

What does a comment look like?

Well, comments look differently in different programming languages and configuration files but some of the most common are the

  • # used by Python
  • // for single lines and /* and */ for block comments in languages like JavaScript

Here is a simple python program that has commented out the second line

print("I'm the first line")
#print("I'm the second line")

The output of this program would be

I'm the first line

Notice how the 2nd line was ignored because it was commented out?

The // and /* will not work in Python, most language use one or the other of the two common types but not both

Why do people use comments?

One of the main reasons for the existence of comments is to…well leave comments 😄. The big value that comments provide is it allows the programmer to put text into the code that the compiler or interpreter ignores. This is useful because sometimes when writing programs it is not obvious what a line or a blocks of code is doing. So, as a way to help out programmers will often leave comments to let other programmers, or themselves in a few months, know what this code is doing.

Not only are comments used for comments but they are also used to turn on or off blocks of code that may be useful in the future. Because the compiler or interpreter ignore these liens that means that who ever is writing the software can leave in different configuration options that are not on by default simply by comment them out. Take a look at the following block to see what that may look like

In the Raspberry Pi config.txt you will see a line like this

# uncomment if you get no picture on HDMI for a default "safe" mode
#hdmi_safe=1

The hdmi_save=1 is being ignored by the configuration because this file is using # as the comment symbol. So if you want to enable the hdmi_safe=1 configuration thant just remove the # from the beginning of the line. An uncommented (enabled) version would look like the following.

# uncomment if you get no picture on HDMI for a default "safe" mode
#hdmi_safe=1

Comments in Python

Python also uses the # to comment out code. So if the following script was ran

print("First line")
#print("Second line")
print("Third line")

than the output would be

First line
second line

Pretty simple 👍

Comment in JavaScript

JavaScript uses // for single lines and /* and */ for block comments. A single line comment would look like the following excerpt from our JavaScript tutorial on converting a csv to an array

/*
This is the main section of code that converts the CSV to an array
It takes itterates over every entry in the `rows` variable to generate
the final output
 */
let housingDataArray = [];
rows.forEach((housingEntry, index) => {
    let housingObject = new Object();
    // creat array from CSV entry string
    let housingEntryArray = housingEntry.split(",");
    // loop over every element in the housingEntryArray to build the housingObject
    housingEntryArray.forEach((e, i) => {
        // set each value with its corresponding title in the housing object
        housingObject[titleRowArray[i]] = e;
    });
    // append hosingObject to the housingDataArray
    housingDataArray.push(housingObject);
});

You can see we are using the both single line and block comments to help the reader understand what the purpose of of different sections of the code. This is more descriptive than you will normally see out there but because it was a tutorial we were assuming readers of all skill levels so. That is why we were extra descriptive with our comments.

Comments in Configuration Files

The Raspberry Pi uses a config.txt file to allow a user to control some configration options on the pi. The following is an excerpt from config.txt

# uncomment this if your display has a black border of unused pixels visible
# and your display can output without overscan
#disable_overscan=1

You can see this file is using the # to comment out disable_overscan=1. So if this is someting you wanted to turn on than you would just remove the # like this

# uncomment this if your display has a black border of unused pixels visible
# and your display can output without overscan
disable_overscan=1

Comments in C

C like JavaScript uses the // for single line comments and /* */ for block comments. Here is an example

#include <stdio.h>
/* this is a simple hello world c program
you could compile it using gcc on a raspberry pi */
int main(void){
    printf("Hello, I am not commented out");
    //printf("No one will see me because I am commented out :(");
    /*
    printf("I'm ignored by the compiler");
    printf("I am also ignored");
    */
    printf("Finshed");
    return 0;
}

This would output

Hello, I am not commented out
Finished

And that is it! All you need to know to get up and running uncommenting to your hears desire! Have fun 🙏