Comment from my group project teammate. You don’t need to comment every line lol

  • RustyNova@lemmy.world
    link
    fedilink
    arrow-up
    0
    ·
    edit-2
    4 months ago

    It’s not that bad. It definitely helps in long functions.

    I’m an advocate for code commenting itself, but sometimes it’s just better to comment on what you’re doing, and in those cases it helps to over commentate.

    Instead of letting the reader interweave code reading and comment reading, I think it’s better to do either. Either you go full self describing code, letting the reader parse it as code,m, or you abstract everything, making it more of an explanation of your reasoning, and abstract lines that may look too complicated.

    Not every comment needs to be useful, but I still write them to not have this switch between reasoning and thinking in code. It can also double as rubber duck debugging too!

    • Darohan@lemmy.zip
      link
      fedilink
      arrow-up
      0
      ·
      4 months ago

      Legit, I’ll take this over the undocumented spaghetti I too often see written by “professionals”.

      • Fal@yiffit.net
        link
        fedilink
        English
        arrow-up
        0
        ·
        4 months ago

        This is so wrong. I would absolutely prefer no comments over incorrect comments, which is exactly what happens when things get over commented

    • henrikx@lemmy.dbzer0.com
      link
      fedilink
      arrow-up
      0
      ·
      edit-2
      4 months ago

      Universities often teach students to write a lot of comments, because you are required to learn and demonstrate your ability to translate between code and natural language. But this is one of the things that are not so straightforward in professional environments.

      Every comment is a line to maintain in addition to the code it describes. And comments like this provide very little (if any) extra information that is not already available from reading the code. It is not uncommon for someone to alter the code that the comment is supposed to describe without changing the comment, resulting in comments that lie about what the code does, forcing you to read the code anyway.

      It’s like if you were bilingual, you don’t write every sentence in both languages, because that is twice as much text to maintain (and read).

      The exception of course, being if you are actually adding information that is not available in the code itself, such as why you did something a particular way.

      • magic_lobster_party@kbin.run
        link
        fedilink
        arrow-up
        0
        ·
        4 months ago

        It’s like if you were bilingual, you don’t write every sentence in both languages, because that is twice as much text to maintain (and read).

        This is a very good analogy. And just like with natural languages, you might have an easier time expressing an idea in one language but not the other. Comments should provide information that you find difficult to express with code.

      • Nevoic@lemm.ee
        link
        fedilink
        arrow-up
        0
        ·
        4 months ago

        Yup this is the real world take IME. Code should be self documenting, really the only exception ever is “why” because code explains how, as you said.

        Now there are sometimes less-than-ideal environments. Like at my last job we were doing Scala development, and that language is expressive enough to allow you to truly have self-documenting code. Python cannot match this, and so you need comments at times (in earlier versions of Python type annotations were specially formatted literal comments, now they’re glorified comments because they look like real annotations but actually do nothing).

        • smeg@feddit.uk
          link
          fedilink
          English
          arrow-up
          0
          ·
          4 months ago

          Exactly! Write your code to be as clear and self-descriptive as possible, and then add a comment if something is still not immediately obvious.

          • Starbuck@lemmy.world
            link
            fedilink
            arrow-up
            0
            ·
            4 months ago

            If I see comments explaining every other line, especially describing “what” instead of “why”, I assume the code was written by a recent grad and is going to be bad. Describing what you are doing looks like you are doing a homework assignment.

            Like on that line, obviously we’re initializing a variable, but why 1 instead of 0? Could be relevant to a loop somewhere else, but I guess I’ll have to figure that out by reading the code anyways.

    • cheddar@programming.dev
      link
      fedilink
      arrow-up
      0
      ·
      edit-2
      4 months ago

      If there are too many comments, it means you have to support them just like the code itself. Otherwise, like any other documentation, comments will quickly go out of sync.

    • Doc Avid Mornington@midwest.social
      link
      fedilink
      English
      arrow-up
      0
      ·
      4 months ago

      It’s better to have useful comments. Long odds are that somebody who writes comments like this absolutely isn’t writing useful comments as well - in fact, I’m pretty sure I’ve never seen it happen. Comments like this increase cognitive overhead when reading code. Sure, I’d be happy to accept ten BS useless comments in exchange for also getting one good one, but that’s not the tradeoff in reality - it’s always six hundred garbage lines of comment in exchange for nothing at all. This kind of commenting usually isn’t the dev’s fault, though - somebody has told a junior dev that they need to comment thoroughly, without any real guidelines, and they’re just trying not to get fired or whatever.

  • Fades@lemmy.world
    link
    fedilink
    arrow-up
    0
    ·
    4 months ago

    Reminds me of every fuckin PR I do for the Indian contractors that were sold to us as “senior devs” but write code like a junior and you better believe every other line has the most obvious fucking comment possible

    • Shirasho@lemmings.world
      link
      fedilink
      arrow-up
      0
      ·
      4 months ago

      Better than writing beginner level crap that is at the same time super cryptic and not documenting at all. We have a bunch of that in our codebase and it makes me wonder why these devs are writing extension methods for functionality already built into the standard libraries.

    • Shirasho@lemmings.world
      link
      fedilink
      arrow-up
      0
      ·
      4 months ago

      Better than writing beginner level crap that is at the same time super cryptic and not documenting at all. We have a bunch of that in our codebase and it makes me wonder why these devs are writing extension methods for functionality already built into the standard libraries.

  • Tarogar@feddit.de
    link
    fedilink
    arrow-up
    0
    ·
    4 months ago

    There is usually no such thing as too many comments. There is a point to keep them to the point though

      • Tarogar@feddit.de
        link
        fedilink
        arrow-up
        0
        ·
        4 months ago

        You know, you do you in Humor communities. I personally don’t expect to find the most serious of comments under posts in those.

        Anyhow…Naturally there is a good argument to be made about making good comments. And that it may be a good idea to not comment things that are probably obvious. Just so that the file is a shorter read.

      • sping@lemmy.sdf.org
        link
        fedilink
        English
        arrow-up
        0
        ·
        4 months ago

        Well on Reddit, programmerhumor was mostly populated by people weirdly proud of how bad they are at their job, so I don’t see how Lemmy was going to be different.

        • Tarogar@feddit.de
          link
          fedilink
          arrow-up
          0
          ·
          4 months ago

          Not to mention the fact that it’s programmer Humor. Not programming advice. which means that there are usually less serious comments to be found that may or may not be good advice. But I suppose some people have no sense of humour.

  • Cratermaker@discuss.tchncs.de
    link
    fedilink
    arrow-up
    0
    ·
    4 months ago

    Software devs in general seem to have a hard time with balance. No comments or too many comments. Not enough abstraction or too much, overly rigid or loose coding standards, overoptimizing or underoptimizing. To be fair it is difficult to get there.

  • fibojoly@sh.itjust.works
    link
    fedilink
    arrow-up
    0
    ·
    4 months ago

    More useful would be what sort of values is acceptable there. Can I use team number 2318008? Can I use team 0? If not, why not? WHY / WHY NOT is often useful.

    • rbits@lemm.eeOP
      link
      fedilink
      arrow-up
      0
      ·
      edit-2
      4 months ago

      Lol that’s exactly what this was. I wrote this python script, and he went through and added comments like this a day before the deadline.

      Not trying to throw shade on him though, it’s more the university’s fault for not explaining what makes a useful comment. I just thought it was funny

  • u/lukmly013 💾 (lemmy.sdf.org)@lemmy.sdf.org
    link
    fedilink
    English
    arrow-up
    0
    ·
    4 months ago

    I am not a programmer, I just barely wrote one bash script in the past. But I’d say more comments are better than too few.

    When I later wanted to edit it, I got completely lost. I wrote it with absolutely no comments.

    • riodoro1@lemmy.world
      link
      fedilink
      arrow-up
      0
      ·
      4 months ago

      Bash is a shit „language” and everytime i need to write the simplest thing in it I forget which variable expansion I should use and how many spaces are the right amount of spaces. It’s impossible to write nice to read bash, but even in C you can write code that comments itself.

    • floofloof@lemmy.ca
      link
      fedilink
      English
      arrow-up
      0
      ·
      4 months ago

      I’ve been programming for almost 25 years and I’d still rather see too many comments than too few. A dogmatic obsession with avoiding comments screams “noob” just as much as crummy “add 1 to x” comments. If something is complex or non-obvious I want a note explaining why it’s there and what it’s supposed to do. This can make all the difference when you’re reviewing code that doesn’t actually do what the comment says it should.

    • Fades@lemmy.world
      link
      fedilink
      arrow-up
      0
      ·
      4 months ago

      Wrong. Too many comments makes the code messy and less readable and also it provides ZERO value. Just look at the post, WHAT is useful about ANY of that comment???

      All it is is a waste of goddamn space, literal junk crowding the actual code.

      • LwL@lemmy.world
        link
        fedilink
        arrow-up
        0
        ·
        4 months ago

        Too many is still better than too few, and it’s not close. Useless comments make parsing a bit harder. Missing comments can mean hours of research.

        • sping@lemmy.sdf.org
          link
          fedilink
          English
          arrow-up
          0
          ·
          edit-2
          4 months ago

          These are arguments talking past each other. Sure 1 useful comment and 9 redundant ones can be better than zero, but comments are not reliable and often get overlooked in code changes and become misleading, sometimes critically misleading. So often the choice is between not enough comments versus many comments that you cannot trust and will sometimes tell you flat-out lies and overall just add to the difficulty of reading the code.

          There’s no virtue in the number of comments, high or low. The virtue is in the presence of quality comments. If we try to argue about how many there should be we can talk past each other forever.

  • r00ty@kbin.life
    link
    fedilink
    arrow-up
    0
    ·
    4 months ago

    When people read my code, they usually say they like that I comment so much, it makes it easier to understand what’s happening.

    I say, I comment so much because my memory is terrible. It’s for me!

    • sping@lemmy.sdf.org
      link
      fedilink
      English
      arrow-up
      0
      ·
      4 months ago

      I’ve worked in a few startups, and it always annoys me when people say they don’t have time to do it right. You don’t have time not to do it right - code structure and clarity is needed even as a solo dev, as you say, for future you. Barfing out code on the basis of “it works, so ship it” you’ll be tied up in your own spaghetti in a few months. Hence the traditional clean-sheet rewrite that comes along after 18-24 months that really brings progress to its knees.

      Ironically I just left the startup world for a larger more established company and the code is some of the worst I’ve seen in a decade. e.g. core interface definitions without even have a sentence explaining the purpose of required functions. Think “you’re required to provide a function called “performControl()”, but to work out its responsibilities you’re going to have to reverse-engineer the codebase”. Worst of all this unprofessional crap is part of that ground-up 2nd attempt rewrite.

      • r00ty@kbin.life
        link
        fedilink
        arrow-up
        0
        ·
        4 months ago

        Ironically I just left the startup world for a larger more established company and the code is some of the worst I’ve seen in a decade. e.g. core interface definitions without even have a sentence explaining the purpose of required functions. Think “you’re required to provide a function called “performControl()”, but to work out its responsibilities you’re going to have to reverse-engineer the codebase”. Worst of all this unprofessional crap is part of that ground-up 2nd attempt rewrite.

        I think this is actually quite common in commercial code. At least, for most of the code I’ve seen. Which is why I laugh most of the time when people imply commercial code is better than most open source code. It’s not, you just cannot see it.