Hacker News new | ask | show | jobs
by nickjj 2547 days ago
I've never used a proper statically typed language for web development but with Elixir can't you solve the 90% with pattern matching and guards?

For example (taken from the docs on guards):

    def foo(term) when is_integer(term), do: term
    def foo(term) when is_float(term), do: round(term)
If you tried to pass a string into foo at run time, no function pattern would be matched and it would blow up. The above should also give IDEs a way to potentially say "hey, when you call foo, it accepts a term and expects an int or float", and it's also very human readable to figure out what you need to provide as arguments without IDE support.

What's interesting about guards is you can also put expressions in there. Like `when foo > 3` and now suddenly you have a new type of integer that only accepts integers greater than 3, except it's not an explicit IntegerGT3 type you have defined somewhere.

In practice, how much worse is that vs a "real" statically typed language, other than putting guards on things is optional?