4 ms·
You have to deal with it in some way. If a function should return a boolean and something bad happens then it can return Union<boolean, failure> or Optional<boo
by sz4kerto 8y ago
You have to deal with it in some way. If a function should return a boolean and something bad happens then it can return Union<boolean, failure> or Optional<boolean> or nullable boolean or throw an exception. The difference is basically in compiler assistance. Null pointers are bad because the lack of good static analysis support.
- hellofunk 8y agoBut you are talking about a statically typed way of handling nil. Options and Unions are not nil, which is the point. But you don’t get this in Clojure and nil can mean a lot of different things in different contexts, which is more complicated than a simple optional.
- degrews 8y agoSo how _do_ you handle nil without those things? You've said you try to just avoid it, but many functions return nil and there's no easy way around it (e.g. trying to get the max value of an empty list)
- qop 8y agoRepresent the problem programatically. If there's some reason data is missing, use a symbol :idk, :not-provided, etc. Programs DO things, use what you're doing to describe your program, whenever possible. In a better world, max([]) # -> None(T) But sometimes we have to get creative...
- hellofunk 8y agoFunctions only return nil when nil is a valid value in your logic.