Gray's Matter
Justice Gray - North America's favorite metrosexual software consultant

I Wish These People Updated More Than Once a Year

globe.gif

I thought I would continue my seeming tradition of hitting these questions once every 6 months.   Actually, I had given up on Granny getting into Corillian but that's okay; she's seen the light and is now an independent consultant!  Nonetheless, I have still felt the need to answer some of Scott Hanselman's old interview questions in an attempt to help get her up to speed.

So, without further adieu, let's tell two stories about marriages:

Story #1:

My sister-in-law is getting married this coming May.  I had a chance to meet her future husband's parents this past Christmas, both of whom are from Quebec and primarily speak French.  As is my custom when I am meeting new people, I tried to amp up the patented Justice Gray charm ™ and impress them with the French I vaguely remembered from about a decade and a half ago.  I introduced myself ("Je m'appelle Justice") and then decided to follow up with the coup de grace: terrifically witty banter.  

"The French I am speaking now is the only French I know!"


I paused for laughter - but instead was met with nervous silence!!  In this moment, I finally learned what Donald goes through at the beginning of every EDMUG meeting.

I was definitely a little confused; after all that sentence should have been a guaranteed laugh riot.  My future brother-in-law came up to me and quietly whispered,
"I think I understood what you were saying, but my parents actually think you have some sort of handicap now"

It seems instead of my intended phrase, I had stated something closer to

"I speak French.  French speak!!  Only French!!  I know speak!!!"

Fortunately, I solved the awkwardness that night like anyone would: by getting *completely hammered*.

Speaking of solving all of the world's problems through excessive alcohol consumption , let's go onto story #2.

As most of you know, I was married a year and a half ago.  What many of you don't know is that one of my groomsmen, flush with alcohol and ready to try and impress the ladies, decided to go to one of the bridesmaids and show off his *fluent* knowledge of Cantonese.  Whatever his planned come-on line was will forever remain a mystery.  I wish I could say the same for the translation of what he *did* say, which was, "Boy, I'd really like to sleep with your mother."  

So, what's the problem here?  Lost or unclear intent through translation, or lack thereof.  This is also the difficulty Scott Hanselman was referring to when he asked

"What’s wrong with a line like this? DateTime.Parse(myString);"


This line on its own seems pretty simple - after all, you're just asking for the runtime to take a standard string and convert it into a DateTime object.  

DateTime myDate = DateTime.Parse("10/06/2006");

What's the value for myDate.Month and myDate.Day?

And therein lies the problem: there is no way for you to tell me this without knowing additional information.

For example, if I am running this with an English culture, the DateTime object represents October 6, 2006.  However, if I ran this same line on a computer with its culture set to French (or if the application's culture was set to French), then the DateTime object now represents a completely different date (June 10, 2006, to be precise).  This happens because French dates reverse the position of the month and the day.  

To get around this, always pass Culture information as the second argument to DateTime.Parse, as in the following:

DateTime myDate = DateTime.Parse("10/06/2006", System.Globalization.CultureInfo.GetCulture("fr-FR"));

Now, obviously you wouldn't want to do a culture retrieval every single time you call DAteTime.Parse!  Your application should probably be setting the culture itself, somewhat like the following

System.Threading.Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.GetCultureInfo("fr-FR");
DateTime myDate = DateTime.Parse("10/06/2006", System.Globalization.CultureInfo.CurrentCulture)


This sets the culture for the particular thread of execution that your current user is experiencing.  

You might not think that globalization errors are as embarassing as the two stories I talked about earlier.  Trust me, in the context of a globalized application, they are even worse.  Take this tip and use it to save yourself humiliation in code reviews everywhere!

Previous entries in this series:
My grandmother and the Global Assembly Cache (and Star Wars)
My grandmother and the difference between processes and threads
My grandmother and the difference between HTTP GET and HTTP POST

Monday, March 26, 2007 #

3/26/2007 10:09:39 AM (Mountain Daylight Time, UTC-06:00)
Good post, honey! I actually laughed out loud this time! ;)

And wasn't our groomsman saying that about *my* mother, no less? Proof that alcohol can rot even the smartest brain!
3/26/2007 10:13:08 AM (Mountain Daylight Time, UTC-06:00)
I thought you laugh out loud at every post I make?!?!

MY LIFE IS A LIE
3/26/2007 10:17:15 AM (Mountain Daylight Time, UTC-06:00)
Dude, what's up? A technical post? I was expecting to read something about Transformers or Macs.
3/26/2007 10:19:28 AM (Mountain Daylight Time, UTC-06:00)
Well, every so often I need to take a break from the Mac/Transformer thing, though I love it a lot. Don't worry, I'll try not to post anything technical for another 6 months ;)
3/26/2007 1:43:45 PM (Mountain Daylight Time, UTC-06:00)
Thanks for this post Justice! Today I used this to illustrate to a developer why just having something like the XmlSerializer deserialize a DateTime without declaring the culture was a bad idea (especially since the agreed upon date format was NOT the same as the default culture of the machine we were testing on).
JH
3/27/2007 8:37:19 AM (Mountain Daylight Time, UTC-06:00)
when you said "Je m'appelle Justice"
How did you pronounce Justice?
In its English way, or French sexy way?
anonymous
3/27/2007 10:03:40 AM (Mountain Daylight Time, UTC-06:00)
I wonder if it wouldn't be better to actually specify the format of the date along with the date itself...
3/27/2007 10:48:30 AM (Mountain Daylight Time, UTC-06:00)
Hahaha! nice ;)
3/27/2007 12:03:00 PM (Mountain Daylight Time, UTC-06:00)
WHO CARES WHAT YOU THINK VLAD

*ahem* ;)

Actually, you are quite correct depending on the situation. =) I will have to edit the post after to add that in.
3/27/2007 12:03:49 PM (Mountain Daylight Time, UTC-06:00)
Anonymous - no matter what method or language in which I say "Justice", it's *always* a sexy way. ;)
3/28/2007 11:39:11 AM (Mountain Daylight Time, UTC-06:00)
lol.
I think I know what that guy said.
Ok, I better go back and finish this tech article.
4/1/2007 6:05:26 PM (Mountain Daylight Time, UTC-06:00)
Absolutely brilliant. This is a great way to make your point.
12/7/2007 5:26:25 AM (Mountain Standard Time, UTC-07:00)
I believe that finding a good husband is a tedious task but not an impossible one.
3/22/2008 9:39:37 AM (Mountain Daylight Time, UTC-06:00)
discount lowest cost butalbital
3/22/2008 9:45:46 AM (Mountain Daylight Time, UTC-06:00)
Tramadol Us
6/9/2008 7:34:55 AM (Mountain Daylight Time, UTC-06:00)
Your stories are very funny. I had a good laugh reading them and I have to tell you that you could always be hired for a comedy show so get ready because you never know what life has prepared for you...
Name
E-mail
Home page

Comment (HTML not allowed)  

Enter the code shown (prevents robots):