3 ms·
I used flow typing in MyPy and it's awesome. TypeScript has the same thing (although I would be curious if their rules are significantly different). I think y
by chubot 6y ago
I used flow typing in MyPy and it's awesome. TypeScript has the same thing (although I would be curious if their rules are significantly different).
I think you can't practically have null safety without flow typing, at least in an imperative language, otherwise you end up with casts everywhere. MyPy has null safety, though it takes some effort to turn it on for most codebases.
- millimeterman 6y agoNot at all - that kind of dataflow analysis is basically just a hack to patch over the fundamentally broken design of having everything be nullable. It's totally unnecessary in a language with proper algebraic data types where there's no all-pervasive concept of "nullability". The only imperative language I know of that has this is Rust, but it originates from ML languages like OCaml and Haskell. It's one of those features where once you get used to it, it's hard to fathom how anyone programs without it. It's such a simple yet expressive feature that's incredibly useful when writing normal, ordinary code. Nothing fancy or theoretical.
- blandflakes 6y agoI'm mostly agreeing with both you and the sibling - flow-sensitive typing is great. I think it's awesome in Kotlin, and removes the Java-style casting or manual unwrapping inside of if guards you always end up with. As sibling said, ML-style languages get away with this a different way - chained "container" operations in Scala, for example, are "right-biased", so the only get called if the result of the preceding operation was a success or not null. I've heard it called "Railway Oriented Programming": https://fsharpforfunandprofit.com/rop/ https://fsharpforfunandprofit.com/rop/