I rather write garage code than using slop

  • Buddahriffic@lemmy.world
    link
    fedilink
    arrow-up
    1
    ·
    2 hours ago

    Somehow I got into an efficiency/performance focused mindset pretty early on, so I appreciated the algorithm analysis when I got to it (though I thought then and still do think that big O notation simplifies it a bit too much… Those dropped terms can be just as or even more significant as the final term when it comes to typical data sets, but it’s still useful in understanding how an algorithm scales).

    And I’d say that just going over the existing data structures and understanding their strengths and weaknesses can help just by being aware something exists. Like if all you know are arrays and linked lists, you’ll probably struggle a bit to handle key/value pairs. And then, once you learn about them, you might use them for everything and then wonder why your code runs so slowly.

    And the main reason why I’d like more people to be aware of how to be good programmers is that there seems to be a lot of people that just go from “something I’m doing as a hobby” to “something I’m doing for money” or “a large hobby project that has been picked up by the community”. And software quality has been dropping at a similar rate to how much hardware is improving.

    But you’re right that, without the greater context, a lot of it can be confusing and can beg the question of “why do I need this?”

    • starelfsc2@sh.itjust.works
      link
      fedilink
      arrow-up
      3
      ·
      edit-2
      1 hour ago

      Yeah just for me personally I also really liked making things as efficient as possible, but I thought data structures and algorithms were lame because I had zero context around it.

      Maybe that’s just how it’s taught though, because there are really cool examples of what data structures to use and why. For instance if you have npcs with attacks that all have different cooldowns, and a central system that applies the attacks, what’s the best way to store it? A min tree is O(log n) on insertion, so that seems best, but what if it’s very likely an attack is invalidated and you need to remove it before it triggers? Lots of interesting concepts to consider there, instead of just “this does x and has y properties, so it’s good in this use case.”

      • Buddahriffic@lemmy.world
        link
        fedilink
        arrow-up
        1
        ·
        56 minutes ago

        Oh yeah, and that’s where I think that knowledge comes in handy because they don’t just say “here’s a list of structures to use and the rules of when to use them” but they give you tools for evaluating how good various ideas are for handling that problem. It boils down to pretty much counting the CPU operations (which IMO is obvious, if tedious-seeming) and then goes through examples of how to do this to show that the math isn’t actually that overwhelming.

        Also it helps seeing equivalence between problems. Like your example is pretty much equivalent to scheduling threads on shared CPU resources with different priorities, especially if there’s a shared global cooldown between all those skills so they don’t just fire off when ready. They are a bit different but they might be close enough for a similar solution to work. So research can include CPU schedulers. Though on the other hand, something running at a game time resolution is trivial compared to the OS that needs to determine this as quick as possible so it can switch to the next thread (which is also an important consideration because it might not be worth optimizing this part at all vs say the order you process the data in each frame, though this isn’t a lesson from algorithms or data structure class but more general “how to optimise usefully” advice).