4 December 2019

New Classes in Java 10

New in Java 10As Java developer I used to monitor the new features of Java very closely. As Code Cop my focus on programming languages is much broader. Currently I am working with clients using C#, Java, JavaScript, Kotlin, Oracle PL/SQL, PHP, Python and TypeScript. (And I would love a few more clients using some F#, Go or Scheme.) Since version 9, Java is released much more often than it used to be and I lost track of its new features. Eventually I had to catch up. Here is the list of all new classes in Java 10. Java 10 was launched March 2018 and went EOL September 2018. While it is not relevant as a version on its own, I want to be explicit about it as it is part of 11 and all later releases.

Local-Variable Type Inference
The most interesting new feature is the var keyword, Local-Variable Type Inference. This is a compiler feature and is not visible in the public classes available in the JRE/JDK. The var causes a lot of discussions about readability of source code. I recommend checking out the Style Guidelines for Local Variable Type Inference in Java to avoid confusion.

Experimental Java-Based JIT Compiler
JEP 317 enables the Java-based JIT compiler named Graal. It comes with the jaotc command which produces native code for compiled Java methods. While this is a feature of Java 9, JEP 295, the new class jdk.tools.jaotc.Main and the packages jdk.tools.jaotc.* show up for the first time.

Other Smaller Changes
The number of new classes in Java 10 is below 50, of which 40 classes are the jaotc. The remaining are
javafx.scene.control.TabPane$TabDragPolicy

jdk.incubator.http.HttpRequest$BodyPublisher
jdk.incubator.http.HttpResponse$BodySubscriber
jdk.incubator.http.HttpResponse$MultiSubscriber

jdk.jfr.events.FileForceEvent

jdk.packager.services.singleton.SingleInstanceListener
jdk.packager.services.singleton.SingleInstanceNewActivation
jdk.packager.services.singleton.SingleInstanceService
a change to JavaFX, drag policies for tabs in a TabPane, providing Flow implementations for the experimental HTTP 2 client, something in the Oracle Flight Recorder, a commercial feature that must be unlocked before being used and Single Instance functionality for Java Packager.

This is a very small release, still Simon Ritter from Azul Systems managed to find 109 New Features In JDK 10. Check them out!

List of all public classes
You can download the complete list of all classes available in Java from version 1.0 to 10.0.2. Each class name is annotated with [release] showing the release it first appeared, e.g. java.lang.annotation.Annotation [5].

21 November 2019

Promotion Service Kata

In September I attended a small, club-like unconference. The umbrella topic of the event was katas and their use in teaching and technical coaching. A kata, or code kata, is defined as an exercise in programming which helps hone your skills through practice and repetition. We spent two days creating, practising and reviewing different exercises. I came home with a load of new challenges for my clients.

Kata Factory
One session, run by Bastien David, a software crafter from Grenoble, was named Kata Factory. Bastien guided us to create a short exercise with a very small code base, focused on a single topic. In the first part of the session we created small tasks working in pairs. Then we solved a task from another pair in the second part. A total of four new coding exercises was created, tried and refined. It was awesome.

Promotion Service Kata
I worked with Dmitry Kandalov and we created the Promotion Service Kata. It is a small refactoring exercise, based on Feature Envy, a code smell listed in Martin Fowler's book. (Did you know that there is a second edition of this great book? No, so get it quickly.) The code base contains a single service, the promotion service, which calculates discounts for promoted items. It is a bit crazy because it also reduces the tax. The data is stored in a classic DTO and its fields are not encapsulated. The task is to make it a rich object and encapsulate its fields. There are existing unit tests to make sure things are still working.

After the Kata Factory, I spent some time on porting the kata to different languages. Currently the code is available in C#, Java, Kotlin, PHP and Python. Pull requests porting the code to other languages are very welcome. Check out the code here.

Promotion Service RetrospectiveNotes from first run
I already facilitated the exercise with a small team of C# developers. Here is what they said about the kata:
  • It is a good exercise.
  • It is a short exercise. It is small, so there is no need for context.
  • Encapsulate all the things!
  • I learned to separate concerns.
  • I learned about string.Format (a C# specific function).
  • I did not know the goal of the exercise.
  • Maybe rename the Persist() method to Save().
  • The Item class should be in its own file.
Conclusion
Bastien's approach shows that it is possible to create a brand new and highly focused coding exercise in a short time. As with most development related things, pair work is superior and it is easy to come up with new code katas when working in pairs. Small exercises - I call them micro exercises - are easy to get started because there is little context to know. Context is part of what makes coding assignments difficult. I am very happy with this new exercise.

Give it a try!

11 September 2019

Human Needs vs. Bad Code

We human beings have basic needs. There might be a finite, limited number of fundamental needs. We then choose different strategies to meet these needs. Techniques like Nonviolent Communication (NVC) are based on identifying and meeting shared needs. For example, my goal of professional training and coaching is not only knowledge transfer - i.e. teaching people useful tricks. I also want to stretch them, make them think "outside the box" and change their behaviour: e.g. focus in self-improvement, take control of their career and ultimately assume their social responsibility. When I thought about my work as Code Cop, what I liked about it and what inspired me, I arrived at my own needs: learning and growth - I want my clients to learn and grow. Further clarity, consistency and integrity which is what I need when working with software.

My Needs (Wordle)
Needs are central to our work, our own needs as much as the needs of our colleagues and clients. Earlier this year I attended an unconference, meeting some friends in Grenoble. We discussed how to align technical coaching work, e.g. Technical Agile Coaching, with business goals. We paired up and worked on different approaches. I was not surprised when one team started the whole alignment with discussing basic needs of all people involved. It was very interesting and outside of the scope of what I want to write about today.

Missing Code Quality
Today I want to write about possible reasons for missing code quality. I discussed human factors before and held the strong opinion that developers creating bad code were unskilled, lazy and weak. When considering needs and strategies to meet them, the issues is getting more vague. Which needs could be fulfilled by a developer creating some quick and dirty code, duplicating some method or adding some library just to play around with it? When I discussed this with my friend Aki Salmi, Software Crafter and Communication Trainer, he quickly came up with a bunch of needs like acceptance, appreciation, cooperation, consistency, inclusion, respect/self-respect, stability, trust, integrity, autonomy, choice, challenge, competence, contribution, creativity, discovery, effectiveness and purpose. This is a huge list of needs to get started. As an exercise to the reader, try to figure out how the listed needs could be met.

Needs Met When Creating Bad Code (in German)
Three Examples
Now let's motivate some of the listed needs in detail. For example, someone might bring in some technology which is not necessary for the project and introduces additional, unnecessary complexity. Met needs might be creativity (I want to try something new), learning (I want to learn it), joy (I enjoy playing with it), safety (I will add it to my CV - Resume-driven development), autonomy and choice (I choose myself), consistency and integrity (I have always been using it), safety (I already know how to use it) and so on. What about someone who never argues for quality related changes, clean-ups, more time or reduced scope? Needs met might be appreciation (My boss is happy), ease (I do not argue with anybody), security and protection (I keep my job) etc. And for typical fire fighting, quick-and-dirty developers: competency (I can do it), efficacy (I am fast), effectiveness (I can make it work). These are just a few ideas I got while discussing the topic during a workshop.

Needs Met When Creating Good Code (in German)
Opposite
Now let us look at the opposite side. For quality code, I value consistency - which is obviously a good thing. It is also consistency which keeps some people from adapting to new ways of working, as in "this is the way I've always worked" - obviously a bad thing. If I keep my code base clean, I am sure that I can work on it later, which makes me feel safe. The same need for safety might keep someone from trying something new, because it is scary, or it might make people thrash their code because their boss is requesting too much in too short time.

Conclusion - If Any
Needs are everywhere. They are universal, cannot be denied nor argued. We use some strategies to fulfil needs when we mess up the code. There are many needs involved, maybe that is why there is so much bad code written. On the other hand, we use strategies to fulfil needs when keeping our code clean. It scares me that opposite behaviour might be driven by same needs. How can we condemn these duct-tape and legacy coders when they are just driven by their needs as we are?