Hello, this is my second topic-based blog and today I will be talking about something I learnt about in depth over several days in my Software Process Management class. This was a very interesting topic and I learned a lot of things about code that I had previously not known about. Some of the things that I was taught in my earlier days of coding were proven to not be the best way to go about making organized, clear code. One example of this is that I was originally taught to make comments after most lines of code, just to make sure everyone reading the code will understand it. However, it turns out this was just a beginner step to help myself learn. In reality, clean code should be easy to read and understand, making many comments obsolete.
Now I will talk about some examples of obsolete comments. One of these are redundant comments. These are comments that are unnecessary. An example of this would be: z = x + y (sets z to the sum of x and y). As you can see, the code speaks for itself, and this comment is completely obsolete. Another comment type that is unnecessary would be misleading comments. These comments are usually created when someone forgets about a comment after updating the code. This leads to the wrong comment being on a block of code that doesn’t even do what that comment states!
The blog I researched for this post is linked here: Writing Clean Code: Tips and Best Practices – DEV Community
Unsurprisingly, this blog shared many of the same values that I learnt about in class. It gave me an overview of the material I had gotten an in-depth understanding of, with many additional helpful tips and tricks. This blog mentioned using meaningful names for your classes, functions, methods, and variables. This ensures that someone else who is reading your code can easily understand EXACTLY what everything is used for. Ex) “bananas VS. bananasInBasket”
Another thing that this blog shared with what I learnt about is to make sure functions and methods are small and limited to a specific number of lines. You don’t want an entire code that may be repeated inside one method. Instead, create a function that you can call inside the method to keep the code clean.
The website also mentioned good practices for making comments, and to make sure you refactor your code a lot over time!
From the blog cs@worcester – Akshay's Blog by Akshay Ganesh and used with permission of the author. All other rights reserved by the author.