• RaphaelSchmitz@feddit.org
        link
        fedilink
        arrow-up
        11
        ·
        1 day ago

        Not a problem, ignore the edgelording, you’ll be fine.

        A lot of people don’t understand that readability is about how fast someone can correctly understand that whole class/file/etc afterwards. Sometimes using enums improves that, sometimes not.

        For enums specifically, it is good to be aware what you do with them. Often it directly maps to a decision. E.g. enum ExportType with values JSON/XML/CSV - instead of passing an enum value to a big function with 3 different paths, you could have 3 classes that have a common interface, and pass one of those to the function to use. That is nicer sometimes, other times not.

        Another thing is that enums are often used to have a small INT DB column, which is not supposed to represent a number (like for math and stuff) but different options. In that case, yeah enum is perfect to describe in code what those numbers actually mean.

        But yeah, it all comes down to: After you write it, look at your code and see if it makes sense quickly - if not, adjust.

      • ZILtoid1991@lemmy.worldOP
        link
        fedilink
        arrow-up
        10
        ·
        1 day ago

        Enums in Rust are spicier unions, and Rust boosters like to paint it as the perfect way to do it, because it’s the best language ever, with no faults. If you disagree, they’ll try to frame you as a Lunduke fan and a bigot.

        • RustyNova@lemmy.world
          link
          fedilink
          arrow-up
          6
          ·
          1 day ago

          Never said that. In fact, enums have lots of issues that can add a lot of boilerplate code.

          But actually having data associated with the type system instead of just a flag is a lot more powerful and less prone to errors than classic enums

          You can also put functions on this union type that allows easy abstraction of what state the union is in

        • Johanno@feddit.org
          link
          fedilink
          arrow-up
          1
          ·
          1 day ago

          Iffind rust interesting but I don’t use it enough to know anything deep about it.

          All I know is that I am not made for c++.

          Hell I can’t keep track of pointers and scopes. And who the hell made templates?

          • ZILtoid1991@lemmy.worldOP
            link
            fedilink
            arrow-up
            1
            ·
            1 day ago

            Templates outside of D are a mess, and the reason why metaprogramming has a bad name. Templates inside D are easy to use, and its attempt at it is something more language should copy.