We have a bit of a battle going on in our development team over this. I would love to hear what others think about this.
In the actual code? No, not unless you're going to have lots of people working on the code who are familiar with .NET but not with C#.
In member names? Absolutely. For instance, suppose Convert.ToSingle
had been called Convert.ToFloat
- that would be totally 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 in favour of using the CLR type names everywhere, Jeff Richter recommends that in "CLR via C#". (If you haven't already got it, buy a copy regardless of this matter - it's a wonderful book.) I didn't agree with the arguments he put forward, but there are some there, anyway.
I generally use the C# alias when declaring a variable, but the CLR types for the static members. I guess I just like the visual distinction it provides.
(Although it's not a particularily strong reason) I prefer type names over aliases because of IntelliSense standard coloring.
My previous development team adopted this practice because of the mix of C# and Visual Basic.NET developers. It was decided that the CLR types would make it easier for the C# and VB.NET people to communicate.
I think that almost the only time it makes sense to always use the CLR type names is in a mixed-language shop. One other possibility is if you are planning to switch from the current language to another one in the near future. In that case I would go with the CLR type names.
Other than that, there really isn't a strong motivating reason to choose one methodology over the other. It's far more important that you come to a consensus one way or another and make sure everyone is following the "standard".
I think it makes sense to consistently use the CLR type names when calling static type member methods, as you have to do that on enums anyway. So for declaration, use the C# type names, but when calling static members, use the CLR types. This makes it easier to read and more consistent imho. Since, you can't write:
MyEnum value = enum.Parse(typeof(MyEnum), "value");
which would fit better with:
int i = int.Parse("1");
long l = long.parse("1");
You'd rather write:
int i = Int32.Parse("1");
long l = Int64.Parse("1");
MyEnum value = Enum.Parse(typeof(MyEnum), "value");
Nope. I can't. It seems to me that the aliases are there to be used :)
© 2022 - 2024 — McMap. All rights reserved.