There are a lot of ways to make code more efficient. A lot of organizational tactics that software engineers use are a lot simpler than you might think. Code can benefit from some organization, when someone is bug-fixing, reading your code, or just wants to understand what is going on.
This is where clean code comes in. Clean code will allow you to read your own code better and be more efficient with your time. If you have variable names or comments in your code where you can’t really understand what is happening, that’s a huge problem! When working on a large group of code, especially on a team, it is important to make your code readable. One thing I have taken from the article “Clean Code — A practical approach” by Mikel Ors, is that you can even do something as little as turning an iteration to a number into a variable.
Example:
numCars = 10
for (i=0; i < numCars […]
// If you just iterated to 10, it wouldn’t show what it was iterating to and the user might get confused. It just takes a little bit of extra effort.
That being said, code smells are something to avoid! You don’t want to have unnecessary things in your code because not only can this prevent readability, but it can also slow down your code. From “Code Smells” by Jeff Atwood, it is important to ruthlessly delete your unused code. If you have a block of code lying around that doesn’t do anything to the overall project, it can make it so the program runs slightly slower and make it harder on editors trying to fix and locate code.
Example:
numCars = 10
numberCars = 5 // Isn’t being used
for (i=0; i < numCars […]
// Can confuse the user on whether this is iterating to 5 or 10
Overall, it is important to clean up your code. Just because your code works and the result is great, doesn’t mean that you can’t make it more efficient to code and faster to use. In big projects, these problems you might think are small turn very big very fast. It is important to prevent these issues while you see them.
References:
“Clean Code — A practical approach” by Mikel Ors on Medium
“Code Smells” by Jeff Atwood on Coding Horror