• @[email protected]
      link
      fedilink
      English
      17 months ago

      If your company uses some sort of code checking tool on PRs, there may be a requirement that all functions have a docstring, even if it’s obvious what it’s doing. Leads to silly comments like this quite often

  • @[email protected]
    link
    fedilink
    37 months ago

    Commenting code is a super important habit to get into—it not only helps others understand your thought process but also makes it easier for you to pick up where you left off if you revisit the code later. Plus, well-commented code can significantly reduce the onboarding time for new developers on a project. Remember, comments should explain the “why” behind the code, not just the “what.” For instance, stating why you chose a particular algorithm or data structure can be far more helpful than just labeling it. According to a study by SmartBear, 44% of developers regard poorly documented code as a top cause of project delays, so it’s definitely worth the extra effort!

    • @[email protected]
      link
      fedilink
      Deutsch
      27 months ago

      But it’s also important to learn that comments should be brief and concise. We have one file from an ex-dev in which there are 750 lines of code and 2000 lines of comment, when someone wants to maintain this code they always have a hard time because this many comments are taking up so much screen real estate that you can’t find the code that actually does stuff

    • Fonzie!
      link
      fedilink
      8
      edit-2
      7 months ago

      Okay now I get the joke.
      I hate these kind of people.

      By the way, your ``` both need to be on their own, separate line

        • Fonzie!
          link
          fedilink
          2
          edit-2
          7 months ago

          It renders correctly on the web as well for me.

          But the ``` being on their own line is how to write it properly, as stated this website among many others.

          This way, you can put the intended programming language on the same line as the first ```, ensuring proper colour coding!

          Ex.

          echo "Hello $name\n";
          
          echo "Hello $name\n";
          

          EDIT I checked on mobile, it rendered odd on Jerboa for me:

          Screenshot of essteeyou@lemmy.world their comment in the Jerboa client before the edit

          Now it is fixed:

          Screenshot of essteeyou@lemmy.world their comment in the Jerboa client after the edit

  • JoYo
    link
    fedilink
    English
    37 months ago

    someone else’s code would have the wrong values.

  • @[email protected]
    link
    fedilink
    English
    127 months ago

    I know some folks are joking about and dunking on this, but in modern times, I have justification. Call me lazy, but I have found myself writing out these comments and then letting the AI take over to at least give me a sketch of an implementation. Works reasonably well and saves me a lot of time and effort. Mostly I don’t bother to remove them, though I usually edit them a bit.

    On the other hand, there are factions within my colleagues who steadfastly insist that commenting is unnecessary and to some degree even potentially harmful, and that if you feel the need to comment your code, it means your code should be improved so that it’s obvious what it is doing without the need for comments.

    • @[email protected]
      link
      fedilink
      137 months ago

      And your colleagues are probably correct with respect to this sort of «what it does» commenting. That can be counterproductive because if the code changes and the comment isn’t updated accordingly, it can be ambiguous. Better have the code be the singular source of truth. However, «why it does it» comments are another story and usually accepted by most as helpful.

      • @[email protected]
        link
        fedilink
        5
        edit-2
        7 months ago

        I’ll add that you should have a comment anytime you are using some sort of algorithm to explain what it is and the expected result when it’s not intuitive or a complex math operation that isn’t immediately clear. Ex// I’m using Newton’s Method to approximate a solution to speed up the inverse square root

      • @[email protected]
        link
        fedilink
        English
        8
        edit-2
        7 months ago

        if the code changes and the comment isn’t updated accordingly, it can be ambiguous.

        People always cite this as a reason comments are bad. In 30+ years as a developer I have seen (and participated in) a lot of failed software projects, but not once has a mismatch between comments and code been the actual cause of the failure. Moreover, the same logic could be applied to the names of methods and variables (“if the code changes and the method and variable names aren’t updated accordingly, it can be ambiguous”) but nobody ever suggests getting rid of that. At the end of the day, comments are useful for imparting information about the code to future developers (or yourself) that is too complicated to be adequately communicated by a method name.

        • @[email protected]
          link
          fedilink
          67 months ago

          I didn’t say the source of failure. I said a source of ambiguity. And having also been in the industry for decades, I have encountered it many times, where a junior programmer or somebody new to a project read some documentation and assumed a behavior which in fact did not match the current implementation. So you may have been fortunate, but your experience is certainly not ubiquitous.

          With respect to variable names, I’d suggest those too should absolutely be updated too if the name is given in a way that adds ambiguity.

          I’m not saying comments are bad; rather that bad comments are bad, and sometimes worse than no comment.

    • @[email protected]
      link
      fedilink
      4
      edit-2
      7 months ago

      At least docblocking a summary above every method is always good. You can automatically generate documentation this way.

    • YonderEpochs
      link
      fedilink
      57 months ago

      Would you mind sharing a bit more about the workflow you’re describing? I’m on a “ask people how they’re using AI to help them dev” kick.

      Sounds like you’re using an agent integrated with your IDE, would you be willing to give specifics? And you’re talking about writing some comments that describe some code you haven’t yet written, letting the AI take a stab at writing the code based on your comments, and then working from there? Did I get that right?

      Happy for literally any elaboration you feel like giving :)

      • @[email protected]
        link
        fedilink
        English
        3
        edit-2
        7 months ago

        I use VS Code and GitHub Co-pilot and develop in a variety of different languages and frameworks. I’ve got lots of experience with some, but I’m less knowledgeable on others.

        So, having the AI assist with languages I am very familiar with is basically a way to save time and preserve my mental energy. For languages and frameworks I’m less experienced with, it speeds things up because I’m not having to constantly search how-tos and forums for guidance. And for languages/frameworks I have limited or no experience with, it can be a helpful learning tool that speeds up how long it takes to get ramped up.

        With this set-up, if I start writing a line of code and then pause for a moment, co-pilot kicks in and tries to autocomplete that line, sometimes even suggests the entire block of code. It’s really good at recognizing simple patterns and common boilerplate stuff. It’s less good at figuring out more complex stuff, though.

        However, I find that if I start out by writing a comment that explains what I’m trying to accomplish, and to some degree how to accomplish it before I start writing one of those more complex blocks/lines, the AI has a much higher success rate in returning helpful, functioning code. So, basically yes, I write the comment to describe code I haven’t written, and I’ll let the AI take over from there.

        This works for code, raw database queries, configuration files, and even for writing tests. I’m not an expert at building out Docker configurations for local development or configuring auto-deployment on whatever random system is being used for a project, but I can often get those things up and running just by describing in comments what I need and what I’m trying to accomplish.

        The VS Code co-pilot extension also has some context menu items that let you ask questions and/or ask for suggestions, which comes in handy for some things, but for me, typing out my intentions in comments and then letting the auto-complete kick in as I’m starting a line of code is faster, more efficient, and seems to work better.

        Granted, co-pilot also likes to try to auto-complete comments, so that’s sometimes funny just to read what it “thinks” I’m trying to do. And most of the time, I do remove my comments that were specifically to guide co-pilot on what I wanted it to do if they’re super redundant. And, at the end of the day, not everything co-pilot suggests is production-worthy, functional, nor does what I actually described. In fact, a lot of it is not, so you should expect to go back and fine tune things at a minimum. It’s just that overall, it’s good enough that even with all the supervision and revisions I have to make, it’s still a net positive, for now.

        • YonderEpochs
          link
          fedilink
          17 months ago

          Awesome, thank you! This largely matches my own experience, I’ve found it (Claude in my case) most useful in areas where I’m weakest. I haven’t tried this scaffolding-via-comments approach though, it sounds cool.

          Any experience with Cursor or other IDEs or agents? Was co-pilot a choice or just kinda a natural default?

  • Sparky
    link
    fedilink
    52
    edit-2
    7 months ago

    Hey thanks for reminding me I made a clock squared in blender about 2 years ago

    yes there is an error in the image, and no I’m not telling you where it is

    • @[email protected]
      link
      fedilink
      2
      edit-2
      7 months ago

      What a fun idea!

      Is it on purpose that all clocks in this are coupled at the 3 o’clock position? I assume all the clocks go the same speed. Then the large clock and all the smaller clocks at the 3 o’clock position (there are 13 of them) would show the same time. E.g. in one hour, the 12 o’clock position would show 1 o’clock, but the large clock and all the clocks on the 3 o’clock position would show 4 o’clock.

      Oh and why is it a clock squared if you have three layers of clocks? Isn’t it cubed then?

      • Sparky
        link
        fedilink
        17 months ago

        I was mainly thinking of making some recursion hence why all the subclocks mirror the parent clock (for that given hour). Also I called it clock squared because I didn’t think the resolution would be high enough for people to actually notice the 3rd level of clocks.

        You might notice that some dials don’t really align with the hours they’re supposed to show. That’s because I had to place a bunch of clocks at varying hours with a viewport rendering the parent clock at an angle that probably made it difficult to spot the errors. I rendered it once and didn’t bother re-rendering it once I saw the errors :)

        • @[email protected]
          link
          fedilink
          17 months ago

          Haha yes, recursion is always fun!

          Although I’m still confused on what the clock would show in an hour. Because if the subclocks mirror the parent clock at the given time, then they would all be stuck to the hour they are positioned on? Or if they can move then the sublcocks are coupled to 3 o’clock of the main clock. But well, it is all hypothetical anyways :D

          • Sparky
            link
            fedilink
            27 months ago

            Idk maybe the sub clocks are static and never change :3

    • @[email protected]
      link
      fedilink
      57 months ago

      An interesting concept would be if all hand on the 12 clocks would work, but the hands of the clock in the middle are stuck at 12 position, this way the hands in the middle would point to the clock showing the correct time.

    • @[email protected]
      link
      fedilink
      17
      edit-2
      7 months ago

      //forgive my sins, it took me 2 hours to nail down this arcane spell. if anyone touches this they will know my wrath
      =(/&)((//((%=)(&)%)(&()

        • @[email protected]
          link
          fedilink
          English
          67 months ago

          Or breaks a year later and your have to figure out what the fuck you made. The worst thing in the world is when you leave it for the next guy, and you end up being the next guy.

  • @[email protected]
    link
    fedilink
    87 months ago

    basically how it feel when a professor requires u comment every single line of code u write to explain it. I know people tend to drop out of real engineering to do programing but an entire 4 years of this bullshit as opposed to just a couple classes sounds way worse than calc 3 or differential equations.

    • @[email protected]
      link
      fedilink
      English
      1
      edit-2
      7 months ago

      The only problem with courses like calc 3 and differential equations (in my experience, as a mathematician) is that they are cheating somewhat. By cheating I mean relying on inadequate, flawed or entirely omitted proofs. How can the students truly understand something if they are not presented the whole story (or at least reference)?

      The good thing about these courses are that there are usually no shortage of relevant exercises!

      • @[email protected]
        link
        fedilink
        17 months ago

        u could be right calc 3 was alright, pretty fun actually but differential equations i still dont get at all, maybe i should try learn it on my own now with more time and no pressure.

        • @[email protected]
          link
          fedilink
          English
          17 months ago

          I detested differential equations. However, that was more due to how it was presented than the underlying, surprisingly, beautiful math.

  • Russ O
    link
    fedilink
    17 months ago

    @Vordimous @linuxgal when I see this sort of thing when reviewing PRs, I write words to the effect of “tell me WHY it’s doing that, not WHAT it’s doing”. The “what” is usually obvious from the code and thus not worthy of comment. The “why” will enlighten your colleagues (and future you).

  • @[email protected]
    link
    fedilink
    27 months ago

    It should have the numbers change in the middle like a digital clock but look like the numbers on a clock.