Categories
Uncategorized

Clean Code

What is Clean Code?

Writing clean code means to be an efficient communicator.

Clean code is easy to read, easy to understand and easy for anyone to step in and make fixes or changes when needed.

When writing code, you should not be thinking about whether it makes sense to you- you should be considering if it will make sense to the next person who’s going to look at the code.

Clean code allows you to clearly communicate with the next person who works on your code.

5 Tips for Keeping Code Clean

  1. Use meaningful names: When coming up with names for your variables, classes, or functions, it’s imperative to use appropriate names for them. They should be clear and descriptive, and represent what that variable, class or function does.

2. Keep it simple: When it comes to writing clean code, it’s important to remember “less is more”. Avoid duplicating code whenever possible, which will make it easier to navigate and maintain.

3. Use comments sparingly: Comments are extremely helpful when trying to show others what you’re trying to do with a particular part of code. However too many comments can make the code look muddled and make the code more difficult to understand/maintain.

4. Reduce number of characters in a line: Remember that we want to write code that’s easy to read. By avoiding long lines of code, you can ensure that whoever opens the file to work on that code, will be able to read the code without scrolling horizontally to see what the code is doing.

5. Single Responsibility Principle (SRP): The SRP is the idea that each function or class within a program should only contain one main responsibility or goal.

My Goals

One thing to try

For the most part, I feel like I try and stay true to most of the principles listed out above. However I know I have a tendency to write a lot of comments. My goal is to make sure the comments I write are efficient and necessary.

One thing to avoid

I will avoid writing duplicate code. I have struggled in the past with duplicating code that should have been turned into a function that gets called when needed. I will aim to work on this, avoiding duplicate code.