Fork me on GitHub
#off-topic
<
2020-04-17
>
David Pham19:04:39

Some says a class of errors disappear with static typing. (Which are they?) Can static typing also introduce errors?

Jivago Alves19:04:53

Some languages won’t allow a NPE to happen just because they force you to handle all possible cases. This is just an example. You can have errors on your logic and that’s what tests are for in those languages. Depending on how rich is the type system, you can make illegal states impossible. In other words, code won’t even compile. https://fsharpforfunandprofit.com/posts/designing-with-types-making-illegal-states-unrepresentable/

phronmophobic19:04:29

hope this doesn’t come off as trite, but static typing mostly prevents type errors at runtime. static typing shouldn’t introduce errors, but it is often more verbose and may require you to change perfectly valid code to appease the type checker. changing your code to appease the type checker may introduce errors or overcomplicate solutions. another point to make is that when someone says “static typing”, they often mean “static analysis” which can prevent other classes of bugs besides type errors.

Jivago Alves19:04:05

> it is often more verbose I’d argue it depends on the type inference of the language. For instance, Haskell vs Java.

hindol19:04:51

Rust with its borrow checker makes race conditions go away. Not related to type system, but compiler can become quite powerful and catch a lot of errors. But arguably the "fun" of coding goes out the window as half the time you just try to make the compiler happy.

phronmophobic19:04:20

i would say static analysis rather than compiler (although the two are usually bundled together(but not necessarily)

phronmophobic19:04:04

linters are an example of static analyzers that can catch many kinds of errors before runtime , but do not compile anything

seancorfield19:04:12

Although a static type system won't "introduce errors", it can make certain programs illegal that would otherwise run correctly.

dpsutton01:04:17

Making sweeping changes to a large codebase to data structures is way easier in a statically typed language. Having a compiler walk you through all the affected areas is quite nice

slipset07:04:49

Hillel Wayne recently wrote about this in his newsletter, but I can’t find a link to it right now. But he was referring to this post https://fsharpforfunandprofit.com/posts/designing-with-types-making-illegal-states-unrepresentable/

slipset07:04:57

Kris Jenkins has a talk https://www.youtube.com/watch?v=NLcRzOyrH08 around the same topic.

slipset07:04:00

Not being a static typist myself, I do see the value of this, but I also see that this approach requires some effort. In most codebases I’ve worked with things like an SSN would be a String, which lets you pass the complete works of Shakespeare around and the type checker is still happy.