Scott Hanselman

Internationalization/I18n: Char.IsDigit() matches more than just "0" through "9"

March 10, '04 Comments [5] Posted in ASP.NET | Javascript | Bugs
Sponsored By

Raymond Chen just gave me a "duh" moment, by pointing out the obvious-only-if-you-think-about-it.  Char.IsDigit() doesn't mean 'IsZeroToNineInEnglish', it means 'is in the decimal range of 0 to 9' and darnnit if there aren't other ways (other than 0,1,2,3,4,5,6,7,8,9) to express them! :)

So let's run an experiment.

class Program {
  public static void Main(string[] args) {
    System.Console.WriteLine(
      System.Text.RegularExpressions.Regex.Match(
        "\x0661\x0662\x0663", // "١٢٣"
        "^\\d+$").Success);
    System.Console.WriteLine(
      System.Char.IsDigit('\x0661'));
  }
}

The characters in the string are Arabic digits, but they are still digits, as evidenced by the program output:

True
True
Uh-oh. Do you have this bug in your parameter validation? (More examples..)
If you use a pattern like @"^\d$" to validate that you receive only digits, and then later use System.Int32.Parse() to parse it, then I can hand you some Arabic digits and sit back and watch the fireworks. The Arabic digits will pass your validation expression, but when you get around to using it, boom, you throw a System.FormatException and die.
[Raymond Chen]

Arabic speakers (مرحبًا, كيف حالك ؟ and forgive me, it's been college since I studied Arabic) how to you handle numeric validation in JavaScript AND guarantee that the JavaScript you use on the client-side is semantically equivalent to the server-side code?

Either way, my friends, read, grok, and be enlightened.  Muy interesante.

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook twitter subscribe
About   Newsletter
Sponsored By
Hosting By
Dedicated Windows Server Hosting by SherWeb

Reminder: Update your RSS Feed Url and check your Smoke Detector Batteries!

March 10, '04 Comments [4] Posted in XML
Sponsored By

Just a friendly reminder.  It applies to me, but it could also apply to other folks.  I shall declare this day "Check your OPML File and Subscriptions Day."

If you are goodly enough to have subscribed (thank you) to my Radio RSS feed (http://radio.weblogs.com/0106747/rss.xml) please update your subscription to point to the updated feed.  I haven't been at Radio for over 6 months.  However, I have continued to update my Radio RSS feed, so you wouldn't have an interrupted experience.

Again, to recap.  Here are my feeds, Coke: RSS 2.0 or, if you like Pepsi, here: Atom 0.2.

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook twitter subscribe
About   Newsletter
Sponsored By
Hosting By
Dedicated Windows Server Hosting by SherWeb

My TWO .NET Rocks shows are up on MSDN now

March 8, '04 Comments [1] Posted in ASP.NET
Sponsored By

I totally forgot that MSDN is hosting the .NET Rocks shows for download!

Not only can you listen to my second show from last month (thanks Rory and Carl!) but you can also checkout my first attempt from October 2003!

  • Show #2: Carl and Rory talk with Scott Hanselman about ASP.NET, declarative programming, client-side validation, caching, perf testing, blogging trends, and more. [MSDN]
  • Show #1: Scott and Carl chat about .NET, C#, Reflection, Regular Expressions, Freeware, Code Sharing, Config Files, Sockets, Multi-Threaded programming, and a laundry list of Scott's favorite utilities that you just have to check out. [MSDN]

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook twitter subscribe
About   Newsletter
Sponsored By
Hosting By
Dedicated Windows Server Hosting by SherWeb

More on My Lasik and the Windows 98 Machine that Zapped Me

March 8, '04 Comments [7] Posted in Musings
Sponsored By

My LASIK posts have been ridiculously popular, considering this is a .NET and Programming Blog.  That being said, there were a few blogs that mentioned my surgery and I thought it would be useful for me spend some time in Photoshop and explain to you EXACTLY what I saw, and EXACTLY what I see now.

Here's before, this is -9.25 diopters (roughly 20/1600 for me) and what I saw without glasses for ~20 years.  I adjusted this photo in Photoshop to show represent what I saw before as accurately as possible.

Here's after.  I'm now at LEAST 20/20 (I'll be officially measured this Friday, one month after my operation.  I suspect I'll be 20/15.  Just a hunch.

I adjusted this after picture to show you exactly what I see now.  Note the slight “motion” blur over the lights.  Note the darkness of the background and the bright contrast of the foreground.  

Not to bad for a Windows 98 machine.  One thing to note also.  While it's totally reasonable to worry about this operation, and most folks are concerned that they might never seen well again, I thought it was a reasonable risk.  It IS VERY possible to have side-effects that will result in a loss of best corrected vision.  There's about a 0.04 percent chance using my doctor's stats.  The problem with stats that compare success with failure is that someone has to fail.  I feel really bad for folks that are in that 0.04 percent bucket - having surgery is inherently dangerous. 

That said, I'm happy with the result - more every day - and I will enjoy the next 10 years of vision...before I have to get bi-focals!

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook twitter subscribe
About   Newsletter
Sponsored By
Hosting By
Dedicated Windows Server Hosting by SherWeb

UEX = User Education and Generating <devdoc>

March 5, '04 Comments [4] Posted in NUnit | NCover | Nant | XML
Sponsored By

I was poking around in the Authorization and Profile Application Block and noticed what nice documentation it has.  I'm a HUGE fan of NDoc, and we build a great deal of documentation with it during the automated build process. (The goal: NAnt -> NUnit -> NCover -> NDoc)

Lots of folks know the basics about XML Documentation in C# but usually only take it this far:

   /// <summary>
   /// The entry point for the application.
   /// </summary>
   /// <param name="args"> A list of command line arguments</param>
   public static int Main(String[] args)
   {
       return 0;
   }

However there's a lot more cool stuff/tags beyond summary and param that can be done with XML Documentation.  Also adding LOTS of rich documentation to your source code can make the files unruly and end up containing more prose then code. 

So, you can instead add your documentaiton like this:

   /// <include file="doc\Main.uex" path='docs/doc[@for="MyNamespace.Main"]/*'></include>
   public static int Main(String[] args)
   {
       return 0;
   }

and then you'd have a file called Main.uex in your doc directory:

<docs>
   
<doc for="MyNamespace.Main">
        <summary>
            <para>Get the whatever from the <paramref name="whateverElse"/> for the <paramref name="whatever"/>.</para>
        </summary>
        <param name="whateverElse">
            <para>The section to retrieve the whatever.</para>
        </param>
        <param name="whatever">
            <para>The whatever to retrieve.</para>
        </param>
        <returns>
            <para>The <see cref="SomeClassName"/> for the given name.</para>
        </returns>
        <exception cref="SomeException">
            <para>An error occurred while performing the operation.</para>
        </exception>
        <remarks>
            <para>Here is some text about something.
</para>
            Here is the config section in the configuration file:
            <code>
            ...
            &lt;section name="mySection" type="MyConfigHandler,MyAssembly,Version=1.0.0.0,Culture=neutral,PublicKeyToken=null" /&gt;
            ...
            </code>
            Here is the code that do something.
            <code> 
                using System;
                class MyNamespace {
                private String whatever;
                }
            </code>
        </remarks>
    </doc>
</docs>

Another interesting thing is the <devdoc> tag, which is apparently to indicate documentation that originates from the developer and not the documentation team.   

I think I'll be a lot more likely to include rich documentation for Frameworks we design if I have more room to add code samples and remarks.  Very cool.  You can find lots of great example of this kind of file in the newer Application Blocks, or the Rotor Source Code.  I recommend the former. 

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook twitter subscribe
About   Newsletter
Sponsored By
Hosting By
Dedicated Windows Server Hosting by SherWeb

Disclaimer: The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.