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

Wednesday, March 29, 2017

XML Beans vs JAXB

Seems XML Beans is superior:
JAXB provides support for the XML schema specification, but handles only a subset of it; XMLBeans supports all of it. Also, by storing the data in memory as XML, XMLBeans is able to reduce the overhead of marshalling and demarshalling.
http://xmlbeans.apache.org/docs/2.0.0/guide/conGettingStartedwithXMLBeans.html

Tuesday, October 11, 2016

Ruby - Use Struct for "Reification" / OO

http://blog.steveklabnik.com/posts/2012-09-01-random-ruby-tricks--struct-new

Ruby has the Struct construct which author makes use of to "reify" objects to be more Object Oriented. In Java, we'd have to create a separate class for these tiny strongly typed data objects, e.g. by using the "parameter object" pattern.

Saturday, July 23, 2016

Refactoring for SOLID

I read the two articles below on refactoring and SOLID principles.


In the OOP section of the above article, the interesting takeaway is the encapsulation of logic in a "policy" class which is used along "doer" classes to be invoked and thus abstract away and remove cyclomatic complexity from methods.


This one lends credence to the notion of the "large set of small classes" to abide by the Single Responsibility Principle. The emphasis is on composition of behavior, and using seams or interfaces to swap out or extend (by using decorators) existing behaviors to add new features.