I love SQL, despite its many flaws. Much is argued about functional programming vs object oriented. Different ways of instructing computers. SQL is different. SQL is a language where I can ask the computer a question and it will figure out how to answer it for me. Fluency in SQL is a very practical skill.... Read more »
Java 16 brings Pattern Matching for instanceof. It’s a feature with exciting possibilities, though quite limited in its initial incarnation. Basic Pattern Matching We can now do things like Object o = "hello"; if (o instanceof String s) { System.out.println(s.toUpperCase()); } Note the variable “s”, which is then used without any casting needed. Deconstructing Optionals... Read more »
Some time ago I wrote a post about creating an embedded dsl for Html in Java. Sadly, it was based on an abuse of lambda name reflection that was later removed from Java. I thought I should do a followup because a lot of people still visit the old article. While it’s no longer possible... Read more »
A few years back I posted about how to implement state machines that only permit valid transitions at compile time in Java. This used interfaces instead of enums, which had a big drawback—you can't guarantee that you know all the states involved. Java 15 brings a preview feature of sealed classes, solving this downside.
A while back I promised to follow up from this tweet to elaborate on the fun I was having with Java’s new Records (currently preview) feature. Records, like lambdas and default methods on interfaces are tremendously useful language features because they enable many different patterns and uses beyond the obvious. Java 8 brought lambdas, with... Read more »
Pain is something we generally try to avoid; pain is unpleasant, but it also serves an important purpose. Acute pain can be feedback that we need to avoid doing something harmful to our body, or protect something while it heals. Pain helps us remember the cause of injuries and adapt our behaviour to avoid a... Read more »
End to end automated tests written with Webdriver have a reputation for being slow, unreliable (failing for spurious reasons), and brittle (breaking with any change). So much so that many recommend not using them. They can become a maintenance burden, making it harder, rather than easier, to make changes to the user interface. However, these... Read more »
Having benefited from “var” for many years when writing c#, I’m delighted that Java is at last getting support for local variable type inference in JDK 10. From JDK 10 instead of saying ArrayList<String> foo = new ArrayList<String>(); we can say var foo = new ArrayList<String>(); and the type of “foo” is inferred as ArrayList<String>... Read more »
Many things can be modelled as finite state machines. Particularly things where you’d naturally use “state” in the name e.g. the current state of an order, or delivery status. We often model these as enums. enum OrderStatus { Pending, CheckingOut, Purchased, Shipped, Cancelled, Delivered, Failed, Refunded } Enums are great for restricting our order status... Read more »
Update: this technique no longer works since name reflection was removed in later versions of Java. Here is another approach. Another use of lambda parameter reflection could be to write html inline in Java. It allows us to create builders like this, in Java, where we’d previously have to use a language like Kotlin and... Read more »