It's easy to write code that computers can understand. It's hard to write code that humans can understand.
Writing clean code is an important step to becoming a great developer.
So here's some things you can do today to start making your code clean AF
Writing clean code is an important step to becoming a great developer.
So here's some things you can do today to start making your code clean AF


Give everything a meaningful name. Everything 
A name should give you all the big picture information about what something is or does.
In general:
Variables should be nouns
Classes should be nouns
Objects should be nouns
Functions should be verbs or phrases

A name should give you all the big picture information about what something is or does.
In general:




Meaningful names are:
Descriptive
Easily pronounced (don't call something 'ddmmyyyy')
Searchable
Not similar to other names
Consistent with the rest of the code - use one word to describe a describe an abstract concept and STICK WITH IT





A function should do one thing 
This is self explanatory. Don't do more than one thing in a function. Keep it simple, keep it short.
Clean code should have a lot of small functions, not a few big functions.
Bonus: this will also help with naming the function!

This is self explanatory. Don't do more than one thing in a function. Keep it simple, keep it short.
Clean code should have a lot of small functions, not a few big functions.
Bonus: this will also help with naming the function!
Your code shouldn't lie 
This seems simple, but is often overlooked.
A function does something. It shouldn't secretly do something else. This includes changing variables within itself, or setting global vars.
Split this into 2 functions or make the name more descriptive.

This seems simple, but is often overlooked.
A function does something. It shouldn't secretly do something else. This includes changing variables within itself, or setting global vars.
Split this into 2 functions or make the name more descriptive.
Think about how we read code 
We read code from top to bottom.
If your code goes through steps, have the first step functions at the top & the last ones at the bottom.
We want to read the function that calls another function before we read the function that is called.

We read code from top to bottom.
If your code goes through steps, have the first step functions at the top & the last ones at the bottom.
We want to read the function that calls another function before we read the function that is called.
Minimize arguments 
A function should not require more than 3 arguments. This is unnecessarily complex.
If you're finding that your function needs more than 3 arguments, split the function into two, or think about the arguments themselves - could they be their own class?

A function should not require more than 3 arguments. This is unnecessarily complex.
If you're finding that your function needs more than 3 arguments, split the function into two, or think about the arguments themselves - could they be their own class?
Handle your errors separately 

Error handling should be separate from functions. Functions do one thing. They do not handle errors.


Error handling should be separate from functions. Functions do one thing. They do not handle errors.
Consider other data structures 
You may be using an array when you'd be better to use a hash table. Look up other data structures and find one suitable for your use.
This removes a lot of unnecessary code to make your data structure act like another one that already exists.

You may be using an array when you'd be better to use a hash table. Look up other data structures and find one suitable for your use.
This removes a lot of unnecessary code to make your data structure act like another one that already exists.
Comment your code 
A lot of clean code nerds will tell you that if your code is clean, you don't need comments. I disagree.
Code isn't human language. No matter how human you can make it, we will always understand comments better than we can understand code.
Write comments.

A lot of clean code nerds will tell you that if your code is clean, you don't need comments. I disagree.
Code isn't human language. No matter how human you can make it, we will always understand comments better than we can understand code.
Write comments.
Clean code makes programming easy to follow, and also helps you understand what you're coding as you're coding it. It forces you to critically think about your own code.
If you have any other tips, make sure to comment!


If you have any other tips, make sure to comment!


