Here’s a tutorial I wrote on using components to help keep your code organized.

    • TheLongPrice@lemmy.oneOP
      link
      fedilink
      arrow-up
      0
      ·
      20 days ago

      Thank you! I just started on a new project and it felt nice to remind myself what worked well in the previous one.

  • mrsgreenpotato@discuss.tchncs.de
    link
    fedilink
    arrow-up
    0
    ·
    edit-2
    18 days ago

    Why are people still using string references? Like in the case of “Bumpable” - this could be a class name and reference could be via the class name instead of checking the node name by string. String references are super dangerous, as you will get a potential error only at runtime if you make a typo, IDE can’t help you. Don’t get me wrong - I like the idea behind component pattern and I use it myself sometimes, but the execution could be better in my opinion, unless I’m missing some obvious reasons for doing it this way.

      • mrsgreenpotato@discuss.tchncs.de
        link
        fedilink
        arrow-up
        0
        ·
        18 days ago

        Correct, I’d also use exported values if possible. But that isn’t flexible enough in some cases, because you’d need to individually export all possible attributes that the node might have.

        For it to be more flexible, you could have something like this:

        for child in get_children():
          if child is ClassNameHere:
            return child
        

        That would give you the same result as described in the article, without string reference. You could make a static func for it and call it a day :)

    • TheLongPrice@lemmy.oneOP
      link
      fedilink
      arrow-up
      0
      ·
      13 days ago

      That would definitely be an improvement, using classes is probably more robust. In my case, the project wasn’t too huge and it was solo, so I never hit issues with string references.