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.


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)

Idea for a keyboard adapter

The case

Keyboard layouts are numerous. Some time ago, friends of mine tried to persuade me to settle for a Dvorak layout. They proposed the BÉPO, though the programmer Dvorak would be more adapted to my professional life.

The idea was attractive. I never settled, though. Why, do you ask? The answer is simple: to be efficient on a keyboard, you need to know its layout by heart and be able to blind-type. This comes naturally after some practice.

However, switching to a keyboard layout has a learning curve. I would not mind if I were able to use the same layout everywhere, but when at work, I must comply with the hardware and rules (“Do not change the configuration of your machine! Get accustomed to your keyboard.”). And sometimes the access restrictions too (“Your rights are not sufficient to configure your clock.”).

In my not-so-long career, I have already had to use several variants of AZERTY and QWERTZ. I sometimes guess type on the Alcibiade‘s laptop, which is an AZERTY configured in international QWERTY. And then I come home and meet yet another variant of AZERTY.

How then to go and try to learn yet another layout?

One time when confronted with a QWERTZ and the explicit order not to change my configuration (as it could mess things up if they ever needed to remote control my machine), I imagined something.

Continue reading Idea for a keyboard adapter

Some thoughts on UX

A year ago, our company tried to put up a team specialized in UX — we dubbed ourselves the UX Avengers, hence the illustration for the post — and wanted its members to trigger some awareness in other developers about the associated issues. This post is translated from the introduction I wrote for the first newsletter we sent.

What is UX?

This notion is sometimes blurry and often confused with UI. UX is the short for User eXperience. According to Wikipedia and the ISO 9241-210 standard, it is “a person’s perceptions and responses that result from the use or anticipated use of a product, system or service”. The name defines the notion.

Obviously, better the experience is, better are the satisfaction and acceptance of the application.

What should you focus on to make your app’s UX better?

The interface

There is a reason UI and UX are so easily confused: the interface is the only thing the user perceives of the application (the look-and-feel). He might be more willing to spend some time on a sober and aesthetically pleasing screen than on a colorful and overloaded screen.

Dilbert designed a UI

The ergonomics

We just spoke about it, though you may have failed to realize it: a screen, as beautiful as it is, cannot be crowded with controls. Your application must be easy to apprehend and understand if it is to capture the users. It is the biggest secret of some well-known companies…


The technology

Even if you have the vision, you need the tools to make it concrete, preferably in an elegant way. The arsenal at your disposal is very wide and evolves rapidly. One of the purposes of this newsletter is to allow you to keep in touch with the latest evolutions.




How to prevent IE from messing with console.log

Short answer

  1. Add the following before any use of console.log:

    Or (which is OK with JSHint’s undef rule):

    Or make a log function that will not add a potentially useless object and that you will use instead of console.log:

    (or just make sure you do not use console.log)

Something more detailed

Continue reading How to prevent IE from messing with console.log

How to download a plugin-free Eclipse platform

Short answer

  1. Go to the dedicated download page.
  2. Select the version you want and click it (column: Build Name).
  3. Go to the Platform Runtime Binary section (available in the table of contents or by adding #PlatformRuntime at the end of your URL).
  4. Click the runtime corresponding to your OS.

Something more detailed

Continue reading How to download a plugin-free Eclipse platform

The Cost of Time

This morning, I arrived at work, booted my machine and launched the core applications I need before even thinking of starting to work: Outlook, so that I can read the e-mail I might have received, Chrome, to see what is new in JIRA, and of course Eclipse which will be used for all development.

Can you guess how long it took to boot and launch only those three? 10 or 15 minutes. Not so much. Just a quarter of an hour lost before even beginning working.

And even once all this was finally up (Eclipse easily took three full minutes), just reading and answering e-mail was a pain. Opening a new tab in Chrome made me wait twenty seconds before I could begin typing in the omnibar, my input for a new message in Outlook had a delay of several seconds, …

It is my (maybe not-so-humble, sorry) opinion that when a developer is faster than his/her machine, there is a problem.

At home, booting1 takes two minutes (half of it being after Windows started). That is already undoubtedly faster than what I have at work, but applications launch in a few seconds too, and they never lag once they are up. Admittedly, I have a killer machine (there was a reason for buying it, even if it is gone now).

But that gives some thinking: lost time is lost money for a company. Which is the most advantageous between losing developer time or buying a efficient machine?

Continue reading The Cost of Time

About writing (and coding)

I always wished I had an artistic talent of some sort. Lately, some friends of mine even diagnosed me to be a latent artist.I

The truth is however that I do not have this apparently innate facility which impresses us so strongly. I cannot draw, I sing out of tune and I am unable to play any instrument.

Yet, those artists which impress us would be the first to remind that what seems to be so easy for them is the fruit of hard work. I tried to begin working on those. I draw simple things sometimes but it is not very convincing yet. A friend of mine makes me notice each time I am out of tune, and I even bought a guitar from a friend (though I did not find the time to learn how to play it yet). There was a time when I edited videos as a dilettante, too, and the result was generally much appreciated, but taking time to make the slightest detail right made the editing of a video quite long.

I cannot believe I will be a performer in any of these arts. There is one last art I always felt attracted to: writing. I even tried some poetry when I was younger. I was proud of it at the time, but it was just child-written poems. I tried again later, with variable degrees of success.

My closest friend often asks me to proofread her written works, and thinks my writing is “excellent” (this is the word she used), but I never wrote any long fictions. I sometimes began some drafts, but always abandoned them soon after having begun.

Plus, writing takes three things: time, motivation/energy and inspiration. The hardest thing to find for me is inspiration. I usually have a beginning or a main idea, but generally no idea of where I want it to go or end.

Time is another difficulty: in today’s life, finding a slot you can use for yourself (while preserving enough sleep) can be a challenge. And the third problem is that often, when I manage to find time, I am usually worn out.

But then I realized: writing is what I do for a living. Not in a language most people can appreciate, not in a way that will make me recognized for any artistic talent, but still. Coding is writing.

Taking some words and punctuation, starting from nothing, assembling them in a correct way, you just create something new for others to enjoy.

There are all the same problems. You have ways to mistreat the language, and you also have several correct ways. And of course, you have some beautiful way, which are those I hope to find when I am coding. Of course, mastering the language when writing code and when writing fiction are not the same things.

The point is: I am already writing. And this is what I love about my job: when writing, I usually lack the inspiration, and I wish I had an idea tank to develop upon. At my work, I am given the ideas and asked to write them. There are constraints, of course, and sometimes I am not allowed to search for my ideal syntax, but on the whole, I just found a job matching my vocation.

Now I wish to write things anybody can read, so I will have a new take on some fictions I have been nurturing in my head for some time. Not sure I will not abandon them in some weeks too, but I will never know I if do not try. Ideas are getting more complex, and at some point, they must be shared, proved against a touchstone, and I guess I will never know their value if I do not take time to put them on paper.

Well, in a file actually. About this, I might publish a roundup of writing tools I used or discovered lately or earlier.

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 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.


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:

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