3 ms·
Or use the null object pattern. Then you can write code that "just works"; kind of a higher level version of a nop.
by JustSomeNobody 10y ago
Or use the null object pattern. Then you can write code that "just works"; kind of a higher level version of a nop.
- specialist 10y agoThe Null Object pattern is The Correct Answer (for Java like languages). Java's Optional is a bad idea implemented badly made even more bad by bad usage.
- mark242 10y agoOption is a takeoff of the Null Object pattern. Option(null).map(str => str + "!").foreach(str => println(str)) is a noop.
- aarongolliver 10y agoYeah, the Null Object Pattern is just optionals except you have to re-implement it each you need optional semantics.
- specialist 10y agoNo. They're opposites. "...an object which implements the expected interface, but whose method body is empty. " https://en.wikipedia.org/wiki/Null_Object_pattern https://en.wikipedia.org/wiki/Null_Object_pattern