Get startedGet started for free

Coding Style

1. Coding Style

Everyone agrees that having a consistent coding style helps reduce bugs and makes collaborating a lot easier. However, everyone thinks that their style is the correct way. So coming up with a consistent is nigh on impossible.

2. Consistency

But all is not lost! The crucial aspect of coding style is consistency. What this means in practice is you may have to adjust to your style to fit in with your collaborators.

3. Uncontroversial rules

There are a few, very few, rules that people agree on. You may be aware that you can use the arrow or the superior equals sign for the assignment in R. While people disagree on which one to use, everyone agrees you should be consistent. When I'm coding, I typically use the equals sign. But DataCamp uses the arrow. So to be consistent with the rest of there courses, I use the arrow in this module.

4. Spacing

Consistent spacing is also important. It's something that's really easy to implement, makes code much easier to understand. For example compare this line of code that is space lacking. To the same code, with a few spaces.

5. Spacing

Two widely accepted rules are: "Use spaces around assignment operators", and "Add a space after a comma". Simple rules that massively improve readability.

6. Let's practice!

Let's practice