How Java’s text Formats can subtly break your code

Today at work we found a subtle issue that will sometimes break your code in very difficult to find ways. Read this if you don’t like days of bug hunting for mysterious issues only occurring on high-load production machines.

Ever wrote code like this?

private static final DateFormat FORMAT = new SimpleDateFormat("yyyy-MM-dd");

prevent-debugging-headache
Most of us did. It’s the most intuitive way to use a DateFormat to format some Date object as a human-readable String.

Unfortunately, it’s wrong.

When used in a multi-threaded context (e.g. in a Servlet), this will end up breaking. Sometimes. When you least expect it.

Continue reading

The Breaking Float Bug is back!

Back in september of 2010 I wrote a blog post about the Breaking Float rendering bug I found in WebKit, the rendering engine backing the Safari, Chrome and Opera browsers. In april of 2013 the WebKit team landed a patch which would eventually end up in the browsers relying on WebKit. Case closed right? Well, not quitte…

Blink brought it back

blinklogo

Coincidentally, in the same month that the Breaking Float bug was fixed, Google forked WebKit into a new project called ‘Blink’. And the fix to the Breaking Float bug was not in the fork. Over time, the Chrome browser switched over to using Blink instead of WebKit, bringing back the issue in all it’s breaking glory.

Continue reading

The Football Oracle’s Predictions

Just after midnight on monday I posted my first sports-related post. I’m not much into sports myself but I happen to know someone who is and often makes predictions about sports matches that come true. So I thought it would be fun if he would share some predictions about the 2014 World Cup that is drawing to a close right now. So I wrote a post about his World Cup predictions.

The Oracle’s first prediction was on the money

Brazilian supporters crying

My ‘Oracle’ as I will call him from now on predicted that Germany would convincingly beat Brazil. Well it does not come much more convincing than winning with 7 to 1!

The Brazilian supporters where shocked at what they were seeing. Germany walked all over Brazil and they are off to the finals!

Continue reading

World Cup Predictions

I’m not into sports but I do watch the European and World Cup matches that my country partakes in. The Netherlands have reached the semi-finals so it seems like a good moment for a post. But as I don’t know anything about sports I consulted with my brother-in-law and a sports-oracle of sorts, Stefan.

Germany to win convincingly from Brazil

Neymar
With Brazil having lost it’s two most important players, Neymar who is suffering from a back injury and Silva who is suspended, Germany is a huge favourite in the eyes of Stefan. They will win convincingly he says. He points out that statistically, the German team is right up there with the Brazilian team, but that the Brazilian team without it’s key players is just not up to that level. “Only if the German team loses it’s keeper in the first minutes of the game to a red card and a penalty that Brazil scores do they risk losing this game”, he says.

Continue reading

I like my code wet

Redundancy. Repeating yourself. Duplication. Copy-paste.

These have become like curse words in IT. This data is completely redundant! Did you just copy-paste that code?

No Copy-Paste, No Copy-Paste, No Copy-Paste

We all learn early on in our programming ventures about how code duplication is bad. It creates maintenance nightmares we are told. Our code should be DRY. I believed it and lived by it. But as I am maturing in my programming I am more and more starting to doubt it.

Continue reading

Change the facebook button color

Yes, it can be done!

Changing the color of Facebook’s Like and Share buttons is something that web page designers wish for, but up untill the rise of HTML5 was practically impossible. But today, thanks to SVG filters, it can be done. It’s still not very easy and, as usual, Internet Explorer is lacking support, but it is definitely possible.

Impatient? Just do it

For the impatient, check out the facebook button colorizer tool I built. You just copy-paste your button code, fiddle with the controls keeping an eye on the live preview until you like the result and then just copy and paste the colorizer code to your website. Couldn’t be easier.

screenshot

Continue reading

Enums in Javascript

I recently stumbled onto a question on StackOverflow that I had answered myself a couple of years back and did some more thinking about it after reading some of the comments and decided that this topic was worth an article.

So what was the question I hear you ask?

What is the best way to write enums in Javascript?

First of all, before answering this question, we have to have a look at what an enum is and what it means to write one in Javascript. So let us look at a definition of enum:

What is an enum?

In computer programming, an enumerated type (also called enumeration or enum [..]) is a data type consisting of a set of named values called elements, members or enumerators of the type. The enumerator names are usually identifiers that behave as constants in the language. A variable that has been declared as having an enumerated type can be assigned any of the enumerators as a value.
-Wikipedia: Enumerated type

And a good example often beats a formal definition:

enum WeekDay = {MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY, SUNDAY};

So, summarizing: An enum is a type restricting variables to one value from a predefined set of constants. In the example above, WeekDay is an enum and MONDAY, TUESDAY etc are the constants in the set, also called the enumerators. If we declare a variable as

WeekDay payDay;

..we would be able to assign it any of the constants MONDAY, TUESDAY etc, up to and including SUNDAY, but not something else like 12 or "labour day".

…which brings us to a problem.

Continue reading