Baby unit tests - eviltoast
  • Kissaki@programming.dev
    link
    fedilink
    English
    arrow-up
    4
    ·
    edit-2
    1 day ago

    Seems like a Ruby issue and suggested improvement? Using keyword arguments does feel like introducing a type of typing.

    In C# I use records for simple, naturally behaving types, I can define explicit and implicit cast operators, so I have to choice between requiring explicit casts or not (because they make sense to require or are not necessary). I can use var to define a variable without specifying a type, and it is deducted from what it gets assigned - but is still that specific type and gives me type safety.

    In Rust, as far as I understand anyway, traits define shared behavior. In Go interface implementations are implicit rather than explicit. With these, there’s even less of a need of elaborate explicit typing like the post argues/gives an example of.


    In general, I’ve never had considerable effort or annoyance implementing or using typing. And I know what it’s good for; explicitness, and in consequence, predictability, certainty, increased maintainability, and reduced issues and confusions. If following references or refactoring becomes unpredictable or high effort, it’d be quite annoying.

    When I’m coding JavaScript adding JSDoc so the typing information gets passed along is quite cumbersome. Without it, the IDE does not give intellisense/auto-completion or argument type matching. JavaScript is better with it, I consider it worth it with IDE support, but it is quite cumbersome. (I try to evade TypeScript compiler/tooling overhead.)

    A programming language can offer extensive auto-deduction while using strong typing. With appropriate conversions in place, it will only report conflicts and where it was intended to.


    I’m thinking of where I enjoyed dynamic natures, which I certainly have. But I don’t think that’s a matter of typing. It’s a matter of programming language interfacing to typing. If in PHP or JS I make a change, hit F5, and get an error, that’s not any better than the IDE already showing it beforehand. And for the most part, I can program the same way with or without typing.

    Man, this became a long text.

    • Ephera@lemmy.ml
      link
      fedilink
      arrow-up
      2
      ·
      6 hours ago

      In Rust, as far as I understand anyway, traits define shared behavior.

      They’re certainly the concept closest to e.g. C#/Java interfaces. But you can also define shared behaviour with enums, as Rust’s enums are on steroids.

      Basically, let’s say you’ve got two existing types TypeA and TypeB for which you want to define shared behaviour.

      Then you can define an enum like so:

      enum SharedBehaviour {
          A(TypeA),
          B(TypeB),
      }
      

      And then you can define the shared behavior with an impl block on the enum:

      impl SharedBehaviour {
          pub fn greet(&self) {
              match self {
                  SharedBehaviour::A(type_a) => println!("Hi there, {}!", type_a.name),
                  SharedBehaviour::B(type_b) => println!("Hello, {}!", type_b.metadata.forename),
              }
          }
      }
      

      On the flipside, Rust doesn’t have superclasses/inheritance for defining shared behaviour.

    • TehPers@beehaw.org
      link
      fedilink
      English
      arrow-up
      3
      ·
      18 hours ago

      If in PHP or JS I make a change, hit F5, and get an error, that’s not any better than the IDE already showing it beforehand.

      This is even worse because it can happen in prod without you ever triggering this case. For some projects, it doesn’t matter because the impact of a bug is small. For most, you put a subpar, buggy experience in front of your users, waste more time looking for the cause and debugging later with upset users, and at worst cause actual damages (depending on the project anyway).