by crtc · 5y ago · 0 comments
It's a misconception that developers who use dynamically typed programming languages write tests that perform tasks of a static type system. They do not write tests like this:
assertException(() => upcase(12));
assertException(() => upcase(true));
assertException(() => upcase(null));
assertException(() => upcase(new Object()));
...
They write tests like assertEquals("TEST", upcase("test"));
assertEquals("HELLO, WORLD", upcase("hElLo, wOrLd"));
assertEquals("BLA123", upcase("bla123"));Those tests that you list later are "happy path" tests. We want to know that that works, but we can't rely on only that sort of test especially if the type system doesn't work with us to avoid incorrect inputs to the function.
Honestly if a sad path causes a typing error in elixir it's not the worst thing. Sentry will catch it, only the user thread crashes, and you go patch it later.
Re your second code block: This can be typed with literal types, no need for tests at compile time.