Saturday, December 7, 2019

author photo

Is It Good to Write Comments on Your Code?

Hello there, it’s me again, and I want to drop another one today, and I always make sure that every article is interesting as the other. I was in the office and someone sent me a text on WhatsApp, asking me if it is good to still write comments on his code. Well, I explained to him and I thought of writing about it too.

Okay, most of you might really want to know what I have to say about this, but I’m not going to stress this and as usual, I’m going to make it as short as I can. And yeah, I’m going to drop a little short story.

Maybe not, but for me using comments are fun and great, that was when I was starting and learning, but as time goes and I got used to what I was going, writing comments on my code became stressful for me, this may be because I am lazy, it has been proven by my mother, and yeah that sounded funny, right? But it’s true, my mom proved that I’m lazy.

So the big question is, is it good to write comments or leave comments on your code? There is a Yes and No answer to this, why do I say this? Yes in the sense that, you are learning and you are a beginner so you need to always leave a comment on your code so that you can recall what a function does on your code, knowing you did not write that code by yourself. And you got the code from GitHub or from a tutorial video on YouTube. So yes always leave comments.

But before anyone kills me or hits me, this also applies to people who are good at programming too, you also need to drop comments, for a complex piece of code and not for a for loop or an if statement if you know what I mean. Like you already know that, a for loop can loop from the pages you want to display on a screen and you still leave a comment saying, “this for loop, brings all the pages form the database”, by you looking at it, you will already know what it does because you wrote it and you are now good at it. This also turns down to learning how to write clean and simple code. I have an article about that, well here it is – Reasons You Should Write Simple Code you can read it.

And this is what I have to say for this topic and leave a comment if you have any question, thanks.

Next article Next Post
Previous article Previous Post

This post have 0 comments


Next article Next Post
Previous article Previous Post