Archive for the ‘Fun’ Category


May 10th, 2007

Following Marc-Andre, I’ve joined Twitter. It’s the kind of application that if someone, six months ago, called me to join the effort I’d say “dude, that’s a plain stupid idea”. Hope I change my mind soon. :-)

Categories: Fun, General | Top Of Page | 1 Comment » |

Another good question for interviews

September 14th, 2006

Given this class declaration:

public class Some<TKey> where TKey: IComparable<TKey>
  public static int Added;

  public void Add(TKey k)

And the following usage

public class Driver
  public static void Main()
    Some<int> intSome = new Some<int>();

    Some<string> strSome = new Some<string>();


What would be the output? Just a tip: check the C# language spec.

Categories: Fun | Top Of Page | 8 Comments » |

Street fight

September 6th, 2006

I’ve just watched this documentary and can’t help feeling shocked. I don’t think the movie was about the good guy vs the bad guy, instead about the censurable, despicable methods used, the transgression of laws, the use of police and fire department in politics activities. I can honestly say that Brazil is way more advanced on elections than US, maybe even – I dare to say – the rest of the world, at least regarding casting votes and couting them. It’s all eletronic, secure, reliable, fast and fault-tolerant. We have the results of an election in a couple of hours. You can even download a java application and watch and query the results being calculated. It’s fun.

The biggest difference is that here we are obligated to vote. Kinda of “enforced” democracy.

Categories: Fun, General | Top Of Page | No Comments » |

Interesting snippet

August 28th, 2006

Ayende has posted an interesting code snippet useful to measure how much a candidate to a job knows about the compiler he/she claims to work on.

selected = selected++;

I’ve seen this one years ago (2002 I think) in a Java prep exam. My first guess was that ‘selected’ variable would hold the result of selected++. Wrong! Then I kind memorized that this one was tricky, but forgot why. But today I was curious enough to check again the IL code to see where is the trick.

The C# code

selected = 1;
selected = selected++;

The IL

L_0000: ldc.i4.1 // loads the literal 1
L_0001: stloc.0  // store in the local
L_0002: ldloc.0 // load the local value (1)
L_0003: dup  // duplicates the stack, now we have two ints with value 1
L_0004: ldc.i4.1 // loads the literal 1 (++)
L_0005: add // sum 1 + 1 and push the result on the stack (2)
L_0006: stloc.0 // saves the value 2 on the local variable which is the top level item on the stack
L_0007: stloc.0 // whoops, the int on the stack now is the 1, store it (overriding the result of the increment)

Knowing this kind of behavior might be useful. On the project I was working on I coded something like the following

int val = 1;
string something = "some value " + (val + ',' + "something else");

Can you the headache this gave me?

If you have time and likes to read, the book Programming language pragmatics is a gem.

Categories: Fun, General | Top Of Page | 8 Comments » |