3 ms·
I found myself writing this kind of code recently: https://pastebin.com/fpQzRypp https://pastebin.com/fpQzRypp Sometimes code is being plugged between two high
by 127 6y ago
I found myself writing this kind of code recently: https://pastebin.com/fpQzRypp https://pastebin.com/fpQzRypp
Sometimes code is being plugged between two highly unstable things. It just needs to work and can't trust that any of the data it receives is valid or good.
I should really be using types here.
- hannofcart 6y agoIndeed, you'll find that type annotations and enforcing them with a type checker will eliminate all those `assert`s for `not None`.
- zo1 6y agoIt won't eliminate it, but... At the very least it'll "push it back" quite close to the point in your code where someone made a not-so-well-thought out decision to accept nullability into a variable and let it propagate that uncertainty into the rest of the system.
- zo1 6y agoAs an anecdote: I've encountered, in production, a large order of magnitude more "null reference" errors in statically compiled languages than I have in python. But, people that propagate inconsistent state into their application exist on both sides, and having a statically-typed language doesn't necessarily shield you from the consequences.