Monday, May 20, 2019

Replacing null checks

This article introduces some patterns for replacing the "old" null-check pattern.

I.e. instead of:
if (value != null) { doSomething(value); } 
do:
Optional maybeValue = Optional.ofNullable(value); if (maybeValue.isPresent()) { doSomething(maybeValue.get()); }

Friday, February 15, 2019

Coding without IF statements

Found below linked article that provides tips on how to avoid using IF statements, with one of the benefits being readability. The tips largely are based on the concept of using a map to the result, which is essentially a one-in replacement of a switch statement. If's can be rigged in too as the examples show:
https://edgecoders.com/coding-tip-try-to-code-without-if-statements-d06799eed231