You can always write comment to your codes. But comment itself can be outdated and misleads a developer. So writing self-documented codes must our first aim to make our code more maintainable.
In my opinion a big step to achieve self-documented code begins writing if clauses.
If a developer understands if clause, he/she understand purpose of the code block more easily.
But how can we write more readable if clause.
Very easy: Don't write logical comparisons into if clause.
1 if ((preprocessedFailedEmails.Count > 0) || (failedEmails.Count > 0))
2 {
3 //some code
4 }
Although this is a very simple if clause it's a bit hard to get what is happening there. Let's make it more readable.
1 bool hasErrors = ((preprocessedFailedEmails.Count > 0) || (failedEmails.Count > 0));
2 if (hasErrors)
3 {
4 //some code
5 }
Happy coding...
Bu yazıyı ilk değerlendiren siz olun
- Currently 0/5 Stars.
- 1
- 2
- 3
- 4
- 5