Introduce abstract and virtual static. Please read the entire proposal... #1370
Replies: 17 comments
-
Have you looked into getting analyzers to verify the correct coding patterns for you? They are much more flexible and can be taken advantage of today rather than three years from now. |
Beta Was this translation helpful? Give feedback.
-
Am using ReSharper, but I'm stumbling over this issue every once in a while and thought I should post it. The problem actually isn't a particular Issue of mine, but the potential of using data, object independently, whilst being flexible by enabling polymorphism even in the static area without having to gather its information from somewhere outside. |
Beta Was this translation helpful? Give feedback.
-
Roslyn analyzers work with or without Roslyn since they are integrated into the C# compiler itself. You can enforce errors or warnings, report suggestions, apply code fixes, etc, and they will work in any C# IDE. |
Beta Was this translation helpful? Give feedback.
-
If you can't use a C# 2.0 feature, what makes you think a C# 8.0 (or whatever) feature will be fine? |
Beta Was this translation helpful? Give feedback.
-
first of all generics don't apply polmorphism, second of all I know how to use them Unity just doesn't serialize them properly. Third of all the stuff I'm requesting is absolutely independent of generics, but nice try being a dick. |
Beta Was this translation helpful? Give feedback.
-
jnm2 so you mean I can use roslyn to make this kind of new requirement myself, that resembles a virtual/abstract static? I have roslyn included, and sometimes I use its recommendations, just like i use resharper, |
Beta Was this translation helpful? Give feedback.
-
This explains Roslyn analyzers well: https://docs.microsoft.com/en-us/visualstudio/extensibility/getting-started-with-roslyn-analyzers They provide ways to address these comments:
Analyzers can provide a compile-time error with a rid squiggly in the editor and a code action to insert the expected members in the subclass. @svick was asking a reasonable question. If, hypothetically, this feature landed in C# 9, how long would it take Unity to allow you to use it? |
Beta Was this translation helpful? Give feedback.
-
@Draethorian That's a pretty quick way to shut down conversation on any proposal and alienate yourself from the community. Given that any proposal requires that a member of the language design team to want to champion through their design meetings in order to even have a chance at implementation it's not very conducive to address criticism through personal attack. |
Beta Was this translation helpful? Give feedback.
-
Well yeah, looks I took it the wrong way. I'm sorry for the insult, but right now I'm stuck in that phase of having to prove myself as an outsider/independent. Guess what that means in Frankfurt's CV Jerkism. So yeah, my nerves are kinda raw. Sry. |
Beta Was this translation helpful? Give feedback.
-
I don't know what "Frankfurt's CV Jerkism" is, but certainly no one is expecting you to prove yourself. We should always be careful in the way we word things. I hope you'll be able to relax, and assume the best, and participate with everyone in this repo long enough to shake off that outsider feeling! 😃 |
Beta Was this translation helpful? Give feedback.
-
thx buddy, appreciate it. svick: I'm sorry I misunderstood your statement. |
Beta Was this translation helpful? Give feedback.
-
Have a read up of parametric polymorphism (link now fixed, thanks @theunrepentantgeek) |
Beta Was this translation helpful? Give feedback.
-
@DavidArno Link is broken. |
Beta Was this translation helpful? Give feedback.
-
Pretty sure that @DavidArno meant this link |
Beta Was this translation helpful? Give feedback.
-
There is at least one compelling use-case for virtual statics. public class MessageBase
{
protected abstract static MessageBase ReadMessage(BinaryReader reader);
} Elsewhere, inside a generic method: void SomeGenericMethod<T>()
where T : MessageBase
{
...
var message = T.ReadMessage(reader);
DoSomethingWithMessage(message);
....
} That is to say, it solves the |
Beta Was this translation helpful? Give feedback.
-
That would require either the C# compiler to emit reflection code, or a new CLR feature, but it could be cool. |
Beta Was this translation helpful? Give feedback.
-
If memory serves (it's been a long while), this aligns with the class methods supported by Delphi's Object Pascal - they could be virtual and overridden by subclasses. They were really useful for creating factory methods and robust serialization, amongst other uses. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Alrighty, I guess we have a blindspot here. Let me explain:
Assume you have this class.
Why is there no way can overwrite the static constructor in a subclass when at the same time I can do it with the new Modifier? abstract and virtual would actually help remind that there is something to implement.
You all know, that this would be an easy task: using a virtual static the same way we use "new". so why the dogma, that this is not and won't ever be possible?
I know, that there are reason to prevent overusing static. because it would simply clutter RAM while being there until the program exits.
But again, after having a bit more complicated container class that has to avoid Generics (Unity3D) it would be great if I could override a virtual static once, instead of every time on an object. Call it dynamic metadata, or whatever, but without, the workaround I'm currently using is quite cumbersome. And I don't want to end up overengineering code, because the provided tech refuses to take a step forward.
Beta Was this translation helpful? Give feedback.
All reactions