A step towards more ecological software development

Have you ever wondered if you, as a software developer, can do more to reduce your carbon footprint? What about the carbon footprint of all the apps you’ve deployed? 

Generally, in software development, you don’t hear a lot about this topic. But why is that? Can we not make enough impact? Is it even worth putting some effort in? 

Changing mindset

There are a lot of aspects in which software can be made more efficient, in order to reduce the computing power needed. Database queries can be made more performant, extra roundtrips can be avoided, unnecessary data doesn’t have to be stored, redundant calculations may be removed, log retention and the amount of logs could be reduced, multiple application instances running simultaneously could potentially be scaled down,… You name it. But do we actually care enough? Usually, when we think of improving these things, we usually do it to improve user experience, but rarely do we think about the ecological impact. We can actually change that. Let’s be a little more conscious in how we technically design our applications. The more of us who think about it, the more significant the overall impact can become over our shared application landscapes.

 

The trigger

To be honest with you, I didn’t always kept the ecological point of view in mind while developing applications. Sure, I thought about performance and log retention, caching were it would be advantageous, reducing round trips, introducing indexes in database queries, but I didn necessarily have the ecological footprint of the application in mind. But then I came accross an interesting post on LinkedIn, that changed this:

This immediately triggered me, and I went on to watch the Devoxx presentation on YouTube, which I truly recommend watching:

Green scheduling

Let’s talk a bit more about the software in the conference talk.

What is it? In a nutshell, it is software that allows you to schedule recurring tasks, like nightly jobs, considering the carbon intensity at the planned execution time. The aim is to run the task at the most opportune moment, being the window of time where carbon intensity would be at its lowest point.

Currently, the software consists of a propriatry API (maintained by First8) as well as an open source Java library. There are plans to support more programming languages in the future. Currently there is already support for the Spring and Quarkus frameworks.

The API is in charge of calculating the most desirable window in which to execute a given job, for a given time zone and region. It also takes an expected duration amount into consideration. Currently, the API is free of charge, but you do require an API key. You can easily set it up though, do go through the steps as documented on their Get Started page.

The library provides the annotation, its processing and the logic calling the API and the scheduled job management.

You are most likely already familiar with Spring’s Scheduled annotation, where you would define recurring jobs like so for example:
@Scheduled(cron = "0 0 2 * * ?", zone = "Europe/Brussels"). Using the library’s equivalent annotation, you would define that like so:
@GreenScheduled(fixedWindow = "02:00 08:00", carbonIntensityZone = "BE", duration = "1h" timeZone= "Europe/Brussels").
Note that instead of always running the job at 2AM, now we specify a time window. The carbonIntensityZone maps to a region as defined with ENTSO-E, from which the API consumes data. You also see that we need to pass a duration parameter, this is mandatory at the moment, and can be a rough estimation of the time the batch job would need to complete. Perhaps, this will be made a bit smarter in the future.

An example I’m personally already using in a hobby project:

@GreenScheduled(
fixedWindow = "01:00 23:00",
duration = "1h",
carbonIntensityZone = "BE",
timeZone = "Europe/Brussels",
dayOfWeek = "MON"
)
public void cleanUpArchivedLogs() {
// Log cleanup code omitted
}

As you can see, there’s different options for defining when the job has to run.
Of course, you would have to use this mindfully. If the job you want to execute is required to run at a specific time (do ask the question: why?), this approach doesn’t fit your case. But for jobs, like the above, where the execution time is not that important, go for it!

Now, imagine the impact it would make if all of us would consider something like this when setting up scheduled jobs. Every job can literally contribute in reducing the carbon footprint.

Even considering the downside of the extra API call and the computing power required for it to come up with the most suitable execution time, we will usually save more carbon, given we setup wide enough windows.

However, the supported regions, at the time of writing, only include ‘NL’. First8 (a Dutch company) does however plan to support a lot more regions, but the timeline on that is not yet very clear. If you are interested in support for a given region, do contact them to request support for it.  

Do not hesitate to contribute to the project on GitHub. The team is welcoming any change or improvement and they setup very easy-to-follow setup and contribution guidelines.

I’m playing around with the software myself. I’m evaluating wether it is ready for use in production applications (mostly region support seems to be lacking).
I’ve also contributed 2 minor changes to the library to show my support:
Implement Autocloseable on schedulers
Javadoc improvements

Green energy production often relies on multiple weather factors like, sun, wind, rain (for hydro plants),… And this little piece of software tries to make better use of that.

Moving forward

The green-scheduler I’ve just ellaborated on is of course not the only answer to improving our shared carbon footprint. It is a good step in the right direction. It makes us reflect on what we can do better. And that’s exactly it, that’s exactly what we need to start doing a little bit more.

Do you have suggestions to further improve ourselves on the topic? Or are there already other things you are actively doing to make an impact? Do let me know in a comment, I would be very interested in hearing about it, or to start a conversation!

Adjust Loading Animations in Vaadin

By default, loading animations in Vaadin are already pretty awesome, though you might want to adjust them to make them fit better with your custom theme.

While tweaking around with the animations myself, I found that there wasn’t too much information to find about it around the web, so here’s me contributing.

It’s All CSS

To adjust the loading animations, there’s actually no need at all to fiddle in Java code. Everything can be easily set up in css. You only need to edit one file, which would be your custom theme’s scss file.

First of all, it is important to know that the styling for the animations is not located under the .v-app class. All the editing can be done top-level, right after the base theme include statement. For the Valo theme, this would be right after the following line: @include valo;.

Top Loading Indicator

In this example I will cover a minor tweak to the loading bar you see on the top of the page, which by default is blue. It is displayed upon page navigation.

To simply adjust the color you can use following code snippet, where all style attributes are just coppied from the default styling. The only property you’ll want to tweak will be the background-color one.

.v-loading-indicator {
    position: fixed !important;
    z-index: 99999;
    left: 0;
    right: auto;
    top: 0;
    width: 50%;
    opacity: 1;
    height: 4px;
    background-color: red;
    pointer-events: none;
    -webkit-transition: none;
    -moz-transition: none;
    transition: none;
    -webkit-animation: v-progress-start 1000ms 200ms both;
    -moz-animation: v-progress-start 1000ms 200ms both;
    animation: v-progress-start 1000ms 200ms both;
}

Connection Lost Spinner

Since we’re at it, we might as well adjust the color of the spinner that shows when the connection was lost. Once again, this snippet must be placed outside the .v-app class. Obviously, if you want to adjust all spinners application-wide, apply the styling to the .spinner class only.

The resulting box with spinner.
The resulting box with spinner.

.v-reconnect-dialog .spinner {
    border-top-color: red;
    border-right-color: red;
}

Centered Loading Spinner

Vaadin’s default spinner is shown upon page refresh, for instance. At least in the Valo theme, it is relatively small. Its’ styling is somewhat basic, so it might be good to give it a more customized touch, like the spinner below.

A custom loading spinner.
A custom loading spinner.

Right along the previously provided css snippet, another one can be placed. Following example shows how to replace the default spinner with our own.

.v-app-loading::before {
    opacity: .8; 
    filter: alpha(opacity=80); 
    width: 100px; height: 100px; 
    background: transparent url(../customtheme/img/spinner.gif); 
}

Update the Vaadin Theme

After these small tweaks in this one file you are all set and ready to check out the result of the applied changes.

Keep in mind that you will need to update the theme first. Vaadin has this Maven plugin com.vaadin:vaadin-maven-plugin:8.0.0, that you can add to your pom.xml. Once added, you can simply update and compile the theme and rebuild your project. Besides that, you will probably have to clear your browser’s cache before reloading your application. If you don’t do that, a previous version of your theme’s css file will be used.

Happy Holidays – 2016-2017

It’s that time of the year again! Holidays are coming up along with the usual festivities. Here’s about my past year and what’s to come in 2017.

Looking back

Overall 2016 was a great year. The major highlight was getting started on my first full time job in Antwerp, Belgium. This was the biggest change in my life so far. I’ve learnt a vast amount of things on the office floor, and that’s more than only technical stuff. I was lucky to work with some very interesting and intelligent people, that enriched me all along.

Whirlpool Rapids
Standing in front of the Whirlpool Rapids defining the border between North America and Canada.

Another big highlight would be the trip I made with my family to Canada during the summer. I’ve never been this far away from home, but I had a great time. Would definitely recommend.

Besides all that great stuff, life went as life goes. There were awesome moments, moments of joy, as well as less pleasant moments.

A new year, new challenges

2017 Will bring more changes. Early January you can expect a small update on my homepage and LinkedIn profile. What I can say is that Java programming will be the core of that change (at my great joy). This will also involve studying for some certificates (including OCA and OCP). Once again, I expect 2017 to be a very enriching year, in general.

You can expect more updates on this blog as well. Most updates are likely to be Java-related and somewhat technical. These updates will be published as I see fit. There’s no need to publish when there’s nothing noteworthy to share. Besides tweeting new articles, I will also share them on a few additional social media. Whenever you’d like to engage with me, I’ll always do my best to read and reply.

Happy holidays and an awesome 2017!

In Depth Test Reporting with Allure

Always wanted to do test reporting properly? Allure, an excellent framework to properly report your test runs does just what you’d expect from it.

Test run overview in Allure
Test run overview in Allure

The main purpose of Allure should be clear. It provides in reports, graphs and different types of overviews (including optional attachments and links) to present the status of your System Under Test (SUT).

Allure in a nutshell according to it’s developers:

A flexible, lightweight multi-language test report tool, with the possibility of adding to the report of additional information such as screenshots, logs and so on.

Lightweight and lightning fast, it is, the framework can generate a report site in less then 2 seconds (mvn site). The list of programming languages and test frameworks you can use with the framework is impressive as well. Don’t worry, all the big ones are definitely covered!

Core Functionality

In fact, the features Allure offer are limited, but that’s also it’s great power. Allure tends to make use of Annotations. An example of one of those is the @Step annotation. When a method is annotated with it and the method gets called in one of your tests, it will be included as a reproduction step in an issue overview. You will be able to see when the step started and how long the execution of it took.

Similarly, you could attach screenshots, los, JSon, XML, … To your failed tests for later reference.

@Attachment(value = "Page screenshot", type = "image/png")
public byte[] saveScreenshot(byte[] screenShot) {
    return screenShot;
}

Furthermore you could arrange different test cases under features and stories. This is purely to add some structure to your reports. Make use of @Features and @Stories annotations on your test case classes and/or methods.

Side Info

You could always dig into an example report to see what the end product looks like.

Another interesting thing to note, is that Allure is an open source project initially developed for Yandex, a Russian Google Chrome variant for internal testing. Find it on GitHub. They now claim thousands of software testers are giving the Allure experience a high note and that it’s being used all around the globe.

You would be silly not to take a look at it, as it is such an incredible easy setup, but a tool that can help you, your co-developers and even your product owner(s) (as they might want to get some insights at some point during development). Presenting a snapshot of the SUT status is done in no-time. A good approach would be to generate a new report after every CI build and iteration.

Basically all you need to do:

  1. mvn clean;
  2. mvn site;
  3. mvn jetty:run (as the front-end can be displayed locally using Jetty).

Those are all Maven commands. Make sure your dependencies are all in place in your pom.xml and you are good to go.

Why Blocking Root Users Is a Bridge Too Far

Rooting your Android phone, shady business for some, pure satisfaction for control freaks and customization lovers. Among these root access privileged users there are obviously a bunch of cheaters and hackers we should be aware of, but there are also a lot of legit users.

 Disputed Pokémon Go Update

Niantic‘s immensely popular game, Pokémon Go recently got an update that blocks devices that are granted root access. From now on, users with elevated rights are not allowed to play the game anymore.

pokemon goDefinite and potential cheaters are avoided from disrupting the intended gameplay, which obviously is a good thing. The downside though, is that all the legitimate players that happen to have rooted their device are now duped.

The result of those duped players not having access to their beloved game must be rather significant. The sales coming from in-app purchases will be directly impacted as less users can buy in-game goodies. The somewhat more indirect impact would concise of negative 1-star ratings on the Play Store. Fora get filled with negative user feedback, people will start discourage others playing the game.

On another note, it is a bit of a strange decision on Niantic’s part, considering they have already built in descent cheating protection. That would be an expertise learned from their previous game, Ingress, which shows a lot of similarities to Pokémon Go (as it is also a positioning based game). People trying to spoof their GPS location are likely to be banned, if they even managed to properly spoof the device’s location. That is a good way to remove the unwanted players from using the app.

Limiting the User Beyond 1 App

If one application blocks the rooted user, they are basically discouraged to continue using their root-required apps and features. A company should not decide for it’s users whether or not they can use rooted Android devices.

Imagine what elevated access can do. It allows one to completely customize their Android livery. Tiresome adds can be removed using ad-blockers, CPU usage and performance can be tweaked. Want to open your favorite music app as you plug headphones in? Guess what you need, root access. There are plenty more reasons why one would want to root his/her device.

Hacky Work-Arounds

What would you expect, root guru’s to stop finding tricky solutions to bypass this kind of issue? There are already quite a few apps that can hide your Su binary. Those however, don’t always do the trick.

Some people like to use something like the Xposed Framework to ‘cloack’ root from specific apps. Others like to go over using the game-changing Magisk.

 

The Importance About Globalization

When you are working on any kind of project, you should globalize it. Except if you have a very specific target audience of course. The importance of globalization in general is enormous.

globe

More than Localization

When we are talking about globalization we are talking about much more than simply localization (which would mainly consist of translating your program). You could say that globalizing your application would mean to make it accessible to users all around the world.

Does your program come with any kind of currency handling? Guess what, you should add support for foreign currencies. Another marvelous example: date formatting! Worldwide there are quite a few different date representations. Make sure you display dates in a matter that your end user is used to.

Try to view the big picture. Apply country-specific standards (representation of VAT numbers, bank account numbers and specifications, address (and zip code) notations, …) as often as possible. But be aware of one downside: data conversion might be needed in some cases. Make sure you are prepared for that (foresee some good old converters).

Increased Target Audience

Imagine what impact a proper globalization implementation might mean for your target audience. Guess what, it will vastly increase and thus result in more sales. Now go improve your conversion rates!

Is it Worth the Effort?

I can already picture programmers and project leads thinking why they would even bother to put in the extra effort to globalize their project(s). Globalizing does indeed take up some time. In fact, you could say most of the time would have to do with the initial setup. Once you get it going, you only need to update your existing resources every once in a while.

The extra effort put in should not be a factor. The value of your application(s) improves so greatly that this minor efforts are really no argument for not having a globalized project. Don’t argue and do it already!