-
Notifications
You must be signed in to change notification settings - Fork 4.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Language or BCL data types #13976
Comments
Leaving my personal view out of this reply. I just wanted to make a note that the referenced line from MSDN is not related to this particular discussion. It is simply saying this: // avoid this:
long ToLong();
// use this instead:
long ToInt64(); There is no content on that page describing the use of these types for code which does not form the public API. |
My personal preference is to use only the language data types for type references. I base this on the following reasons:
That said, regardless of the coding style used by the project I would always use the conventions of the surrounding code when submitting modifications to an existing file of some project. |
I second the use of language keywords, as opposed to the type names. |
+1 for language keywords |
I also prefer language keywords. Before adding this to the coding guidelines I will give some time for other opinions to see if there are any good reasons not to do that. |
+1 for language keywords as well For the sake of completeness I'll also note 2 objections to this rule that I've seen in the past on forums:
|
Use language data types for declarations | BCL data types for calling members
|
There may be other logical reasons to use the BCL types to access members but "because keywords do not have members" isn't one of them. That's simply a false premise. There is no definition of 'keyword' that claims such a thing, they simply are reserved identifiers without a particular semantic. Depending on the semantics attached by the language, possibly depending on context, keywords may or may not have members. There are other keywords which can be used for member access and they don't even have a non-keyword alternative: true/false, base, this. And double and string are probably not the best example due the fact that the names differ only by case. float is much more fun: float f;
Single.TryParse("42.0", out f); I find it difficult to justify enforcing such a naming inconsistency via coding guidelines. |
The "keywords don't have members" reasoning seems somewhat nonsensical to me. When I moved to .NET, my reasoning was that "primitives aren't objects and thus can't have members". Thus, I felt that int x = 42;
sting s = x.ToString(); was rather strange. However, once you get used to the idea that virtually everything is an object (or can be treated as an object), it's actually rather intuitive. The way I think of the keywords (and that's probably because I'm a compiler nerd) is that keywords are simply aliases for the type names. In that world view, them having members is completely sensible or even obvious. Thus, I honestly don't buy the argument at all. The interoperatibility argument does hold merit, but given that interop is not common enough I don't think it should trump over the simplicity that keywords offer. I'm fine, however, with a rule that allows using the type names in classes that deal with interop. |
+1 for language keywords |
I also think that going straight with keywords it's clearer and simpler, at least for a C# developer. |
@weshaggard Do you think we gathered enough feedback? I think we're all siding with keywords. |
Yes I think we have settled on the guidance of using language keywords. I've updated our coding guidelines wiki to add:
Thanks everyone for the discussion I'm closing this issue now. |
+1 for language keywords |
I'm not sure it's worth to discuss this issue. To ensure consistency within the code base the preferred data types should be noted in the wiki. I know this can be a sensitive and subjective issue...
Only use BCL data types
Only use language data types
Use language data types for declarations | BCL data types for calling members
My favorit is the last option because
MSDN says "√ DO use a generic CLR type name, rather than a language-specific name, in the rare cases when an identifier has no semantic meaning beyond its type."The text was updated successfully, but these errors were encountered: