4️⃣

4.4 Operators Style Guide

Chapter Table of Contents

Ch. 4 Operators

Section Table of Contents

Quick Summary

Before we move on here's a brief review of all the operators we learned so far:
 
notion image
 

Style Guide

 
When using binary operators, you should leave at least 1 space between the operands (the things being operated on) and the operator. When using a unary operator, you should not leave any space. Remember, you should follow style conventions to help code be readable to humans.
 
Good style:
a += 1; a = 5 - 1; a++;
 
Bad style:
a+=1 a=5 -1; a ++;
 

Lots of Operators!

Now that you’ve learned all of these operators, you might be tempted to do something like this:
a += b++ * --a % 50;
However, as you probably can see, this is not very readable. Therefore, if you have a lot of operators, you probably want to separate them into multiple lines.
 
 
⚖️
Copyright © 2021 Code 4 Tomorrow. All rights reserved. The code in this course is licensed under the MIT License. If you would like to use content from any of our courses, you must obtain our explicit written permission and provide credit. Please contact classes@code4tomorrow.org for inquiries.