Saturday, December 11, 2010

When In Doubt, Do Nothing

If you are unsure about what you are doing it is better to do nothing then to do something wrong. Express this in your code in order to communicate your doubt clearly to your colleagues.


Like in this example:

void OnItemClick(object sender, EventArgs e)
{
  string selected;
  try
  {
    selected = Parse(e.Item.Value);
  }
  catch (Exception ex)
  {
    Log("Clicked Item not found", ex);
    throw;
   }

  switch (selected)
  {
    default:
    break; 
  }
}

Thursday, December 2, 2010

It's so easy to define delimiters...

Spotlight on a day in the lives of two developers - one on the server-side, the other on the client-side...


Requirement to be fulfilled: Two files have to be transfered over a TCP-connection. Both are zip-files and the transfer is a plain raw-data transfer.

Proposal of the client-side developer: "Just pack the info about the file-lengths into the header"

Answer of the server-side developer: "Are you crazy? Why should I do that? It's much better to just define a delimiter that is sent after the first file. Then you immediately know where the second file starts"

Question of the client-side developer: "But how would you define a delimiter? We work with raw data-transfer, so it isn't possible to define one that is guaranteed not to appear in the stream as real data"

Answer of the server-side developer: "Hah - just take qayxswedcvfrtgb - this one for sure does not appear in any zip-file"

... as a proof that the server-side developer was just plain wrong - not only theoretically but also practically - the client-side developer just took a bunch of the zip-files to be transfered and ran a grep for this string over them - guess what happened... sure there were several appearances of this "delimiter"...

... with this result in hands the client-developer tried to convince the server-developer again that the "delimiter"-solution is plain nonsense...

... and got the answer: "ok, this string seems to have been too short, we take qayxswedcvfrtgbnhzujm,kiol.- instead, then it works"

... needless to say what happened to the data transfer...