Go lang

It has been a crazy few months in startup land. The interesting thing for me about startups is no matter how crazy it is compared to corporate work, I find myself really content amidst the chaos. The big change here is we have decided to build our backend architecture in Go instead of Java. Having done Java for 19 years this is a big change, but for business decisions we decided that the trade offs with Go were better for our long term business needs than the trade offs with Java. Now that I have been using it for a few months I figured I would discuss some of the differences between the languages and what I like and dislike about each.

First Impressions

Just from an initial impression to me, Go seems like a cleaned up C language. You basically have a low level language with primitives and structs, slices (lists in Java), maps, and not a lot more. You end up having to build and write more code than in Java. But in sort of a nod to the good parts of OO they have interfaces and methods that you can attach to structs. At that point it is almost like a super lightweight C++.

I find that I spend a lot more time wiring up code in Go. Having done Spring now for 10 years you spend very little timing wiring up your code as everything is autowired, and you mostly just focus on business logic. Same for SQL Spring Data provides such a nice DSL you don’t write that many database queries either. In my initial analysis it took about 10 times as much code to write a simple REST backend in Go as compared to Spring Boot. But it used 1/10 as much RAM or less. This is the reason we decided to spend more money on Development costs (as it is much more code to write than Java) as we believe the savings on cloud hosting costs down the line will make it a better decision for us.

Go produces a single binary just like Spring Boot gives you a fat jar so I consider them equal here, but the startup time for Go seems to be instant, where as due to all the reflection and wiring at startup in Spring it seems like those apps typically take about 5 seconds to start in my experience (if there is a database involved).

Ceremony

General

Go has taken some steps to remove the ceremony in the language. One of the big differences that I notice is that you no longer needs ()around your statements in for loops, while loops and if statements. I repeatedly find myself putting those in by default and then having the IDE remove them. Another big difference is you no longer have to terminate your statements with ;as the compiler automatically puts those in for you. A little bit like Groovy in that regard.

Iteration

You would think that after doing all that work to remove ceremony that the language would be clean in general. But here is where I see the low level C type stuff come through. In Java if I want to iterate through a list it looks like this:

for (item : list) {

Basically it reads as for each item in the list, and the you operate on it. Go has a range statement to iterate through an array or slice. Here in lies a big difference in Go between Java is that you can return multiple values from a function or method. The designers of the language decided to have the range statement return both the index and the value. Generally in Java if I am using a for each it is because I don’t care about the index, I use a standard for loop if I need the index. Go has the standard for loop but for some reason they decided to return the index as well. You end up having to throw it away if you don’t care about it which feels like more ceremony again so the above statement ends up reading:

for _, item := range list { It is hard to look at that and think that reads better than the Java even though they got rid of the parenthesis.

But even this sort of misses the point as I am not even using for each that much in Java these days instead we have moved to a higher level yet and now use stream operations and handle everything in a functional style. What ends up happening in Java is you spend your time telling the language what you want to happen and let it sort the details of how to do it (lazy execution, or parallel execution, it doesn’t really matter with streams). In Go you spend your time telling the language how you want it to do the iteration so it feels like you are back down in the weeds again.

Initialization

Initializing an empty list also feels like it is more ceremony in Go. In Java you might have:

var list = new ArrayList<String>();

You look at that line and you have the ceremonly of the generics and the () to state which constructor you are calling and then the semicolon to terminate the statement. In go you end up with something like

list := []string{} again I wouldn’t call that better, just different. The ceremony here is the := which allows you to leave out the var at the front and you have the braces at the end which are initializing the struct. It is shorter but again neither seems to read better nor worse, just different.

References

One other big difference which really brings me back to C is you have to specify whether you are dealing with a value type or reference type in Go. In Java all primitives are value types and all Objects are reference types so you don’t have to spend any time thinking about it especially in a world of autoboxing. The drawback to the Java approach is if you need performance and memory compactness sometimes you need to use arrays of primitives and not collections. This is something that can definitely trip up a new programmer. Another problem is if autoboxing isn’t handled correctly it is possible for a NullPointerException to be thrown which could also be confusing to a junior developer.

In Go you have to explicitly thing about whether you are passing a value to a struct or a reference to it. Arrays and slices and maps are automatically reference types but any of your structs you have to explicitly declare if it is a pointer or a value type. For example

type struct Person {
  Name string,
  Age uint
}

pointerToPerson := &Person{Name:"Jeff", Age:41}

valueTypePerson := Person{Name:"The Doctor", Age: 904}

If you want to use pointerToPerson above you have to dereference it with the *. If the pointer is nil you will panic if you dereference it. On the other hand the value type if you don’t initialize it goes to default values so the default for the string is an empty string ""and the default for the integer would be 0.

Concurrency

Concurrency is where Go both shines against Java and feels lacking at the same time. Let’s talk about what is great if you want to call a function concurrently it is amazing you simply do:

go handleData() and handleData() will be executed concurrently. The great thing about go calls is they are extremely lightweight. When I read about project loom where they want to bring fibers and continuations to Java. Because they are much lighter weight than a thread in Java you can have thousands of them without a performance issue. It is my understanding that their is a threadpool underneath that executes your different go routines I think similar to an executor in Java with runables, but again I think the go routines are using much less memory than a Java Runnable.

This kind of light weight concurrency seems to be the direction everything is going whether it is the node system of events and async callbacks or even the reactive movement going through spring. Everyone is trying to execute more things concurrently with a very small thread pool.

There is much more ceremony in a Java Runnable or Callable. First I have to implement an interface and then put my code in a specific method. Then I need a Thread or an Executor on which to execute the code. If it were a Runnable and I needed a return type I would need to pass in some sort of concurrent collection to safely send the data back to the other thread in, or I could return it directly in the callable when I get a future out of that callable that can give me the return value.

Java definitely has a ways to go to catch up to go with the ease of concurrency, but the types are much richer for concurrency in Java so with java.util.concurrent.* one has access to about anything you need. In Go you pretty much just have channels to safely pass data between separate Go routines this again has that simple feeling of C where you are building everything up from primitives vs Java where the libraries are much richer.

Tooling

Here in you can tell how young of a language Go is. To me the tools feel like going back in time to around 2005 in Java. The debugger (delve) is primitive and I often find it not stopping at my break points or not showing me the values of all of my variables. I remember using JBuilder and Visual Cafe and some of the early Java IDEs and having similar issues of the debugger just not working that well. I find myself using printf statements to debug again which feels like going back in time 20 years.

IDE support seems decent though otherwise (if you throw out the debugging issues). I am using IntelliJ Ultimate with their Goland plugin and find myself very productive in writing code. It is the same IDE that I know and love from my Java work, and the understanding of the syntax in general seems to be great. I hear that VSCode is also pretty good for writing Go.

Enterprise Features

This is a small point but one that I just hit in the last week or so and that is that the language lacks support for batching SQL statements. Given that Java is such a strong enterprise language I just assumed that would be built into Go as well, especially given that the language is 9 years old, but maybe most of the internet type software being built isn’t using batch operations to slam a lot of data into a database at once.

Conclusion

At this point I still think Java is a more enjoyable language to program in. I like the higher level you can operate at with things like the stream api, and I like how opinionated Spring is. I think that saves you time setting up a new service and leads to consistency when dealing with new code that you haven’t seen before. Go concurrency model feels like it could be more powerful which is why there is that Java project loom to bring fibers and continuations to the language. The value types are an advantage and result in Go using very little memory compared to a typical spring project, which is again why in the Java world they are working on bringing value types into the language. Go is definitely powerful and fast and effective at what it does. If I were still a C programmer I would probably love it, as it feels like C without all the annoyances. As it stands now I can use it, and it works well, but I am not yet passionate about the language.

Here I go again

This isn’t just a reference to an 80’s hairband song, I have decided to go to work for another startup company. It was just over a year ago when we sold Choose and I took my previous role. When I joined that company I expected to be there for a while. I was given a position to lead the architecture of a new system that had been built by a consulting company to replace a legacy system. Technology wise there were a lot of great decisions made with the new architecture that they had. It was a modern Spring Boot stack, composed of micro services.

I dove into it and started learning the businesses domain. As things sometimes happen in the fall there was a shakeup with the leadership which resulted in the CTO who hired me leaving in January. I was on vacation at the time and I had called into the meeting and heard that announcement. As I sat there thinking about that I was thinking given the trends that were going on, it wasn’t feeling like the culture of the new leadership was compatible with my workstyle. I started thinking about what should I do next.

Out of the blue that afternoon I get a text from my friend Kevin whom I had worked with at Choose. He and another former coworker and friend of mine had started a venture capital fund. Kevin mentioned that they were in talks with a company that they were considering funding and he would like to introduce me to the CEO as he felt like we would work together. After a great initial meeting, I then started doing some meetings with the rest of the team. I was really intrigued by the team at this point. They had a big vision and all around seemed like amazing people to work with.

As things happen the whole fund raising thing takes a great deal of time and I started feeling like maybe it wasn’t going to come together so I started considering some other opportunities as the situation with the leadership at my former company kept deteriorating. My manager left to take a new role, and he was absolutely amazing.

In May the conversation around what we would be working on and my role resumed and we were finally able to get a planned worked out and an offer accepted by the end of June. At that point though I already had my summer travel planned for July so we planned on getting started when I got back from our travel. Once again we had an issue though in that I was rear ended in our minivan and the body shop didn’t repair it in time for us to start our travels up to Minnesota and Wisconsin. We would have been left with just 4 days up there and 4 days of travel which sounded like a nightmare when doing a 1000 mile road trip with 4 children. At that point I requested pushing out my start date another week so that we could have a proper vacation and that wasn’t a problem so we headed north and spent a wonderful couple of weeks with my family.

We headed back to Texas and I finished up my last week of work, and finally at the end of July I started my new role. This is the first time in my career that I was the first engineering hire and this is the earliest stage in a start up that I have ever been able to work on. I just finished up my 4th week of work (I had intended to write this in the first couple of days but I have been too busy to get to it until now), and it has been an amazing ride already. Although I have only been there a month it feels like so much has happened already. I am just excited to be building a new company again and to be diving into amazing architecture and implementation work on a new product.

Serverless and Spring Cloud Function

We have been discussing going to a more serverless architecture at work and so I decided that I should do some research to see where that stuff is now. When I was at Choose we used AWS Lambda to implement the backend of an abandoned shopping cart service. We would then use that data to drive an email campaign to encourage the users to come back and finish purchasing an energy plan. It had a huge effect in driving conversion rates and we were able to implement the service in about 25 lines of vanilla java code. I opted not to use Spring as I judged the startup times to be too slow for it to be worth it. To manage libraries we used the maven shade plugin in our build process to build a fat jar.

In my current role we will deploy on AWS lambda as well. One thing I am looking for in considering serverless frameworks is what allows the developer to have a very nice flow as well, as back when we did the abandoned cart service debugging was a painful experience. At that point I think we did a bunch of console logging messages to figure it out. That won’t scale up for a development team that is going heavy into serverless it is too inefficient.

Then last week I came across this Spring Tips video about a new project Project Riff. I am happy to see Pivotal getting into this space as they build great frameworks and tools. And Riff seems no different it allows a developer to easily install it on their laptop and seems like it has first class support for Google Cloud and anyone’s infrastructure that is already running Kubernetes.

So I really liked the Riff part of that video. But then I was watching the Spring Cloud Function part. Now everyone who knows me knows that I love the Spring framework. I have been using it since 2008, and I think in terms of what it can do for you on Java server apps there is nothing else close. It really accelerates developer productivity and lets them focus on solving business problems. But as I watched this video I was sort of like I don’t get it. Like year I get that people want to use Spring in serverless, but when you watch it take 5 seconds to stand up a function, to me that is a deal breaker. It is too slow and if you are being charged by the second for your service paying 5 seconds to execute a function that will take less than a second is too expensive.

I was pretty much ready to write Spring Cloud Function off as a bad idea based on that then I saw something on Twitter about Dave Syer demoing something at Spring IO this week which brings massively faster startup times. I suspect it has something to do with the spring-context-indexer that Juergen talks about in this video, but I have been unable to find any examples or documentation on how to use it.

The other thing I need to take a look at is the AWS SAM Local tool. The big pain point I had doing Lamda’s a couple of years ago was around debugging them. This looks like it may solve that problem for us by giving us an convenient way to hook this into our development lifecycle.

Apple Watch Series 3 Review

I have been watching the Apple Watch for a couple of years now debating about whether I should get one or not. Initially they looked too limited. The battery life on the initial model was very short and then there was the whole lack of being able to get the watch wet, among other limitations. I decided to sit back and wait a few years and see how it evolved.

The Series 2 started looking interesting, but I still didn’t find it compelling enough to give up the freedom of nothing on my wrist. Finally they announced the series 3 last fall and it started to sound like something that might potentially work for me. First it is setup for swimming with. While I don’t swim very often, for me having a watch on in the pool was always a nice way to keep track of the time. Then factor in the ability to track your workout and get texts and take a call without having to get out and dry off, it starts to look really good for someone who is more active than I am.

I decided to buy a 38mm Series 3 for my wife for Christmas. It sounded like the battery life was getting decent and many of my initial complaints were addressed. My thinking was she doesn’t always have her phone on her when dealing with the kids, so with the watch she would always get my texts or could answer the phone if she wasn’t near her phone.

She used it for a bit, but in the end she found that the battery life still wasn’t quite long enough for her that she would forget to charge it and it would be dead, or if a call came in she couldn’t answer it on the watch anyway as the baby was napping, etc. Given this she decided that we should sell it and she would do something else with the money, so I was thinking well before I sell it I should try it out for a couple of days just to see if I found it interesting enough to get one for myself. Obviously if I were getting one I would go for the 42mm as I find the screen on the 38mm a little bit small, but for testing purposes it would work perfect for me.

In my use I found that I could get about 20 hours out of the battery. That isn’t terrible as it should keep going on your longest days, but in a perfect world I would really like to see the thing last about 3 days. Normally you can just charge it every night so the current battery life isn’t really a deal breaker, but if you wanted to use the watch for sleep tracking, you would have issues with the current battery life. That being said, I don’t think I would use it for sleep tracking as I think having the thing on when I was trying to sleep would just annoy me. I think if I decide to go that route I would rather look at something like the Nokia Sleep which looks much less invasive than wearing a watch all night. At this point with an infant I don’t think really want to track my sleep though as I think ignorance how much many interruptions I have at night is probably bliss at this point.

The integration between the watch and my iPhone X is pretty amazing. You start the music or podcast app and immediately have controls on your watch for what your phone is playing. So when I am out walking the dog, I don’t have to pull my phone out of my pocket to skip a song or to adjust the volume it is all right there on the watch. When I glance at the time on the face I have a watch face that shows me my next calendar event, so I can immediately see when my next meeting is without having to check my phone. All the health metrics (activity and heart monitoring) automatically show up in your health app.

Basically it does what I feel Apple does best, which is to erase the boundaries between their different products. A perfect example of this, is I have a Honeywell Lyric T5 Thermostat. One of the reasons I went with that model instead of a Nest or something else was that it supported Homekit and I wanted to play around with the native integration on my phone. Then when I bought an Apple TV 4K suddenly you can program automations on your Homekit stuff as it just hooks in with the other devices it finds on your network. Granted I could do that before with the Lyric T5 App, but now it is integrated natively in my phone.

The watch is the same way, it gives you tight integration with your phone, and removes more boundaries. The model I have is the Wifi only model. The LTE sounds interesting, but not at the price that AT&T charges for it. I don’t think it adds enough value in my life to justify $10 a month for the service. At $5 a month it could get interesting. My neighbor has one of the original watches and he said he likes how well it works with his airpods as well. So when he is walking he can be playing something through his phone controlling it on his watch all going to his ears with no wires involved and everything just works. If you had the LTE model and a subscription to Apple Music you could even leave the phone behind as you don’t need it anymore. But again I don’t see myself going that route. I own over 4,000 songs, so the idea of renting music doesn’t sound interesting to me as I mostly own everything I want.

The workout app is interesting. I don’t really work out, but I am trying to be a bit more active for health reasons. Most of my activity consists of taking my dog for a walk in the evening. There is an outdoor walk as one of the options in the workout app. Typically I track my walks by having my phone in my pocket and checking Activity under the health app. I usually check how many steps I have at the start of the walk and then see how many I have after my walk to have a rough guestimate of how many steps I walked. The watch still gives you all that, but in addition to that it will also give in real time your distance in miles as well as the time you have been doing that working and what your heart rate is. I find that when walking the dog if I am nearing the end of the walk and I am at 1.5 miles I will push myself a bit and make sure we go for more than 2 miles. I also found it to be useful to sort of push your pace and get your heart rate up, as opposed to just tracking steps, without tracking your speed. Once you end the workout it will also give you the average time it took you to go a mile, and some other stats like average heart rate.

Many of the apps I have automatically have a watch version. I found most of these I have no interest in having on the watch and removed almost all of them. I left the Nokia Health app on there though and it was cool that when I earned a new badge exercising one night on there that it showed the achievement on the watch as well. One thing I disliked is that to remove some of the apple built in apps you have to remove them on your phone. A perfect example of this is the News app and the Stock app. I want neither on the watch, I want the watch to be really focused and just do 3 or 4 things, but to remove those apps from the watch I have to delete them from the phone. Apple doesn’t give me an uninstall option like it does with 3rd party apps. That is pretty annoying as perhaps I want to check my stocks every now and then on my phone I just don’t want it cluttering up my watch app screen, yet I can’t use it in that way.

One of the things I most enjoyed about the watch was getting text notifications on it (you can also get facebook messenger and slack messages there too if you want them). Mostly for when I was driving and I feel a text come in. You can just glance at it quickly at a stop light without having to pick up your phone (or miss the message until later as I do many times now).

So after using it a couple of days do I find it interesting enough to buy? At this point the answer is no. I don’t quite see what the killer app is. It is nice, and somewhat useful, but mostly it just feels like a fun toy at this point. The heart monitoring I must admit I do like. I also like the activity app that sort of nudges you to stand some and be more active. Those are all good things for me. But ultimately it isn’t enough to justify the price.

So what would get me to buy one. Well if I got a gym membership and was swimming regularly I could see myself getting one to track that workout. I think a real killer feature for me would be if the thing could some how do glucose monitoring. I would love to have like real time monitoring of that so that when I ate food I could see how it spiked my blood sugar. I think that kind of tracking would nudge me into eating healthier and would ultimately be the killer app for me. I could also see the watch being a game changer for my friends that are serious about running. The way it gives you the altitude change, average time per mile, weather, and heart rate, would be pretty useful for tracking how your runs are going. My sister does a ton of cardio and I could see her getting a lot out of the watch as well. And with the activity sharing if all your friends are in the Apple Ecosystem it could be useful to try to get a little competitiveness to encourage you to go out and be more active. But in my case it is about 50/50 between the Apple and Android eco systems so maybe some of the people that you want in your activity group you couldn’t get.

Maybe the series 4 will finally deliver the killer feature that will get me into one, but for now I will remain on the sidelines. (There is a rumor that the 4 will offer an even larger screen than the 42mm which sounds nice as well).

Java 10, already!

Java 9 we hardly knew ye, yet here we are and today was the GA release of Java 10. This is especially true for those of us using Spring boot as we just got official Java 9 support a couple of weeks ago and now 10 is out. From my standpoint the big features of the release are the Root Certificates. Java 9 shipped without root certificates if you used OpenJDK which in my mind makes it less useable as now you have to with that, you can’t just run it and go. That is what was keeping me on Oracle’s releases of Java. Now in Java 10 there is no difference with the oracle JDK and the OpenJDK so I will probably just deploy my apps on OpenJDK in the future. That simplifies Linux installation as now you can just run apt-get install and go. Before I used to have to add the ppa for Oracles and install it and then deal with the strong crypto policy files. All those old pain points are gone.

The next big change is Parallel Full GC support in G1GC. In Java 9 they changed the default VM to G1 and now they have enhanced it so that if you have to run a full collection it will at least run in parallel and reduce the pause time for your application.

The feature all the developers are talking about is local variable type inference. So now you can write:

var list = new ArrayList<String>();

Instead of:

List<String> list = new ArrayList<>();

The thinking being the name of the variable is the most important part and this may make the code more readable. For me I am not completely sold on this change. I think in some circumstances it may make the code more readable, but in other cases it will be worse, so I am taking a wait and see approach with using this style.

The other small developer feature that looks good to me, are APIs to create unmodifiable collections. I could see myself using that a lot, and it will be nice to no longer need Guava for some of these things. Instead of thehorrible old:

List<String> list = new ArrayList<>();
list.add("String 1");
list.add("String 2");

return Collections.unmodifiableList(list);

And making sure that you aren’t leaking the original reference you can just do:

var list = List.of("String1", "String2");

or if you have the list shown in the first example and you want to lock it down you can use:

return List.copyOf(list);

which I think reads better than:

Collections.unmodifiableList(list);

and it is obvious that it is making a copy so you don’t have to worry about leaking the original reference.

Other than that there is better support for the VM to realize it is running in a docker container and only assume the resources assigned to the container instead of reading the OS values. Otherwise there isn’t a lot there. That being said if you have managed to get on Java 9 already in production you need to upgrade right away as 9 is no longer supported, and you need 10 to make sure that you have all the latest security fixes.

Finally I will leave you with this:

Java version text

The times they are a changing…

Let’s Encrypt Wildcard Certs

Recently Let’s Encrypt announced that they would be supporting wildcard certs. I was pretty excited to hear about this as many times I would like to get certs for machines that might not be accessible on the internet. Currently I didn’t see an easy way to do this. With the new certs you could get a cert on your web server for your domain and use that cert on all the other machines in your domain that need TLS as well.

I decided to try it out and see how easy it was to do. I updated my certbot client to version 0.22 and did some google around and found out that you have to specify the new acme version 2 servers on the client command line in order to generate the wildcard cert. So I found the command and fired it up:

./certbot-auto --server https://acme-v02.api.letsencrypt.org/directory -d *.haskovec.com --manual --preferred-challenges dns-01 certonly

The command runs and asks you a few questions and then presents a DNS challenge. They give you a TXT record that you need to update in your DNS server to prove that you control the domain. I added the record and waited a couple of minutes and next thing you know it generated my new cert.

I updated my NGINX config to point to the new cert restarted the server and hit my site. Next thing I see is an SSL error. It turns out if you only have *.haskovec.com in the cert that isn’t a valid server for the base domain of haskovec.com. So I reran the command again and specified the following:

 ./certbot-auto --server https://acme-v02.api.letsencrypt.org/directory -d haskovec.com -d *.haskovec.com --manual --preferred-challenges dns-01 certonly

This time it asked me if I want to expand my cert to include the new domain name. I said yes. Next it had 2 challenges that I needed to insert into my DNS TXT record. I added them both and finished generating the new cert. When I restarted NGINX my site was back. I ran the https://www.ssllabs.com/ security test on my site and I am still at an A+.

All in all a very easy process and I recommend people give it a try.

Java 9 Upgrade

After upgrading my test app to Spring Boot 2.0 yesterday I decided to see how difficult the Java 9 upgrade was from there. I am happy to report that it was fairly trivial. I upgraded my maven pom to set the Java version to 9 and did a mvn clean install.

Immediately I see some no class def exceptions around javax.transaction.Transaction. I did some quick google searching and discovered the problem seems to be in the Maven Surefire plugin. I found a work around that said to set the version to 2.20.1 and added a command line flag of –add-modules javax.transaction. After doing that I was seeing errors around java.xml.bind. Doing some more searching I then added a second –add-modules java.xml.bind. This fixed the issue. In the course of doing so I found a link to the issue on apache’s website. Reading through the comments I ended up with a final configuration of 2.21.0 with the following options:

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.21.0</version>
            <configuration>
                <argLine>--add-modules java.xml.bind</argLine>
            </configuration>
        </plugin>
    </plugins>
</build>
Once I dropped that configuration into my pom everything built and ran correctly. So once you get your app to Spring Boot 2.0 the jump to Java 9 is pretty seamless. My follow up change now will be to switch to the new factory methods on List and Set in the app to take full advantage of the features. Once Java 10 drops in a couple of weeks, I will take the App to 10 and see how that goes.

Spring Boot 2.0

Spring Boot 2.0 has finally arrived. Unfortunately we aren’t yet in a position at the office to be able to begin the upgrade so I decided to start playing around with it on one of my projects at home as I didn’t want to wait until we were ready to update our app.

The first thing I noticed about it they removed findOne() from CrudRepository. This to me is a bad change for all the users of the framework. It is one of the most commonly used methods in Spring Data, and not people either have to refactor their code to use findById() which returns an Optional<> of the type and deal with the optional instead of a null or you have to add a findOne with an @Query to all of your repositories. I have worked on projects in the past that have hundreds of tables and Repositories. This change is forcing them to update hundreds of classes just to upgrade to Spring Boot 2.0. It seems to me a better choice would have been to @Deprecated on findOne and encourage people to upgrade to the new findById method.

The next breaking change I found was also in Spring Data. They removed the delete() method from CrudRepository that takes an ID as the type. It has been replaced by a deleteById() call. There is no good reason for this change. In Java we have method overloading so the language can determine whether to invoke delete() with the Entity or delete() with an ID. It seems like they were trying to be consistent with findById() but they just end up breaking a bunch of code in the process. The only benefit that I can see with this change is groovy will get happier as it seems to be very poor at understand overloaded methods.

The next change I noticed was when calling new PageRequest(page, size) it was telling me that constructor was deprecated. To me this is the right way to handle the situation. I clicked into the method and it suggested to use PageRequest.of() instead. That was an easy fix that I made and seems more consistent with Effective Java about using static factory methods instead of constructors.

Finally I got all my unit tests updated to replace the findOne calls with the findById changes I had made and I went to launch the application and Hibernate fell over. It looks like the new version of Hibernate requires me to specify a GenerationType of Identity with MySQL where before it didn’t force me to specify it.

All in all it wasn’t too bad to upgrade my toy application. I am really looking forward to using Spring Boot 2.0 going forward, but a little disappointed by some of the Spring Data breaking changes. I feel like this could have been transitioned in to make it easier to upgrade existing Spring Boot 1.5.x applications. It is interesting that 2.0 is the first release to support running under Java 9, and it is finally released a month before Java 9 goes away and Java 10 is released. Up next for my test application will be switching it to Java 9 to see if I see any issues with that.

Upgrading to Java 9

Upgrading to Java 9

Ever since Java 9 was released last fall, I have been wanting to upgrade our software at work to the new platform. I am not interested in the new module stuff, mostly I just want the convenience methods like List.of(), and the platform improvements. I think G1 by default looks good, the new representation for strings to save memory looks like a huge win, and all the performance numbers that I have seen show it to be a big win. Unfortunately this is not as straight forward as one should hope.

Step 1 – Spring Support

Even though Spring 5.0 was released back in December I think which fully supports Java 9, Spring Boot 2.0 is not yet released. I believe it is in RC2 now and about to be released in the next week or so, but at this point we are less than a month away from Java 10, before we will have proper Spring Boot support in Java 9. All of our microservices are currently running on Spring Boot 1.5.10 except for one. It is still running on the 1.3.x version of Spring boot, which brings us to our second Spring issue to resolve. Some contractors that originally started that service did a hack to lazy load @Formula s in hibernate. While this worked in Hibernate 4.x in Hibernate 5 the hack no longer worked so we can’t even update this service until we refactor those entities and move that data into views. That is still a work in progress. The other microservices could be moved to 2.0 when it comes out, but I think their is a consensus that we don’t want to move to 2.0 until we have all our services to a place where we could do that.

Step 2 – Gradle

We are currently running gradle 3.5.1. Going to Java 9 is going to require Gradle 4.2 (which is also a requirement for the Spring Boot 2.0 Gradle plugin). Normally this is no big deal upgrade the gradle.build file edit the wrapper portion to the new version run ./gradlew wrapper and check in the new gradle wrapper. But in this case we still have a developer running on IntelliJ 2016.1 and another on 2016.2. They would have to upgrade to at least 2017.2 in order for the new gradle to work with their IDE. So we will need to convince the whole team to update their IDE if they haven’t already ideally at that point to 2018.1.

Step 3 – FlywayDB

We are currently using Flyway DB 4.2.0. This didn’t work with Java 9 when I was testing it, so we need to go to 5.0.x. Additionally Spring Boot 2.0 requires Flyway 5.0.x. Ideally we want to upgrade this ahead of Spring to minimize risk. Bring the new flyway into production and then once we are satisfied that it doesn’t break anything upgrade Spring Boot.

Step 4 – Docker Containers

Once we have all that software in place we then will have to update our docker containers to pull in the new JVM. It sounds like in Java 9 Linux, OpenJDK ships with an empty certificate store. So that means finding a Oracle or Azul docker container as our base. We then have to verify that New Relic works with Java 9 so we have our container monitoring. After doing all that we can update our base VM to be Java 9.

Step 5 – Update Jenkins

We will need to add a new VM to Jenkins so that as different builds switch to the new Java 9 container we also switch to compiling them with the Java 9 VM (though with the Java 8 flags still at this point).

Will the pain never end…

Finally after doing everything listed above we could change our compiler flags to 9 and start using the features. It is still a painful road to walk to get us there. At this point it feels like by the time we finish the work that needs to be done (as obviously we need to be shipping features and bug fixes, while we lay the foundation for this on the side) Java 11 will be out and we will be moving to that.

Even though Java 9 support is so close to being out in Spring Boot I still feel like I am at least 6 months away from getting to use any of it. This feels much more painful than when I moved an App from Java 7 -> 8. At that point I think it was just a matter of coordinating a JBoss container upgrade from 6.0.1 to 6.4. After we got that into production we updated the VM to Java 8 (still with everything compiling on 7). Then we upgraded our Jenkins machine to have Java 8 for the compiler, and finally we updated our maven pom to use source and target of 8. I wonder if anyone Spring shops will even make it to 9 or if everyone is holding out for 11 at this point (also to get the LTS release). While I really like the sound of the 6 month release cadence actually getting the dependencies in place and lined up to do an upgrade will probably mean most enterprises just end up going from LTS release to LTS release and I would guess that Java 9 and 10 see very little use running production code and mostly will just be things for developers to play with on their machines.

Themes for 2018

Introduction

As is tradition on this blog I always lay out some themes to focus on for the upcoming year. These were last years themes if you want to get an idea for the types of things I usually do. I haven’t spent as much time as usual pondering my list this year as I was very busy over my holiday break (at the start with sick kids, and at the end with lots of family activities). Given that today is my last day of vacation I decided it is time to get some things written down. Here are my themes for 2018.

Theme 1 – Health

I started out last year wanting to drop about 50 pounds by my birthday in July (just to get healthier before I turned 40). I managed to lose 30 before my birthday, and then sort of fell off on it in the second half of the year so about half of that came back. So I want to make the same push this year and try to get down to around 200 lbs by my birthday and I am working on my approach. Way back in the day I tried weight watchers and was very successful with it, but always felt hungry on it. Several years later I experimented with the primal diet and found it to be way more effective for me than weight watchers, but a challenge due to limits on foods that you can’t really eat. Last year I lost all that weight following slow carb diet from the 4 hour body. The big advantage of that diet is that you get a cheat day so anything that you really crave you can have once a week. I will probably be doing something between primal and slow carb.

Along that line of thinking one of the priest’s blogs that I follow is doing a program he is calling Nineveh 90 which is sort of his program for physical, mental and spiritual health. He launched it on January 1st and it goes up through March 31st (Holy Saturday). Kind of a lent on steroids. I decided I was going to adopt components of it myself, but not starting until today the 7th as I prefer to celebrate the Christmas feast for the entire 12 days of it.

The components related to physical health that I will be trying to follow in conjunction with eating better are:

  • Regular and Challenging exercise. Not sure I will hit the challenging part, but I will at least try to get close to my 10,000 steps in every day and maybe walk the dog more than usual.
  • At least 7 hours of sleep. I often get tempted to stay up late when reading or when working on some sort of problem and I will try to be diligent and get to bed by 11pm.
  • No alcohol – I enjoy a beer at night generally with my dinner, so I will be cutting this out (which should help cut carbs). I will still allow myself a drink if I am out, so that I can still participate in my neighborhood brew club and if I am out for my wife’s birthday or our anniversary or valentines day which will fall in there I can still have a drink. This should cut a lot of calories and carbs for me as with 4 little kids I don’t get out much.
  • No desserts & sweets – I don’t have much of a sweet tooth so giving up desserts & sweets until Easter is doable, though with the caveat of exceptions for birthdays, anniversary, and valentines day.
  • No eating between meals – This one is going to be more of a challenge. I have gotten into the bad habit of nibbling on a slice of cheese here or a little of this there. This should do a lot to cut out sort of bored snacking, and help me drop that extra holiday weight.
  • No soda or sweetened drinks – This also isn’t much of a challenge. Occasionally I enjoy a root beer float, but those are few and far between so no soda until Easter is easy (and I don’t sweeten my coffee).

So those are the physical health components to the Nineveh 90 stuff that I will be following. There are other aspects related to spiritual aspects as well. I will be adopting some of this as it seems like a good challenge for the start of the year and sort of an extended lent this year. In the original program you can relax the discipline on Sunday and Solemnities, but I will be relaxing the discipline instead as I noted above. The relaxed part sort of reminds me of the cheat day in slow carb, relax one day a week so you can keep it up the rest of the time. The final component he lays out is fasting on Wednesdays and Fridays. He suggests bread and water only if you are medically fit otherwise standard Catholic Lenten fast. I think I will probably fast and only do water and coffee on Wednesdays and maybe not eat until supper time on Friday (since Sofi and I usually eat something together on our Friday nights after we get the kids to bed).

Theme 2 – More blogging

This is sort of an annual one for me. But generally I try to make it a priority anyway. This does compete for a limited slice of time though. After work generally I Am busy with the kids for a couple of hours. After we get them to bed I still need to walk the dog and get some exercise in and hang out with my wife and try to read, and sometimes do a bit of work. So this one will continue to be bumped as it needs to, but I will try to stay in the habit and find some time on the weekend to work on a post here and there.

Theme 3 – Learning

This for me means lots of books and playing around with ideas on the computer. I have just started Effective Java 3rd Edition and it is great as expected. I haven’t quite gotten to the part about the updates for Lambdas and Streams, but I look forward to seeing the insights there. Other things I am playing around with on the learning side are messing around with a bit of Swift. I have a udemy course I was working on for iOS development under Swift. I did some over paternity leave and would like to play more with it. Also have been playing around with Kotlin some. I like most of what I see in that language. Maybe I will do a Java vs Groovy vs Kotlin type post about what I like or dislike about each of the languages. I think Kotlin gets nearly everything right, except for having classes final (not open) by default. I think that was a mistake. I have always been looking a bit at Node.js and Express just because of all the hype it is getting and I want to play around with the newer versions of Angular and the whole progressive web app concept, since I spend most of my time at work focusing on backend development.

Theme 4 – Architectural changes at work

I have already started some of these this fall. Part of this will be shifting more of our app to Java away from Groovy. I think Groovy in an enterprise app is a mistake. It is the opposite of fail fast, instead the compiler hides errors, and it just feels dated after using Java 8 / 9 features. Their closures are inferior to lambdas and streams, and the tooling around the language just isn’t that good.

Included in these architecture changes will be trying to get our services updated to Spring Boot 2.0 when it finally releases and then shift to the Java 9 or 10 platform (instead of 8). I would also like to look into rolling out the SonarQube build breaker to enforce our coding rules, that has worked well for us in previous companies that I have worked in.

Conclusion

I think working on these 4 areas will be plenty to keep me busy this year. If I am diligent about them it should also give me topics to blog on. I started this post on the 7th, but I had to finish it up tonight. My year is already starting out busy and I don’t expect it to slow down at all from here. Happy 2018 everyone!