To write code comments or not, it should not be a question

Published Mar 02 2021 08:47 AM 3,007 Views
Comments, just do it. I write this post because I read a couple of articles, and messages on social platforms about stop using comments in your code. In some cases, there is good reasoning behind it, but even with this reasoning, I believe that comments are too valuable for your DEV team.

 

To start this article, I want to tell you that using comments or not in your codebase is an opinion. There are always PROs and CONs with everything you do or use. I also want to point out that people saying not to use comments are not wrong or right. They have good intentions and believe why they think comments should not exist in your code. For instance, they want to highlight that it is essential to write clean code, invest more in better documentation, less code smells, and many more reasons.

 

I agree that we need to make our code better, write better documentation, and do more end-to-end testing, but comments have no impact on these points. They might even improve some of these points.

Comments == Clean Code

 

Writing comments in your code does not mean that your code cannot be clean.

What is clean code? Clean code is yet again an opinion. It is like when you ask a kid to clean their room. Two minutes later, they tell you it is completed. When you go to their room, they put everything in a box. For them, that is cleaning, but is it for you? Maybe you like that all of their stuff is sorted in different boxes.

When you write code, the first intent should be to write it so that everyone can understand it. Sometimes you implement the functionality so that you need to remind yourself why you did it or tell someone else. If you would not do it, it can lead to bugs later on in the process, when someone would refactor the code.

By not writing comments, you make the assumption everyone else is on par with you. That would be so great, but this is far from the truth.
 
Important: Never assume anything
I still know when C# introduced Linq or Lambda expressions. It was very easy to refactor all your loops to use this new way of writing your code. Instead of 10 lines, you ended up with two lines. Incredible, you might think, but many developers did not even know what was happening. It was too new, and some developers were using tools to do the refactoring of this. At that time, in the company I was working in, we decided to educate everyone before refactoring all the code to use it. Once everyone understands how it works, we could think about starting to use it.

Once everyone understood it, we also started commenting when we refactored these lines. Everyone in the team indeed understood it, so what is the point? Well, new developers are joining the team.
 
Another good reason from Wassim Chegham
 
comments1.png

Comments != bad code

Comments cannot fix bad code or bugs. This statement is something I read as well in one of the articles. I agree that comments cannot fix bad code, but what is the reason for the bad code, and what is bad code?

Again, it assumes that the other developer has the same skills as you.

What if a junior developer in your team wrote the code?

If there were comments, you could see where she/he was after. Show the person how to write the particular code more solidly. Or teach them why you think this is bad behavior. We were not perfect the first time when we were writing code, and still, each day, we learn new things ourselves.
 
It might even be so that the comments will help you fix the bug, but the comments will not create the bug. 

Comments lead to more productivity

Many believe that comments lead to noise in the codebase, but is this actually true?

I Believe that having comments in the code is beneficial for productivity. Imagine if you do not understand a part of the logic or why functionality was implemented in a particular way.

Having no comments or references, you might need to go through the whole code step by step to understand the person's thoughts and implementation. Another option would be to call the person to clear things out, but two people are less productive during that call.

Comments are a way of communication

Communication in your team is crucial. A great team relies on good communication.

Comments are a way to communicate to other developers to give more information about how a particular functionality is implemented.

Challenges

Comments also come with a couple of challenges, which I believe are a way of working or guidelines in your team.

Outdated comments

What do you do when you implement a breaking change? Do you leave your documentation untouched?

You will have to do an update to your documentation. The same goes for your comments. When you refactor code, you will have to update the comments or remove them if it does not make sense anymore.

Updating your comments is good developer behavior.

Over-documenting

I also read that many think you need to document in multiple locations when you are writing comments. Comments are not documentation.
 
Documentation: material that provides official information or evidence or that serves as a record.
 
Comments will not serve as the official information about how your solution works or how you can use it.

Comments: an explanatory note in a book or other written text.

  1. Do not write comments for having more lines of code.
  2. Do not write comments to document your code.
  3. Write comments if it makes sense to write them. For instance, to prevent someone else from writing the same mistake.
  4. Use them to explain the `why`, not the `what`.

Comments create noise in your code

In my opinion, it also creates structure. It let your eyes rest. Take a break. For me, line breaks are even more important to add to your code and the number of code lines.

I have a hard time focusing on code when there are too many lines in one file, hardly any line breaks, and no comments. When this is the case, it feels like I am on a boat and get a bit see sick. The reason for this is due to my astigmatism, also the reason why I am wearing glasses.

As these lines of code might feel noise to you, to me, they give my eyes a break. Let me focus on the next block of code.

Why should you comment?

The most crucial reason to comment is for yourself as this will help the future you from understanding your own code.

The next reason is to help others understand you. Suppose an employee takes over a project from you or enters your team. It will make their lives easier. Or when you do a handover when leaving the company, the person sill not have any ways to contact you anymore. Would you like it that you enter a codebase where you do not understand any of the written logic?

Commenting tips

 
  • KISS: Keep it short and simple - you do not need to write a book.
  • Do not comment-out lines of code. During debugging/testing, this might happen, but make sure not to check in these lines. This behavior leads to code smells. Be sure your code lives inside source-control. That way, you do not have to worry about a deleted line of code. The main reason why this behavior happens is not to lose that one precious line of code.
  • Write code you understand so that you do not always need to comment.
  • Explain the why not the what.
    • If you need to explain the what, in many cases, it is too difficult to understand. Try to simplify, if not possible, you can comment. An example could be the screenshot from above.

Best of both worlds

There is a solution for everything. Almost everything can be solved by code. If you are a person that does not like to see comments, I have created just the VSCode Extension for you. With the Hide Comments extension, you decide if you want to show or hide the comments for the project.
 
comments2.png
%3CLINGO-SUB%20id%3D%22lingo-sub-2178622%22%20slang%3D%22en-US%22%3ETo%20write%20code%20comments%20or%20not%2C%20it%20should%20not%20be%20a%20question%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2178622%22%20slang%3D%22en-US%22%3E%3CDIV%3E%3CSPAN%3EComments%2C%20just%20do%20it.%20I%20write%20this%20post%20because%20I%20read%20a%20couple%20of%20articles%2C%20and%20messages%20on%20social%20platforms%20about%20stop%20using%20comments%20in%20your%20code.%20In%20some%20cases%2C%20there%20is%20good%20reasoning%20behind%20it%2C%20but%20even%20with%20this%20reasoning%2C%20I%20believe%20that%20comments%20are%20too%20valuable%20for%20your%20DEV%20team.%3C%2FSPAN%3E%3C%2FDIV%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CDIV%3E%3CSPAN%3ETo%20start%20this%20article%2C%20I%20want%20to%20tell%20you%20that%20using%20comments%20or%20not%20in%20your%20codebase%20is%20an%20opinion.%20There%20are%20always%20PROs%20and%20CONs%20with%20everything%20you%20do%20or%20use.%20I%20also%20want%20to%20point%20out%20that%20people%20saying%20not%20to%20use%20comments%20are%20not%20wrong%20or%20right.%20They%20have%20good%20intentions%20and%20believe%20why%20they%20think%20comments%20should%20not%20exist%20in%20your%20code.%20For%20instance%2C%20they%20want%20to%20highlight%20that%20it%20is%20essential%20to%20write%20clean%20code%2C%20invest%20more%20in%20better%20documentation%2C%20less%20code%20smells%2C%20and%20many%20more%20reasons.%3C%2FSPAN%3E%3C%2FDIV%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CDIV%3E%3CSPAN%3EI%20agree%20that%20we%20need%20to%20make%20our%20code%20better%2C%20write%20better%20documentation%2C%20and%20do%20more%20end-to-end%20testing%2C%20but%20comments%20have%20no%20impact%20on%20these%20points.%20They%20might%20even%20improve%20some%20of%20these%20points.%3C%2FSPAN%3E%3C%2FDIV%3E%0A%3CH2%20id%3D%22toc-hId--522252935%22%20id%3D%22toc-hId--522252935%22%3E%3CSPAN%3EComments%20%3D%3D%20Clean%20Code%3C%2FSPAN%3E%3C%2FH2%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CDIV%3E%0A%3CDIV%3E%3CSPAN%3EWriting%20comments%20in%20your%20code%20does%20not%20mean%20that%20your%20code%20cannot%20be%20clean.%20%3C%2FSPAN%3E%3C%2FDIV%3E%3CBR%20%2F%3E%3CDIV%3E%3CSPAN%3EWhat%20is%20clean%20code%3F%20Clean%20code%20is%20yet%20again%20an%20opinion.%20It%20is%20like%20when%20you%20ask%20a%20kid%20to%20clean%20their%20room.%20Two%20minutes%20later%2C%20they%20tell%20you%20it%20is%20completed.%20When%20you%20go%20to%20their%20room%2C%20they%20put%20everything%20in%20a%20box.%20For%20them%2C%20that%20is%20cleaning%2C%20but%20is%20it%20for%20you%3F%20Maybe%20you%20like%20that%20all%20of%20their%20stuff%20is%20sorted%20in%20different%20boxes.%3C%2FSPAN%3E%3C%2FDIV%3E%3CBR%20%2F%3E%3CDIV%3E%3CSPAN%3EWhen%20you%20write%20code%2C%20the%20first%20intent%20should%20be%20to%20write%20it%20so%20that%20everyone%20can%20understand%20it.%20Sometimes%20you%20implement%20the%20functionality%20so%20that%20you%20need%20to%20remind%20yourself%20why%20you%20did%20it%20or%20tell%20someone%20else.%20If%20you%20would%20not%20do%20it%2C%20it%20can%20lead%20to%20bugs%20later%20on%20in%20the%20process%2C%20when%20someone%20would%20refactor%20the%20code.%3C%2FSPAN%3E%3C%2FDIV%3E%3CBR%20%2F%3E%3CDIV%3E%3CSPAN%3EBy%20not%20writing%20comments%2C%20you%20make%20the%20assumption%20everyone%20else%20is%20on%20par%20with%20you.%20That%20would%20be%20so%20great%2C%20but%20this%20is%20far%20from%20the%20truth.%3C%2FSPAN%3E%3C%2FDIV%3E%0A%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%0A%3CDIV%3E%3CSTRONG%3EImportant%3C%2FSTRONG%3E%3A%20Never%20assume%20anything%3C%2FDIV%3E%0A%3CDIV%3E%0A%3CDIV%3E%3CSPAN%3EI%20still%20know%20when%20C%23%20introduced%20Linq%20or%20Lambda%20expressions.%20It%20was%20very%20easy%20to%20refactor%20all%20your%20loops%20to%20use%20this%20new%20way%20of%20writing%20your%20code.%20Instead%20of%2010%20lines%2C%20you%20ended%20up%20with%20two%20lines.%20Incredible%2C%20you%20might%20think%2C%20but%20many%20developers%20did%20not%20even%20know%20what%20was%20happening.%20It%20was%20too%20new%2C%20and%20some%20developers%20were%20using%20tools%20to%20do%20the%20refactoring%20of%20this.%20At%20that%20time%2C%20in%20the%20company%20I%20was%20working%20in%2C%20we%20decided%20to%20educate%20everyone%20before%20refactoring%20all%20the%20code%20to%20use%20it.%20Once%20everyone%20understands%20how%20it%20works%2C%20we%20could%20think%20about%20starting%20to%20use%20it.%3C%2FSPAN%3E%3C%2FDIV%3E%3CBR%20%2F%3E%3CDIV%3E%3CSPAN%3EOnce%20everyone%20understood%20it%2C%20we%20also%20started%20commenting%20when%20we%20refactored%20these%20lines.%20Everyone%20in%20the%20team%20indeed%20understood%20it%2C%20so%20what%20is%20the%20point%3F%20Well%2C%20new%20developers%20are%20joining%20the%20team.%3C%2FSPAN%3E%3C%2FDIV%3E%0A%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%0A%3CDIV%3E%3CSPAN%3E%3CSPAN%3EAnother%20good%20reason%20from%26nbsp%3B%3C%2FSPAN%3E%3C%2FSPAN%3E%3CA%20title%3D%22Link%20to%20the%20tweet%20of%20Wassim%20Chegham%22%20href%3D%22https%3A%2F%2Ftwitter.com%2Fmanekinekko%2Fstatus%2F1365425869909549062%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noreferrer%22%3EWassim%20Chegham%3C%2FA%3E%3C%2FDIV%3E%0A%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%0A%3CDIV%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22comments1.png%22%20style%3D%22width%3A%20586px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F259922iC7641B86A6E6919B%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22comments1.png%22%20alt%3D%22comments1.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FDIV%3E%0A%3CH2%20id%3D%22toc-hId-1965259898%22%20id%3D%22toc-hId-1965259898%22%3EComments%20!%3D%20bad%20code%3C%2FH2%3E%0A%3CDIV%3E%0A%3CDIV%3E%3CSPAN%3EComments%20cannot%20fix%20bad%20code%20or%20bugs.%20This%20statement%20is%20something%20I%20read%20as%20well%20in%20one%20of%20the%20articles.%20I%20agree%20that%20comments%20cannot%20fix%20bad%20code%2C%20but%20what%20is%20the%20reason%20for%20the%20bad%20code%2C%20and%20what%20is%20bad%20code%3F%3C%2FSPAN%3E%3C%2FDIV%3E%3CBR%20%2F%3E%3CDIV%3E%3CSPAN%3EAgain%2C%20it%20assumes%20that%20the%20other%20developer%20has%20the%20same%20skills%20as%20you.%20%3C%2FSPAN%3E%3C%2FDIV%3E%3CBR%20%2F%3E%3CDIV%3E%3CSPAN%3EWhat%20if%20a%20junior%20developer%20in%20your%20team%20wrote%20the%20code%3F%20%3C%2FSPAN%3E%3C%2FDIV%3E%3CBR%20%2F%3E%3CDIV%3E%3CSPAN%3EIf%20there%20were%20comments%2C%20you%20could%20see%20where%20she%2Fhe%20was%20after.%20Show%20the%20person%20how%20to%20write%20the%20particular%20code%20more%20solidly.%20Or%20teach%20them%20why%20you%20think%20this%20is%20bad%20behavior.%20We%20were%20not%20perfect%20the%20first%20time%20when%20we%20were%20writing%20code%2C%20and%20still%2C%20each%20day%2C%20we%20learn%20new%20things%20ourselves.%3C%2FSPAN%3E%3C%2FDIV%3E%0A%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%0A%3CDIV%3E%3CSPAN%3EIt%20might%20even%20be%20so%20that%20the%20comments%20will%20help%20you%20fix%20the%20bug%2C%20but%20the%20comments%20will%20not%20create%20the%20bug.%3C%2FSPAN%3E%26nbsp%3B%3C%2FDIV%3E%0A%3CDIV%3E%0A%3CH2%20id%3D%22toc-hId-157805435%22%20id%3D%22toc-hId-157805435%22%3E%3CSPAN%3EComments%20lead%20to%20more%20productivity%3C%2FSPAN%3E%3C%2FH2%3E%0A%3CDIV%3E%0A%3CDIV%3E%3CSPAN%3EMany%20believe%20that%20comments%20lead%20to%20noise%20in%20the%20codebase%2C%20but%20is%20this%20actually%20true%3F%3C%2FSPAN%3E%3C%2FDIV%3E%3CBR%20%2F%3E%3CDIV%3E%3CSPAN%3EI%20Believe%20that%20having%20comments%20in%20the%20code%20is%20beneficial%20for%20productivity.%20Imagine%20if%20you%20do%20not%20understand%20a%20part%20of%20the%20logic%20or%20why%20functionality%20was%20implemented%20in%20a%20particular%20way.%20%3C%2FSPAN%3E%3C%2FDIV%3E%3CBR%20%2F%3E%3CDIV%3E%3CSPAN%3EHaving%20no%20comments%20or%20references%2C%20you%20might%20need%20to%20go%20through%20the%20whole%20code%20step%20by%20step%20to%20understand%20the%20person's%20thoughts%20and%20implementation.%20Another%20option%20would%20be%20to%20call%20the%20person%20to%20clear%20things%20out%2C%20but%20two%20people%20are%20less%20productive%20during%20that%20call.%3C%2FSPAN%3E%3C%2FDIV%3E%0A%3CDIV%3E%0A%3CH2%20id%3D%22toc-hId--1649649028%22%20id%3D%22toc-hId--1649649028%22%3E%3CSPAN%3EComments%20are%20a%20way%20of%20communication%3C%2FSPAN%3E%3C%2FH2%3E%0A%3CDIV%3E%0A%3CDIV%3E%3CSPAN%3ECommunication%20in%20your%20team%20is%20crucial.%20A%20great%20team%20relies%20on%20good%20communication.%3C%2FSPAN%3E%3C%2FDIV%3E%3CBR%20%2F%3E%3CDIV%3E%3CSPAN%3EComments%20are%20a%20way%20to%20communicate%20to%20other%20developers%20to%20give%20more%20information%20about%20how%20a%20particular%20functionality%20is%20implemented.%3C%2FSPAN%3E%3C%2FDIV%3E%0A%3CH2%20id%3D%22toc-hId-837863805%22%20id%3D%22toc-hId-837863805%22%3E%3CSPAN%3EChallenges%3C%2FSPAN%3E%3C%2FH2%3E%0A%3CDIV%3E%0A%3CDIV%3E%3CSPAN%3EComments%20also%20come%20with%20a%20couple%20of%20challenges%2C%20which%20I%20believe%20are%20a%20way%20of%20working%20or%20guidelines%20in%20your%20team.%3C%2FSPAN%3E%3C%2FDIV%3E%0A%3CH3%20id%3D%22toc-hId-1528425279%22%20id%3D%22toc-hId-1528425279%22%3E%3CSPAN%20style%3D%22font-family%3A%20inherit%3B%22%3EOutdated%20comments%3C%2FSPAN%3E%3C%2FH3%3E%0A%3CDIV%3E%0A%3CDIV%3E%3CSPAN%3EWhat%20do%20you%20do%20when%20you%20implement%20a%20breaking%20change%3F%20Do%20you%20leave%20your%20documentation%20untouched%3F%20%3C%2FSPAN%3E%3C%2FDIV%3E%3CBR%20%2F%3E%3CDIV%3E%3CSPAN%3EYou%20will%20have%20to%20do%20an%20update%20to%20your%20documentation.%20The%20same%20goes%20for%20your%20comments.%20When%20you%20refactor%20code%2C%20you%20will%20have%20to%20update%20the%20comments%20or%20remove%20them%20if%20it%20does%20not%20make%20sense%20anymore.%3C%2FSPAN%3E%3C%2FDIV%3E%3CBR%20%2F%3E%3CDIV%3E%3CSPAN%3EUpdating%20your%20comments%20is%20good%20developer%20behavior.%3C%2FSPAN%3E%3C%2FDIV%3E%0A%3CDIV%3E%0A%3CH3%20id%3D%22toc-hId--279029184%22%20id%3D%22toc-hId--279029184%22%3E%3CSPAN%3EOver-documenting%3C%2FSPAN%3E%3C%2FH3%3E%0A%3CDIV%3E%0A%3CDIV%3E%3CSPAN%3EI%20also%20read%20that%20many%20think%20you%20need%20to%20document%20in%20multiple%20locations%20when%20you%20are%20writing%20comments.%20Comments%20are%20not%20documentation.%3C%2FSPAN%3E%3C%2FDIV%3E%0A%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%0A%3CDIV%3E%0A%3CDIV%3E%3CSTRONG%3EDocumentation%3C%2FSTRONG%3E%3CSPAN%3E%3A%20material%20that%20provides%20official%20information%20or%20evidence%20or%20that%20serves%20as%20a%20record.%3C%2FSPAN%3E%3C%2FDIV%3E%0A%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%0A%3CDIV%3E%0A%3CDIV%3E%3CSPAN%3EComments%20will%20not%20serve%20as%20the%20official%20information%20about%20how%20your%20solution%20works%20or%20how%20you%20can%20use%20it.%3C%2FSPAN%3E%3C%2FDIV%3E%3CBR%20%2F%3E%3CDIV%3E%3CSTRONG%3EComments%3A%3C%2FSTRONG%3E%3CSPAN%3E%26nbsp%3Ban%20explanatory%20note%20in%20a%20book%20or%20other%20written%20text.%3C%2FSPAN%3E%3C%2FDIV%3E%3CBR%20%2F%3E%3COL%3E%0A%3CLI%3E%3CSPAN%3EDo%20not%20write%20comments%20for%20having%20more%20lines%20of%20code.%3C%2FSPAN%3E%3C%2FLI%3E%0A%3CLI%3E%3CSPAN%3EDo%20not%20write%20comments%20to%20document%20your%20code.%3C%2FSPAN%3E%3C%2FLI%3E%0A%3CLI%3E%3CSPAN%3EWrite%20comments%20if%20it%20makes%20sense%20to%20write%20them.%20For%20instance%2C%20to%20prevent%20someone%20else%20from%20writing%20the%20same%20mistake.%3C%2FSPAN%3E%3C%2FLI%3E%0A%3CLI%3E%3CSPAN%3EUse%20them%20to%20explain%20the%20%3C%2FSPAN%3E%3CSPAN%3E%60why%60%3C%2FSPAN%3E%3CSPAN%3E%2C%20not%20the%20%3C%2FSPAN%3E%3CSPAN%3E%60what%60%3C%2FSPAN%3E%3CSPAN%3E.%3C%2FSPAN%3E%3C%2FLI%3E%0A%3C%2FOL%3E%0A%3CH3%20id%3D%22toc-hId--2086483647%22%20id%3D%22toc-hId--2086483647%22%3E%3CSPAN%3EComments%20create%20noise%20in%20your%20code%3C%2FSPAN%3E%3C%2FH3%3E%0A%3C%2FDIV%3E%0A%3C%2FDIV%3E%0A%3C%2FDIV%3E%0A%3C%2FDIV%3E%0A%3C%2FDIV%3E%0A%3CDIV%3E%0A%3CDIV%3E%3CSPAN%3EIn%20my%20opinion%2C%20it%20also%20creates%20structure.%20It%20let%20your%20eyes%20rest.%20Take%20a%20break.%20For%20me%2C%20line%20breaks%20are%20even%20more%20important%20to%20add%20to%20your%20code%20and%20the%20number%20of%20code%20lines.%3C%2FSPAN%3E%3C%2FDIV%3E%3CBR%20%2F%3E%3CDIV%3E%3CSPAN%3EI%20have%20a%20hard%20time%20focusing%20on%20code%20when%20there%20are%20too%20many%20lines%20in%20one%20file%2C%20hardly%20any%20line%20breaks%2C%20and%20no%20comments.%20When%20this%20is%20the%20case%2C%20it%20feels%20like%20I%20am%20on%20a%20boat%20and%20get%20a%20bit%20see%20sick.%20The%20reason%20for%20this%20is%20due%20to%20my%20astigmatism%2C%20also%20the%20reason%20why%20I%20am%20wearing%20glasses.%3C%2FSPAN%3E%3C%2FDIV%3E%3CBR%20%2F%3E%3CDIV%3E%3CSPAN%3EAs%20these%20lines%20of%20code%20might%20feel%20noise%20to%20you%2C%20to%20me%2C%20they%20give%20my%20eyes%20a%20break.%20Let%20me%20focus%20on%20the%20next%20block%20of%20code.%3C%2FSPAN%3E%3C%2FDIV%3E%0A%3CDIV%3E%0A%3CDIV%3E%0A%3CH2%20id%3D%22toc-hId--2096986751%22%20id%3D%22toc-hId--2096986751%22%3E%3CSPAN%3EWhy%20should%20you%20comment%3F%3C%2FSPAN%3E%3C%2FH2%3E%0A%3C%2FDIV%3E%0A%3C%2FDIV%3E%0A%3C%2FDIV%3E%0A%3CDIV%3E%0A%3CDIV%3E%3CSPAN%3EThe%20most%20crucial%20reason%20to%20comment%20is%20for%20yourself%20as%20this%20will%20help%20the%20future%20you%20from%20understanding%20your%20own%20code.%3C%2FSPAN%3E%3C%2FDIV%3E%3CBR%20%2F%3E%3CDIV%3E%3CSPAN%3EThe%20next%20reason%20is%20to%20help%20others%20understand%20you.%20Suppose%20an%20employee%20takes%20over%20a%20project%20from%20you%20or%20enters%20your%20team.%20It%20will%20make%20their%20lives%20easier.%20Or%20when%20you%20do%20a%20handover%20when%20leaving%20the%20company%2C%20the%20person%20sill%20not%20have%20any%20ways%20to%20contact%20you%20anymore.%20Would%20you%20like%20it%20that%20you%20enter%20a%20codebase%20where%20you%20do%20not%20understand%20any%20of%20the%20written%20logic%3F%3C%2FSPAN%3E%3C%2FDIV%3E%0A%3CDIV%3E%0A%3CDIV%3E%0A%3CH2%20id%3D%22toc-hId-390526082%22%20id%3D%22toc-hId-390526082%22%3E%3CSPAN%3ECommenting%20tips%3C%2FSPAN%3E%3C%2FH2%3E%0A%3C%2FDIV%3E%3CSPAN%20style%3D%22font-family%3A%20inherit%3B%20color%3A%20inherit%3B%20font-size%3A%2018px%3B%22%3E%3CSPAN%20style%3D%22font-family%3A%20inherit%3B%20color%3A%20inherit%3B%20font-size%3A%2018px%3B%22%3E%26nbsp%3B%3C%2FSPAN%3E%3C%2FSPAN%3E%3CDIV%3E%0A%3CUL%3E%0A%3CLI%3E%3CSPAN%3EKISS%3A%20Keep%20it%20short%20and%20simple%20-%20you%20do%20not%20need%20to%20write%20a%20book.%3C%2FSPAN%3E%3C%2FLI%3E%0A%3CLI%3E%3CSPAN%3EDo%20not%20comment-out%20lines%20of%20code.%20During%20debugging%2Ftesting%2C%20this%20might%20happen%2C%20but%20make%20sure%20not%20to%20check%20in%20these%20lines.%20This%20behavior%20leads%20to%20code%20smells.%20Be%20sure%20your%20code%20lives%20inside%20source-control.%20That%20way%2C%20you%20do%20not%20have%20to%20worry%20about%20a%20deleted%20line%20of%20code.%20The%20main%20reason%20why%20this%20behavior%20happens%20is%20not%20to%20lose%20that%20one%20precious%20line%20of%20code.%3C%2FSPAN%3E%3C%2FLI%3E%0A%3CLI%3E%3CSPAN%3EWrite%20code%20you%20understand%20so%20that%20you%20do%20not%20always%20need%20to%20comment.%3C%2FSPAN%3E%3C%2FLI%3E%0A%3CLI%3E%3CSPAN%3EExplain%20the%20%3CEM%3Ewhy%3C%2FEM%3E%3C%2FSPAN%3E%3CSPAN%3E%26nbsp%3Bnot%20the%20%3C%2FSPAN%3E%3CSPAN%3E%3CEM%3Ewhat%3C%2FEM%3E%3C%2FSPAN%3E%3CSPAN%3E.%3C%2FSPAN%3E%3CUL%3E%0A%3CLI%3E%3CSPAN%3EIf%20you%20need%20to%20explain%20the%20%3CEM%3Ewhat%3C%2FEM%3E%3C%2FSPAN%3E%3CSPAN%3E%2C%20in%20many%20cases%2C%20it%20is%20too%20difficult%20to%20understand.%20Try%20to%20simplify%2C%20if%20not%20possible%2C%20you%20can%20comment.%20An%20example%20could%20be%20the%20screenshot%20from%20above.%3C%2FSPAN%3E%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3C%2FDIV%3E%0A%3CDIV%3E%0A%3CH2%20id%3D%22toc-hId-256841358%22%20id%3D%22toc-hId-256841358%22%3E%3CSPAN%3EBest%20of%20both%20worlds%3C%2FSPAN%3E%3C%2FH2%3E%0A%3C%2FDIV%3E%0A%3CDIV%3E%0A%3CDIV%3E%3CSPAN%3EThere%20is%20a%20solution%20for%20everything.%20Almost%20everything%20can%20be%20solved%20by%20code.%20If%20you%20are%20a%20person%20that%20does%20not%20like%20to%20see%20comments%2C%20I%20have%20created%20just%20the%20VSCode%20Extension%20for%20you.%20With%20the%20%3C%2FSPAN%3E%3CA%20title%3D%22VSCode%20Hide%20Comments%20Extension%22%20href%3D%22https%3A%2F%2Fmarketplace.visualstudio.com%2Fitems%3FitemName%3Deliostruyf.vscode-hide-comments%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3E%3CSPAN%3EHide%20Comments%3C%2FSPAN%3E%3C%2FA%3E%3CSPAN%3E%26nbsp%3Bextension%2C%20you%20decide%20if%20you%20want%20to%20show%20or%20hide%20the%20comments%20for%20the%20project.%3C%2FSPAN%3E%3C%2FDIV%3E%0A%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%0A%3CDIV%3E%3CSPAN%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22comments2.png%22%20style%3D%22width%3A%20728px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F259926iCD44189CC77EF382%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22comments2.png%22%20alt%3D%22comments2.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FDIV%3E%0A%3C%2FDIV%3E%0A%3C%2FDIV%3E%0A%3C%2FDIV%3E%0A%3C%2FDIV%3E%0A%3C%2FDIV%3E%0A%3C%2FDIV%3E%0A%3C%2FDIV%3E%0A%3C%2FDIV%3E%0A%3C%2FDIV%3E%0A%3C%2FDIV%3E%0A%3C%2FDIV%3E%3C%2FLINGO-BODY%3E%3CLINGO-TEASER%20id%3D%22lingo-teaser-2178622%22%20slang%3D%22en-US%22%3E%3CP%3ELearn%20here%20why%20you%20should%20comment%20code%20and%20which%20benefits%20are%20there%20for%20others%20and%20your%20future-self%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-TEASER%3E%3CLINGO-LABS%20id%3D%22lingo-labs-2178622%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3Ebest-practices%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3Ecomments%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3Edevelopment%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E
Co-Authors
Version history
Last update:
‎Mar 02 2021 09:49 AM
Updated by: