Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

The best solution I've seen is a Maybe Monad.

The problem is that unless your language has support baked in (a la Haskell) the syntax has way too much overhead.

If you haven't played with Haskell, I thought this was a pretty good explanation: http://paulbarry.com/articles/2009/07/17/emulating-haskells-...



> The best solution I've seen is a Maybe Monad.

More generally an option type. Maybe being a monad has other advantages (lifting for instance, though being a monad isn't actually required: C# 3.0 lifts operations into Nullable when you're e.g. adding two Nullable<int> [aka int?] values) but is not a requirement for a "nullable" living in the types.

> The problem is that unless your language has support baked in (a la Haskell) the syntax has way too much overhead.

Not really. The problem is more around the way your generics work: Putting Nothing in a Maybe Int is nice, putting a new Nothing<Int>() in a Maybe<Int> isn't as much.

And if anything, I think having overhead in pushing null values in the system is a good thing: it avoids people running to it right off the bat, and may make them pause and think about better solutions (a command-type pattern, a Null/SpecialCase object, …)




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: