Publishing the v2.0 of my Excel timesheet

The origins

Why, oh why?

I am a consultant developer. This means I move from client to client and share their time constraints. This includes deadlines, but also work time.

It so happens that some clients have a time clock, like in the old days.

Time clock in the Museum at Wookey Hole Caves (Source: Wikimedia)
Some have these time clocks…
Electronic clocking terminal (Source: Wikimedia, February 2009)
… but this is more likely.

My problem is: while most of my client’s employees can see what the clock stores, I, as an extern, cannot. I do not like to be blind, so each time I am in this situation, like many people I know, I make an Excel sheet where I log my check-ins and -outs.

Sharing my timesheet…

On my latest mission, we were several on the team from the same company. I spent some days without my usual timesheet and when I grew tired, I sent my first basic version, with some conditional formatting, to all members there.

Since they did not seem very interested if I asked whether something standard was available, I did not expect much. But instead, I quickly got some feedback: they asked new features, signalled some bugs, …

The team grew, the requests followed. The possibilities of the timesheet were ever greater, and therefore so was its complexity.

… with the whole world

Finally, using e-mails to track the feedback and release the changelog and user manual became too heavy. I thought of a bug tracker. This led me to create a Github repository. The wiki would come in handy for the user manual too.

Thus the work on version 2, which should make the sheet less specific to our context and more widely usable, began.

And now version 2.0 is here!.

The construct

Choosing the format for storing revisions of the timesheet

The choice of using Excel for the timesheet comes with a consequence: the file we edit is a binary. We know one thing about GIT (and most RCSs) is that it is not that efficient with binaries.

But we also know that a .xlsx file is just a zip of XML files, so we chose to save it as the exploded version of the .zip file.

The only thing we lacked was a way to easily switch to and fro between both forms.

Searching for the tool

I ambitioned at having one script that could be used with an argument to do this. It is easy in Unix. I even found a solution using PowerShell for Windows. But this required to maintain two scripts.

I looked at the build tools I know and some I did not: Maven, Gradle, CMake, …

But all these are oriented towards a specific technology and all of them require to install something on your computer.

Making the tool…

I am a developer after all, and this is within my area. So I went for an executable .jar. Only thing you need to have on your computer? An up-to-date version of Java.

And I came up with a basic Swing interface.

The construct
The construct

It may not look like much, but it does the job…

… and enhancing it

… and it will do more.

Do not hesitate to head over to the repository and fork it to tailor it to your own needs or make this one better.

In the end, it will make developing the xls-time-tracker timesheet and managing its versions easier.

Just wait and see…

Use StringBuilder, not StringBuffer

Java comes with two similar utilities called StringBuffer and StringBuilder. The latter was introduced in Java 5 and here is what the API doc says about it:

[StringBuilder] provides an API compatible with StringBuffer, but with no guarantee of synchronization. This class is designed for use as a drop-in replacement for StringBuffer in places where the string buffer was being used by a single thread (as is generally the case). Where possible, it is recommended that this class be used in preference to StringBuffer as it will be faster under most implementations.

So, in a nutshell: StringBuilder is a non-synchronized StringBuffer (and is, as a consequence, faster). When does it make sense to use a StringBuffer therefore? The only case I see is when your buffer is a field of a class used by several threads. I must admit I do not see this case.

I often see a StringBuffer created inside a method which will return a String, or passed as a parameter to a method, and my first reflex is to change it for a StringBuilder.

Trivia

Did you know that when you write:

Your compiler replaces it with something like:

If you did not, well, now you know how to optimize your code regarding to String construction: append all in one time or manage the StringBuilder yourself to avoid creating and releasing many instances, which leads to poor performances.

Image courtesy from Alcibiade (CC-Attribution 4.0)

CRONs for Java: crontab4j

The first pre-stable version of my latest project crontab4j is now available.

What is it?

The name is plain enough: it allows you to schedule Java jobs using CRONs.

Before going further, keep in mind this version is a WIP. For instance, I heavily use regular expressions now (I love regexps), but I plan on moving to grammars to make things more scalable and easier to debug.

You said available?

Well, right. You can get the sources and compile it yourself, as any Maven project.

I might publish it to Maven later, when I get a stable 1.0.0 version. Until then, you will have to build by your own means.

Doesn’t it fit into the yet another category?

What does not, nowadays? Yes, I know of two other tools which can do the same.

Quartz

Quartz is the well-known Java scheduling library. It is not CRON-centric, but it is powerful and integrates nicely inside a Spring context.

This is why I actually suggested, but my boss thought it might be too much for a simple job. So I took the challenge and wrote a simple parser for him. And made something more elaborate on the side.

So, is it really lighter? It does less things, so it better be! At the current time:

  • Quartz: 645 KB
  • crontab4j: 45KB

And this does not include the transitive dependencies: the goal was to get rid of everything useless. Quartz has been progressing on this aspect, but just before version 2, it had nine dependencies, not counting the transitives. Now it only has two. I must wait to have a stable version before bragging.

cron4j

I did not know of cron4j before I looked to see if the name was already taken, which made me choose crontab4j to avoid confusion.

So, why did I persevere in making crontab4j? First, because I already had taken up the challenge. Second, because I keep in mind that most Java applications today use a Spring context, and therefore need compatible tools, which I aim to provide.

What’s next?

I have established a roadmap, you can see it along with the rest of the project: https://cychop.github.io/crontab4j/.

More to come…

How to determine the best implementation of a Java method

Short answer

  1. Write alternative versions of the method you want to test. They should be named as the original, and suffixed with an index. The rest of the signature must not change.
  2. Download the java-implementation-comparer project from Github.
  3. Build it to add it to your local Maven repository: mvn install
  4. Create a test project importing both:
    • the project you want to test;
    • thejava-implementation-comparer:
  5. Create a test class and write the little code you need:
  6. Just enjoy your comparison:

Something more detailed

Continue reading How to determine the best implementation of a Java method