Clean Code

Regular Clean coding
Even though you have a deadline, always keep code clean.If you have clean code, you'll save time in the future altering and updating code.

10:1 reading/writing code.

  1. Be responsible for the quality of your code. Even though your client, boss or someone else purchases your talents, it is your responsibility to write clean code.Your code defines your talent and abilities.
  2. Use meaningful names. Don't use vague variable names.
  3. Write code that expresses intent. When you write functions or programmatic steps, write it in a way that if someone else were to look at your code without knowing the language, they could still tell what your code is trying to do.
  4. Code should speak for itself, but if you write comments, keep them short and to the point. When you write a comment, it's another piece of the puzzle that you need to keep updated when you update your code. The biggest drawback of comments is that if another developer comes in and alters your code, they may not update your comments, and anyone else that reads the code afterwards may be misled since the comments are no longer valid. Keep them simple, brief and if you update something, keep the comments current.
  5. Keep code cleaner than you found it. When you get the chance, try to look at the surrounding code and clean it up. This doesn't just mean code formatting, this also means that if you see a variable that could be expressed with a better name, and is easily updated, update it and add your comment.
  6. Bob Martin - Single responsibility principle. When a function, method or class does 1 thing, does it well, and only does it. Don't try to write anything that tries to accomplish more than 1 goal. That will leave the next programmer confused and lost when they have to work on it in the future.
  7. Write tests. Not in the sense of pen and paper, but test on how the user may use the code. Unit tests are a great way of testing too. Write the test on paper, write the code, then test it. Rewrite code until it completes the test successfully.
  8. Work in short cycles. Trying to complete a huge project in one sitting will often lead to burnout, confusion or encourage the writing of sloppy code just to get it done. Stop. Take a break. Go for a walk. When you come back, come back refreshed, focused and eager to make something better. I've learned this through studying. Using the Pomodoro technique of studying for 15 minutes and taking a 5 minute break has been phenomenal in my studying and comprehension.
  9. Independent Architecture - There are good practices that you can see across other applications that can inspire you to create a more stable, reusable foundation of different elements. For example, don't constantly rewrite the same function on individual pages. Find a way to create the function as a separate file, and simply include that file in any framework you create.
  10. Practice. The more you code, the better you become. The more you code, the more ideas to write better code come to you. Yes, it's frustrating. Yes, it'll seem like there's not end to the projects. But often if your write clean code and find a better way in the future, you can go back to the previous clean code you wrote and apply the new style with little to no effort.