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)

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…

Simplicity

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.

Resources

Images

Others