re: You Either Have It Or You Don't VIEW POST

re: Wow. Interesting! I've never used clojure so correct me if I'm wrong, but clojure is a lisp and everything is a list in lisp? (hence the name) - s...

correct me if I'm wrong, but clojure is a lisp and everything is a list in lisp?

Not quite. For example atoms aren't lists, neither are other primitive types. That's why there are predicate functions that check for null, i.e. null in Common Lisp or null? in Racket.

It's unfortunate in some ways that Maybe is linked so closely with null/not null, because you can think of it another way

That other way generally has another name though, Either (Haskell) or Result (e.g. Rust). The failure case (Left or Error) holds the error message so you don't have to throw it away. So in your examples a DB operation that may return no records (i.e. find by primary key) could be a Maybe, whereas something that actually produces an error would be an Either. That's why it's not uncommon to see Maybe values inside Either for things like API requests. The Either tells you if the operation itself succeeded (i.e. could we make a request), the Maybe if a value was returned from that request.


ah cool - thanks for clarifying. Then I guess I didn't really get his point!

about Either - yes, exactly - I was kind of deliberately over simplifying to make the point that there's other, sometimes nicer ways to think about Maybe

Maybe, IIRC, comes from Haskell, which doesn't have nullability so it has nothing to do with nullability checking.

It has everything to do with encoding the fact that having a value or not having one are two different, equally informative, and perfecly legal values. And your code must be able to distinguish those and act accordingly.

Lisp, and then Clojure probably have different idioms (i.e. the empty list) that do not require a union type, and can be treated as equally informative. That's probably what Hickey has in mind.

Yes, I understand the difference. The question is if there’s an inherent benefit to nulls or if there’s value to potentially modeling them as “not having something.” The answer is not super straightforward and I believe changes a lot with the domain, something that has been explored in a different comment (scripting vs core business logic for example).

code of conduct - report abuse