Replies: 22 comments
-
You shouldn't need the type name when accessing from within the type itself. |
Beta Was this translation helpful? Give feedback.
-
I agree you don't have to put it there, but it is useful in the same way as specifying "this" is useful. Even using naming conventions I consider it better to specify. |
Beta Was this translation helpful? Give feedback.
-
public struct WhatAboutMe
{
private static int StaticCount;
private static int StaticIncrement;
public void Method()
{
// Should be able to write this? ... 👀
class.StaticCount = class.StaticCount + class.StaticIncrement;
}
} |
Beta Was this translation helpful? Give feedback.
-
One day when we (finally!) get #297: public enum AndMe
{
Foo = 1,
Bar = 2
public AndMe Method()
{
// Should be able to write this? ... 👀
return this == class.Foo ? class.Bar : class.Foo;
}
} |
Beta Was this translation helpful? Give feedback.
-
@Joe4evr Unless there is a local variable having the same name in scope. |
Beta Was this translation helpful? Give feedback.
-
@sjb-sjb what is the difference between Also you should know that static field inside generic class is not one for all generic types. its actually one per each generic type. for example that maybe expected behavior though, I'm just noting it. |
Beta Was this translation helpful? Give feedback.
-
@vladd That's why I always prefix field names with Everyone is free to choose their own rules, but having good naming conventions would pre-empt the need for this request. If you insist to qualify access with (I say that, but looking at the options right now, there doesn't seem to be such a rule for accessing static members from its declaring type.) |
Beta Was this translation helpful? Give feedback.
-
When does Oracle's dodgy patent on enums expire? Java itself is 22 years old, but I don't know when they took out the patent on enums. I'm assuming the patent only has a 20 year life? |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
-
Funny to see @gafter's name as an inventor on Java's patent, but then I saw this and was less thrilled: https://www.google.com/patents/WO2011084876A3 Didn't know Microsoft was in the business of patenting syntax representations, but I'm not a fan. |
Beta Was this translation helpful? Give feedback.
-
@jnm2 I think they also patented storing trivia in syntax nodes. I wonder what Apache 2 license says about patents. |
Beta Was this translation helpful? Give feedback.
-
@orthoxerox that's a... odd patent? Sounds like a patent for taking notes in the margin of a notebook... |
Beta Was this translation helpful? Give feedback.
-
@Joe4evr You seem to be advocating the "manual" way of resolving naming conflicts. If we would take your way one step further, one could see that we don't need However the syntax for disambiguating the local name and instance field name does exist, so the syntax for disambiguating the local name and static field would be just feature parity. (Yes, one can specify the full class name, which is however error-prone and can get a really ugly look with long generic parameter lists and nested classes.) PS: Microsoft's own naming convention guidelines suggest not using underscores (as well as Hungarian notation like |
Beta Was this translation helpful? Give feedback.
-
I merely stated my preference. And then I said what every dev can do to have the compiler warn or even error when their preferred style is violated. And if I'm not mistaken in that breaking such a rule brings up a Quick Fix, it's just a matter of And sure,
And yet, both those styles are used throughout the BCL quite extensively. 🙃 |
Beta Was this translation helpful? Give feedback.
-
@vladd Those guidelines are only about names that are public, not about private implementation details:
|
Beta Was this translation helpful? Give feedback.
-
This is Hungarian notation: bool bCompleted = true;
int iCount = 100;
float fWeight = 50f; |
Beta Was this translation helpful? Give feedback.
-
Actually that isn't either, at least not what Hungarian notation is supposed to be. It got bastardized into this notion that it's supposed to be a prefix representing the data type of the variable, but that's redundant and unnecessary. The prefix is supposed to indicate the functional type of the variable to help distinguish it from other variables of the same data type but different functional types. You should never call a variable Hungarian Notation - Charles Simonyi But yes, the data type prefix somehow became the norm and VB5/6 helped it to spread like wildfire. Sorry for the rant. |
Beta Was this translation helpful? Give feedback.
-
@svick Yes, following the naming conventions is not required. Nevertheless I am following the naming conventions for the private members too, is this somehow wrong? Should the language design "punish" the developers who adhere to the official naming conventions? In any case, I see the language feature which facilitates adhering to the official naming conventions as a good thing. The idea of changing the code's naming conventions and giving up on official convention seems quite strange to me. |
Beta Was this translation helpful? Give feedback.
-
Getting back to the proposal... About @jnm2 's questions, I would suggest struct and enum in those cases. How do we upvote ideas by the way? |
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
-
It would not provide the same benefit as Besides, the current way of doing it is even shorter than your idea. class EntityIdIndexes<TDbContext, TEntity, SortType, FilterType, IncludeType, AnotherType>: ...
{
static int StaticCount;
static int StaticIncrement;
public void Method()
{
// You can just do this
StaticCount = StaticCount + StaticIncrement;
// Instead of this:
class.StaticCount = class.StaticCount + class.StaticIncrement;
}
} Also, having it be Also, the |
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
OK I agree this is a small one --
We should be able to use the 'class' keyword to shorten references to static members:
Beta Was this translation helpful? Give feedback.
All reactions