←back to thread

1087 points smartmic | 4 comments | | HN request time: 0.951s | source
Show context
1-more ◴[] No.44310959[source]
This concept is really interesting when you think about statically typed, pure functional languages. I like working in them because I'm too pretty and stupid to think about side effects in every function. My hair is too shiny and my muscles are too large to have to deal with "what if this input is null?" everywhere. Can't do it. Need to wrap that bad boy up in a Maybe or some such and have the computer tell me what I'm forgetting to handle with a red squiggly.
replies(1): >>44311458 #
9rx ◴[] No.44311458[source]
Formal proof languages are pretty neat, but boy are they tedious to use in practice. It is unsurprising that effectively no code is written in them. How do you overcome that?

Where the type system isn't that expressive, you still have to fall back to testing to fill in the places where the type system isn't sufficient, and your tests are also going to 'deal with "what if this input is null?" everywhere' cases and whatnot by virtue of execution constraints anyway.

replies(1): >>44311689 #
1-more ◴[] No.44311689[source]
I'm just talking null-less FP languages such as Haskell and Elm, not a full proof system such Lean and Agda or a formal specification language such as TLA+.

I'm not sure I agree with your prior that "your tests are also going to 'deal with "what if this input is null?" everywhere' cases and whatnot." Invalid input is at the very edge of the program where it goes through a parser. If I parse a string value into a type with no room for null, that eliminates a whole class of errors throughout the program. I do need to test that my parser does what I assume it will, sure. But once I have a type that cannot represent illegal data, I can focus my testing away from playing defense on every function.

replies(1): >>44311742 #
9rx ◴[] No.44311742[source]
Assume that there was room for null. What is your concrete example of where null becomes a problem in production, but goes unnoticed by your tests?
replies(3): >>44312349 #>>44313810 #>>44314847 #
default-kramer ◴[] No.44313810[source]
How many people actually write exhaustive tests for everything that could possibly be null? No one I've ever met in my mostly-C# career.

I can confirm that at least 30% of the prod alerts I've seen come from NullReferenceExceptions. I insist on writing new C# code with null-checking enabled which mostly solves the problem, but there's still plenty of code in the wild crashing on null bugs all the time.

replies(1): >>44314156 #
1. 9rx ◴[] No.44314156[source]
> How many people actually write exhaustive tests for everything that could possibly be null?

Of those who are concerned about type theory? 99%. With a delusional 1% thinking that a gimped type system (read: insufficient for formal proofs) is some kind of magic that negates the need to write tests, somehow not noticing that many of the lessons on how to write good tests come from those language ecosystems (e.g. Haskell).

> I can confirm that at least 30% of the prod alerts I've seen come from NullReferenceExceptions.

I don't think I've ever seen a null exception (or closest language analog) occur in production, and I spent a lot of years involved in projects that used dynamically typed languages even. I'd still love for someone to show actual code and associated tests to see how they ended up in that situation. The other commenter, despite being adamant, has become avoidant when it comes down to it.

replies(1): >>44314862 #
2. mdaniel ◴[] No.44314862[source]
> to see how they ended up in that situation

The "how" is almost always lack of discipline (or as I sometimes couch it, "imagination") but usually shit like https://github.com/microsoft/SynapseML/issues/405#:~:text=cl...

I've had to learn in my career not to open other people's projects in a real IDE because of all the screaming it does about "value can be null"

replies(2): >>44315821 #>>44320377 #
3. 9rx ◴[] No.44315821[source]
That's a tough bouncing ball to follow as it appears that the resolution was to upgrade to a newer version of a dependency, but if we look at that dependency, the fix seems to be found somewhere in this https://github.com/microsoft/LightGBM/compare/v2.2.1...v2.2....

There is admittedly a lot in the update and I may have simply missed it, but I don't see any modifications, even additions, to tests to denote recognition of the problem in the earlier version. Which, while not knowing much about the project, makes me think that there really isn't any meaningful testing going on. That maybe be interesting for what it is, I suppose, but not really in the vein of the discussion here about where one is using type systems and testing to overcome their personal limitations.

4. 1-more ◴[] No.44320377[source]
> in a real IDE because of all the screaming it does about "value can be null"

Yeah, when you have extra tools like that it can certainly help. The thing is that you can ignore any warning! I like it to be a compiler error because then there's no way to put that on the tech-debt credit card and still pass CI. If you are able to put those warnings into your CI so a PR with them cannot merge, then that's like 99% of what I like in my code: make the computer think of the low-hanging-fruit things that can go wrong.

With all of that said, solving for null does not get you everything a tagged union type does, but that's a different story.