Clean Code

Clean code. Succinct. Legible. Intuitive. Write your code with others and your distant future self in mind. When you are writing code, please keep it clean. Some nice, well-written code is a beautiful thing. It's easy to tell what it's doing. It's easy to tell what changes can be made so that you can have it do other things. It doesn't force others (or you, if you revisit it down the road) to waste significant brain power trying to wrap their (or your) minds around it. Some things to do to keep your code clean: 1. Use small functions which only do one thing. If a function is getting too big, it means there's too much going on and it won't be easy for a reader to understand what's happening in it. This can be done to taste, but I've been told that around twelve lines is a good max. 2. DRY (a common, though sometimes disputed principle - don't repeat yourself). If you're writing the same code in different spots, it can be hard to maintain. If you realize there's a problem and it needs to change, you always need to know that it needs to be changed elsewhere. That will be hard enough for you. It will be next to impossible for someone else picking up on your code later. 3. Name your variables and functions carefully. You want the person reading it to know exactly what the variable is representing or what the function does. If you don't pay attention, it can be confusing and cause people to write code that behaves in a way they had not intended, due to the code you wrote not behaving as they expected.

Comments