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 …


This content originally appeared on DEV Community and was authored by Jeff Chavez

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!


This content originally appeared on DEV Community and was authored by Jeff Chavez


Print Share Comment Cite Upload Translate Updates
APA

Jeff Chavez | Sciencx (2021-08-26T01:54:31+00:00) Can I Write Clean Code?. Retrieved from https://www.scien.cx/2021/08/26/can-i-write-clean-code/

MLA
" » Can I Write Clean Code?." Jeff Chavez | Sciencx - Thursday August 26, 2021, https://www.scien.cx/2021/08/26/can-i-write-clean-code/
HARVARD
Jeff Chavez | Sciencx Thursday August 26, 2021 » Can I Write Clean Code?., viewed ,<https://www.scien.cx/2021/08/26/can-i-write-clean-code/>
VANCOUVER
Jeff Chavez | Sciencx - » Can I Write Clean Code?. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/08/26/can-i-write-clean-code/
CHICAGO
" » Can I Write Clean Code?." Jeff Chavez | Sciencx - Accessed . https://www.scien.cx/2021/08/26/can-i-write-clean-code/
IEEE
" » Can I Write Clean Code?." Jeff Chavez | Sciencx [Online]. Available: https://www.scien.cx/2021/08/26/can-i-write-clean-code/. [Accessed: ]
rf:citation
» Can I Write Clean Code? | Jeff Chavez | Sciencx | https://www.scien.cx/2021/08/26/can-i-write-clean-code/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.