15
Jan/080
Jan/080
Is your code understandable?
At work I’m constantly trying to improve our code base and at the same time teaching others to do the same thing. One of the biggest problems is that when people write code they don’t think about what they are writing.
Some tips for writing better code :
- Comments
- Keep clear.
- Don’t write too long comments, 1-5 lines should be enough in most cases.
- How many things you need to memorize during reading to understand it.
- Try keeping it in1-5 different things (e.g. variables, special rules..).
- Is there a better way to do this?
- If there is and it doesn’t take too much time then do it!
- Why are you doing this?
- If there is no reason to do it, then don’t!
- Can it be simpler?
- Try divide and conquer, e.g. split function.
- Don’t duplicate code!
- Don’t copy & paste the same code around, make one function for it and then call that.
- Naming
- Don’t use variable names like temp or index, give them a proper name -> temp_vertex_buffer or vertex_buffer_index. Same goes for functions!
- Don’t write huge functions
- Smaller functions are easier to handle and have less bugs.
- Minimize Function Dependencies
- Try writing functions that are independent, e.g. don’t call other functions.
- See Function Cohesion
Enjoy this article?
Comments (0)
Trackbacks (0) ( subscribe to comments on this post )
No comments yet.
Leave a comment
No trackbacks yet.