Can someone give me a REALLY good reason to use CLR type names instead of C # type names (aliases) in code (as a common practice)?

We have a battle in our development team about this. I would like to hear what others think about it.

+14
c # clr
Jun 11 '09 at 14:27
source share
8 answers

In the current code? Not unless you have a lot of people working on code who are familiar with .NET but not C #.

In the names of the participants? Absolutely. For example, suppose Convert.ToSingle was called by Convert.ToFloat - this would be completely confusing for F # developers for whom โ€œ float โ€ means โ€œ64-bit floating pointโ€.

My general rule is C # aliases for implementation, CLR types for member names.

If you want to find some arguments for using CLRs around the world, Jeff Richter recommends this in "CLR via C #". (If you have not received this yet, buy a copy, regardless of this, this is a wonderful book.) I did not agree with the arguments that he put forward, but there are, anyway.

+28
Jun 11 '09 at 2:30 p.m.
source share
โ€” -

I usually use a C # alias when declaring a variable, but CLR types are for static members. I think I just like the visual difference it provides.

+3
Jun 11 '09 at 14:33
source share

(Although this is not a very strong reason), I prefer type names over aliases because of the standard IntelliSense layout.

+3
Jun 11 '09 at 14:58
source share

My previous development team adopted this practice due to a combination of C # and Visual Basic.NET developers. It was decided that CLR types would facilitate the communication of C # and VB.NET people.

+2
Jun 11 '09 at 14:34
source share

I think it's almost the only time it makes sense to always use CLR type names in a mixed language store. Another possibility is that you plan to switch from the current language to another in the near future. In this case, I would go with CLR type names.

In addition, there really is no strong motivational reason to choose one methodology compared to another. It is much more important that you come to a consensus one way or another and make sure everyone follows the โ€œstandardโ€.

+2
Jun 11 '09 at 14:41
source share

I think it makes sense to consistently use CLR type names when invoking methods of a static type type, since in any case you should do this on enumerations. Therefore, use C # type names for declarations, but when invoking static members, use CLR types. This makes reading easier and more consistent. Since you cannot write:

 MyEnum value = enum.Parse(typeof(MyEnum), "value"); 

which is better suited:

 int i = int.Parse("1"); long l = long.parse("1"); 

Do you prefer to write:

 int i = Int32.Parse("1"); long l = Int64.Parse("1"); MyEnum value = Enum.Parse(typeof(MyEnum), "value"); 
+1
Jun 11 '09 at 14:41
source share

Nope. I can not. It seems to me that pseudonyms are used here :)

0
Jun 11 '09 at 2:30 p.m.
source share



All Articles