tags:

views:

481

answers:

8

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.

A: 

Nope. I can't. It seems to me that the aliases are there to be used :)

jalf
+23  A: 

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.

Jon Skeet
support = suppose?
jalf
Fixed, thanks. (15 chars)
Jon Skeet
Thank you Jon... your example makes perfect sense...
SQN
Won't there be a very very very tiny performance hit at compile time when the compiler converts the aliases to type names? (In theory I mean, not that this is a real issue...)
antirysm
Yeah I thought Jeff's justification in his book was a little extreme (pg 119 if anyone is interested). However I agree with him that they should of never included the aliases in the first place and that float val = br.ReadSingle(); is a little odd. Though I think Single val = br.ReadSingle() is also odd, because people have used the aliases as a de facto standard- I don't know anyone that uses Int32 over int.
RichardOD
@antirysm: I suspect the aliases may actually be *faster* because the compiler doesn't need to check through the various namespaces and assemblies to find the relevant full name - it knows the fully qualified name already.
Jon Skeet
(But as you say, it won't be significant - probably not even measurable.)
Jon Skeet
15 chars?
dss539
Minimum length of comment. "Fixed, thanks." wasn't enough.
Jon Skeet
Fixed, thanks.
dss539
+2  A: 

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.

Timothy Carter
+2  A: 

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.

Robert S.
+1  A: 

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".

BBlake
A: 

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");
asbjornu
+1  A: 

(Although it's not a particularily strong reason) I prefer type names over aliases because of IntelliSense standard coloring.

antirysm