Tag Archives: programming

Build beans better with builders

Builders provide a nice, if verbose, way to create immutable java beans.

The upsides are a nice syntax for creating immutable beans, and a way to provide copy-on-write behaviour for immutable objects.

The downsides are the need for verbose boilerplate code, approximately doubling the code size of the bean source files, and the overhead of one extra object created and then left for garbage collection, for each created bean.

Continue reading Build beans better with builders

Chaining Optionals using flatMap and map

The blog post How I learnt to like Optional shows an example of how to chain Optional values safely, using Optional.orElse() to provide empty objects for the next level in the chain.

This blog post uses Optional.flatMap() and Optional.map(), to achieve the same thing, without having to create the empty objects, and without doing any evaluation for empty objects.

Continue reading Chaining Optionals using flatMap and map

How I learnt to like Optional

I used to see Optional<Something> as a completely useless addition to Java, adding to the bloat of Java without being any clearer than checking if a reference is null.

I have changed my mind, and now think Optional<> can be useful in making code simpler, easier to understand, and more robust.

The reason I changed my mind, was the usefulness of Optional.orElseThrow() when having to traverse deeply nested data structures in Java code.

Continue reading How I learnt to like Optional

Very basic emacs usage


Emacs is a very powerful and flexible text editor.

This is a very quick walk-through of essential emacs commands, based on my own experience of the commands I use most frequently.

I’m giving the key shortcuts, because those are the ones I use. But running in a GUI, you can use mouse navigation for such things as switching windows, and there are menu items for many of the commands.

I thought that this list would be short, but once I started writing I thinking about new stuff that I should include. Eventually I had to cut it down to what I really think are the basics.

Continue reading Very basic emacs usage