The following might be totally obvious, but to me it was a revelation, so why not publish it. :-)

There are situations when you have methods returning a collection.
A Java collection can be a set (no sorting, no duplicates), a list (sorting, duplicates) or a map (association key/value).

In some cases, the method might fail.
To have robust code, you would still like to return an empty set, list or collection instead of null.

Read more…

Strings in the D programming language (and in many other languages too) are stored as an array of characters. Sometimes you might forget that you are still working with an array. The following code for example might result in unexpected behaviour.

char[] a = “foo”;
char[] b = “foo”;
a[0] = ‘x’;                    // access violation (Linux)
Stdout(a ~ ” “ ~ b).newline(); // outputs “xoo xoo” (WinXP)

Read more…