Can I Write Clean Code?

I have been having difficulties in writing clean code. But the series of posts in Medium helped a lot. So here are the links to the posts and my takeaways that are worth sharing from part 1, part 2, part 3, & part 4 of Writing Clean Code series by Logeshvar L.

  1. Avoid redundant information. E.g: UserWithNameAndAge is more redundant and is very lengthy. Prefer User
  2. Follow the casing conventions according to the language you’re using. Example: camelCase in Java/Javascript, snake_case in Python and so on.
  3. Be consistent in naming your variables/methods. Example: Avoid using getAge(), fetchName(), retrieveMail(). Instead, be consistent and name them getAge(), getName(), and getMail().
  4. Avoid slang, unclear abbreviations and disinformation (indicative of wrong data structure in the variable name, etc).
  5. Avoid comments that say the obvious or those which are misleading.
  6. Never comment out code, just remove.
  7. Use comments only when you want to provide licensing information, warnings or there is a need to provide API documentation.
  8. Use comments when code is difficult to grasp at a single sight and it would make it easier by providing some comments as explanations (e.g: regex).
  9. Properly format the code by adding blank lines to separate unrelated concepts and grouping similar/ related concepts together.
  10. Do not write an unreadably long line of code or name in a single line. Split them into multiple lines and use precise short names.
  11. Write functions with a minimum number of parameters.
  12. Keep your functions simple to read and understand without writing 100s of lines of code inside a single function. Instead, split into multiple short functions.
  13. Consider splitting of functions, but be sensible.
  14. Increase reusability and make code DRY (Don’t Repeat Yourself).
  15. Try not to mix different levels of abstraction in the function.
  16. Avoid unexpected side effects.
  17. Check if your function makes unit testing easier.

These are the takeaways which you can pretty much read in the blog posts. After reading the posts. I hope we can all answer the question above that Yes! We can write clean code with practice and tips provided in the blog posts.

I encourage you to read each posts as he provides helpful examples and detailed steps/tips to implement writing clean code.

I’ll surely get back to these posts as I write codes.

To God be the glory!


Source link