3 ms·
i like static code because a codebase that applies types well gives you the same benefits of writing lots of tests for free.
by parpfish 1y ago
i like static code because a codebase that applies types well gives you the same benefits of writing lots of tests for free.
- cma 1y agoIronically they usually make unit tests and testing by hand in the repl harder
- Spivak 1y agoYep, there is basically nothing else to be said. Using a static type checker isn't some moral imperative or whatever. I simply am able to write better, more correct code faster than without it. And my test suite doesn't have to do things like check the return type of the function because the type checker already knows.
- igouy 1y agoUmmm wouldn't that be check the return value which the type checker doesn't already know?
- 90s_dev 1y agoType systems make 93% of tests obsolete. The other 7% are implied by developing new features and making sure they work as you expect. If nothing broke, you're good to go. Incidentally, it scales with a team. The more people writing code, the more people who will run into some bugs one of you introduced. In my experience, automated tests (unit or e2e) never reduced that number, but only slowed us down. I wonder if TDD & BDD were just an excuse to bill clients for more time while giving them a false sense of security.
- theLiminator 1y agoIronically the strongest advocates of dynamic languages tend to be places where a strong type system would solve a huge percentage of their bugs. Web development is mostly the munging of data together and ensuring that you're glueing stuff together correctly. Static type systems, especially ML based ones would ensure that most of this is done correctly.
- AnimalMuppet 1y ago> Type systems make 93% of tests obsolete. I don't suppose I could trouble you for a source for that number?
- igouy 1y agoThe benefits are not the same. Code can type check but not be correct. There's no free lunch. Some languages require explicit type definitions others don't.
- theLiminator 1y ago> Code can type check but not be correct. Depends on your type system. It can prove the correctness of certain properties depending on your language. Conversely, unit tests can pass but your code might not be correct.
- igouy 1y agoDepends on your type system. Depends on your tests. Depends. Yet another under-specified commentary ;-)
- kibwen 1y agoConversely, code can pass tests and not be correct, including in ways that would have been trivially caught by a type system. If you care about correctness, use both. Codebases written in static languages still use tests.
- deleted 1y ago