Hacker News new | ask | show | jobs
by AlchemistCamp 1008 days ago
Unless you've worked with Clojure or another immutable, dynamically-typed language with pattern matching, you probably don't have a good mental model for what this would look like. It's a completely different story from a language like Python or JavaScript.

Immutability and pattern-matching get you at least the 80-20 of what a rigid type system does for larger code bases, and your team won't have to be as large when you're using a language like Elixir or Clojure as it would with older, more entrenched languages.

1 comments

I feel like a common refactor in a large project might be a complete redefinition of a model layer exposed via a bunch of structs.

How does immutability or patter matching save me from runtime errors caused by changing the fields or types inside a struct? Wouldn’t the pattern matching just fail and go down the wrong code path since it was matching for the old pattern?

I feel like immutability is great, pattern matching is great, but static typing is also great and there is no reason why it can’t happily live along side the other two.

In this case, the question is moot.

Elixir structs have compile-time checks: https://elixir-lang.org/getting-started/structs.html