Refactoring to Optional
When we right software we need to worry about so many things. For instance: Performance, Scalability, Security, and many other important concerns. There is also a need to worry about corner cases, error paths, and conde readability from other engineers. Which is not an easy task. So should we return null or not? Should we throw an exception or not? Null is considered to be a Billion of dollars mistake. Languages have some concepts to help us like Haskell has the Maybe Monad. Scala has Option. Rust has Result. Java has Optional. Since version 8, Java improved a lot and there is still a long head ahead but slowly getting there. Today I decided to do something different with you guys, let’s do a simple refactoring together in order to improve our code and understanding. So there is a video showing from zero to a hero like code step-by-step. This is the first refactoring video I make, hopefully, it will be interesting for you guys. Without further due, let’s get started!
Full code here on my github.
Originally published at http://diego-pacheco.blogspot.com on May 19, 2020.