Sep 04

This is a nice question…since i”ve been using the C# language, I”ve been using the keywords that are mapped to the the simple types introduced by the FCL (ex.: i”ve been using int instead of System.Int32, etc). Now, even though that I know that the int alias/keyword is mapped to the System.Int32, I think that using this style is not really a good thing.

If you ask me, a declarations that looks like this:

Int32 myInt = 10;

is a lot more clearer that this:

int myInt = 10;

why? simple: in the first example, I know that i”m using a System.Int32 type. The second tells me that i”m using an int, which currently is mapped to a System.Int32 type. Yes, i know that the probabilities that this will ever change are really low, but i still find that the 1st snippet communicates my intensions better than the second. With the 1st, there”s really no chance of misinterpreting what i want. Oh, and if you”re thinking: “How is it possible making an iterpretation error with int?”,then please check what the C++CLI spec says about its long type and compare it with what you have in C#…

5 comments so far

  1. vikram
    4:41 am - 9-5-2007

    Its all about your style of coding. It depends on individual. I prefer int i=10;

  2. Luis Abreu
    8:23 am - 9-5-2007

    Well, yes it”s a matter of style. Nothingwrong with using it if you really know what you”re doing. however, you cannot deny that using the correct type name will make your code more readable and less error prone.

    I”d really prefer that the c# compiler wouldn”t have defined those keywords for the FCL type.

  3. Paulo Morgado
    10:03 pm - 9-5-2007

    I suppose you also use System.String instead of string, right?

    And you plan to use:


    instead of:

    from collecction select


  4. luisabreu
    10:23 pm - 9-5-2007

    Hello again.


    wrong, wrong. you see, I only need to use String since we have the using directive. I”m not saying that we should use the complete name of the type. only that we should be specific about it.

    > collection.Select()

    not sure. you won”t believe me, but i”ve installed vs 2008 beta 2 in 2 different machines and i still haven”t managed to have intellisense for the linq expressions 😀 btw, and since you”re mockering the extended methods, must i remind you that you can”t really access all the available funcionality with linq syntax?

  5. luisabreu
    10:25 pm - 9-5-2007

    small adenda to the previous comment:
    should be

    >I suppose you also use System.String instead of string, right?

    instead of: