Coding Conventions

Learn how to follow code- and language-specific conventions.

Using code conventions

Many languages or software companies have standardized the way we format the code we write. These are called code conventions, and in this lesson, we’ll take a look at what they are.

Most programming languages have code conventions, which are recommendations for how we’ll organize our files, indent our code, format comments, and use naming conventions, just to mention a few.

These aren’t rules, but a recommended code style. The idea is that if all programmers using a language use the same code conventions, their code will look more or less the same. This means that if you know the conventions, it’s easier for you to navigate the code and read it. Therefore, it’s essential to learn the conventions for every programming language you’re using.

We’ll take a look at some typical conventions and see how they differ among a couple of languages.

Naming conventions

As we mentioned earlier in this course, a naming convention is a set of rules for formatting the names of variables, types, functions, and other entities in the source code.

Sometimes, programming languages come with official naming conventions. Other times, they aren’t official, but are commonly used by the community using that language. Some companies have developed their own naming conventions for the code written within that company.

A naming convention is not about how you name things, but how you format the names. A naming convention dictates how uppercase and lowercase characters should be used and how names consisting of multiple words should be formatted. Some different styles are frequently used. Let’s revisit some of them.

Camel case

In camel case, each word in a multiword name has an initial capital letter, except for the very first letter. For example, if we want to store a value for the outside temperature, the name used for that variable would be outsideTemperature in camel case.

Camel case is also known as camel caps ...