• Guttural@jlai.lu
    link
    fedilink
    Français
    arrow-up
    1
    ·
    edit-2
    6 days ago

    As soon as I stopped trying to write textbook OOP stuff, this stopped occurring to me. That was years ago.

    I’m not saying I write perfect code, no. But when I read bad stuff I wrote, I can understand it and think of ideas about how to improve it if that becomes necessary.

    On top of writing more functional-style code, the way I achieved this was:

    • Absolutely no inheritance whatsoever. Composition + interfaces work wonders for what I do.
    • Minimal mutable state. This pays dividends when debugging.
    • Ditto for type-system-encoded nullability markers (ie. ? in C#, std::optional in C++…)
    • I avoid writing code just-in-case something happens. If I haven’t run it manually or via unit tests, it goes to the garbage bin (not an absolute, just a guiding principle). There’s a chance that code isn’t even correct to begin with and you’ll have to throw it away should you ever need it.
    • Low indirection. I don’t want to jump through 10 functions to see what something is doing, and nobody else does either.
  • BillyClark@piefed.social
    link
    fedilink
    English
    arrow-up
    6
    ·
    7 days ago

    This does happen a lot, but have you ever had the opposite happen? Where you go into some of your older code, and not only is it nice to read, but you had anticipated that you’d have to make this change later, and so the design makes the change easy?

    That’s happened to me a few times and all I can say is that it takes days for my self-satisfaction to wane.

    • CanadaPlus@lemmy.sdf.org
      link
      fedilink
      arrow-up
      0
      ·
      6 days ago

      I had this happen recently. Very satisfying.

      I did add some more comments and change names, though, since stuff I thought was obvious at the time wasn’t totally.

    • AdamBomb@lemmy.sdf.org
      link
      fedilink
      English
      arrow-up
      0
      ·
      7 days ago

      Happens more often the better you get at your craft. I used to say that if you don’t hate the code you wrote last year, you’re not improving. Well, let’s just say I finally stopped hating mine.

    • Landless2029@lemmy.world
      link
      fedilink
      arrow-up
      0
      ·
      7 days ago

      This actually happened to me last month. I had to touch code from a previous team/project I was on.

      I got the call for a collaboration/consult. I forgot everything about it. Jumped in a meeting next day anyway. We pulled up the code. Everything was documented and I had a section with parameters for a “wish” feature that they actually wanted finally. I pointed it out and told them the needful to finish the feature.

      Thank you past me. I’ll have to buy you a drink.

      Then I had a nice 5pm Scotch.

    • jjjalljs@ttrpg.network
      link
      fedilink
      arrow-up
      0
      ·
      7 days ago

      I used to be better at math and coding. If I pulled up my old project euler solutions I’m not sure I’d understand them anymore.

  • SaharaMaleikuhm@feddit.org
    link
    fedilink
    arrow-up
    3
    ·
    7 days ago

    I am usually quite pleased with my old code. It ain’t perfect, but it’s doing well for itself. Sometimes there is silly stuff I need to fix, but then I just laugh at myself.

  • darklamer@lemmy.dbzer0.com
    link
    fedilink
    arrow-up
    2
    ·
    7 days ago

    I really don’t understand this meme. As a longtime professional programmer I regularly go back and review code I wrote last month, last year and last decade; in order to find things I did wrong and learn from things I did right. Sometimes I do get the revelation of “oh, how much I’ve learned since then”, but that’s most often very far in the past and seldomly that I’d be ashamed of writing the same code again now, mostly just a welcome realization that I’ve been able to learn and improve since then.