[Proposal]: Re-rename to Roles and Extensions #8943
Replies: 8 comments
-
I get the argument, and I could agree it’s better than “implicit/explicit” extension, but I can’t shake the feeling that “role” is weird. Because an explicit extension/role is still conceptually an extension of the specified type, just one you only use in specific situations - a proxy type of sorts. I don’t know; Just my $0.02. |
Beta Was this translation helpful? Give feedback.
-
Just my 2 cents: if we want to drop implicit/explicit, would "extension type" not be an option for roles? I agree that "role" sounds weird. To me an explicit extension (a role) is really just a type. You treat it exactly as if it were an actual type in code (you use it to declare parameters, locals, can cast to it, etc.). It's just that it's specifically also an extension, not a "real" type. So to me "extension type" seems intuitive in that sense, more than "role". With the latter you get into "what is a role", "what does a role mean", etc., whereas with the former, people will just look at it as "oh ok, it's just a type I can declare an use, cool". |
Beta Was this translation helpful? Give feedback.
-
I suggest we use "extension types" instead of "extensions" for implicit extensions. I think we will want to distinguish these from extension methods and also discuss the two in combination. |
Beta Was this translation helpful? Give feedback.
-
One thing I kind of liked about the |
Beta Was this translation helpful? Give feedback.
-
With the name |
Beta Was this translation helpful? Give feedback.
-
To me, it's the other way. |
Beta Was this translation helpful? Give feedback.
-
I imagine C# could fake it by emitting an unspeakable function name to IL and mapping it to the declared name for source code. Though it would be better if the CLR would add extension/role types to the type system. |
Beta Was this translation helpful? Give feedback.
-
Just happen to see this was changed into role so pardon me for duplicate I am not so sure about current use case of I think Suppose we have public class Person
{
public DateTimeOffset birthDay;
}
public extension PersonExt for Person
{
public TimeSpan Age => DateTimeOffset.Now - birthDay; // everyone has age
}
public role Adult for Person // not everyone is adult
{
public static bool operator is(Person person) => person.Age.TotalYears >= 18;
public bool HasJob => false;
public bool Occupation => "College Student";
}
////
Person person0 = LoadFromDB(pid0);
if(person0 is Adult adult0) // check with operator is
Console.WriteLine(adult0.Occupation);
var adult1 = (Adult)LoadFromDB(pid1) // null if operator is return false Alternative syntax might be public role Adult for Person when (Age.TotalYears >= 18)
{
public bool HasJob => false;
public bool Occupation => "College Student";
} |
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.
-
Re-rename to Roles and Extensions
This has been moved to https://github.com/dotnet/csharplang/blob/main/meetings/working-groups/extensions/rename-to-roles-and-extensions.md.
Beta Was this translation helpful? Give feedback.
All reactions