1

I have a habit to comment every single line of code, this helps comprehension but this dirty the code and everyone complain. Is it any way to do such task.

Comments
  • 0
    I have to ask: every line? how does that help with comprehension?

    //what could explain this better?
    x = y+2;

    some code is self documenting. I find the best way to comment is split lines into 5-10 line chunks using. blank lines to separate. comment these. but only if they all achieve the same thing on a big scale.
  • 1
    If you need comments to make your code readable, you should reconsider your approach to programming
  • 0
    @McChicken I disagree. there are times when comments are most definitely needed be cause there are times when unclear code is definitely needed. examples:

    - it's clear what the code is doing. but why?
    - there's a magic number that can't be removed. you should explain what it means and why that number.
    - the code is super speed important (medical/self driving cars) and when it's clarity vs speed, always pick speed! people die otherwise. explain how it works in comments.
    -quake inverse square root. sometimes code is just awesome and works well. even if nobody really knows how it works.
  • 1
    @deadPix3l Don't know what language you're using but if you're sticking to the single responsibility principle, structure your code well, documenting methods with summaries or(something like JS docs) is more than enough.

    Comment for few complex lines is maybe okay but every line is 100% unnecessary and a code smell.
  • 0
    Well. It is not my code. Other ppl code. The point is to increase understanding level to 110 percent. Make the code your code. I cannot control how ppl build code, but u can control how I do it. Why is important to reach 110 percent understanding. You are able to memorize the code, change fast, creative.
  • 1
    @DanijelH oh I agree entirely! comments should be rare and vital if they exist at all. I was just saying that a "comments shouldn't exist, rewrite the code to explain" doesn't always work. granted, usually it does, I agree. but at least for medical/commercial flight controller/critical life supporting code. I would rather have fast, reliable code with magic numbers and comments that explains, rather than a well structured, easily understood and slow method. not much room for lag when designing pacemakers.

    that said. this should only apply to C/asm. all other languages are too slow you shouldn't be using them for said purpose anyways.
Add Comment