-
Notifications
You must be signed in to change notification settings - Fork 140
generator: Overhaul GInterface type naming approach #113
base: main
Are you sure you want to change the base?
Conversation
Hello! I'm the build bot for the Mono project. I need approval from a Mono team member to build this pull request. A team member should reply with "approve" to approve a build of this pull request, "whitelist" to whitelist this and all future pull requests from this contributor, or "build" to explicitly request a build, even if one has already been done. Contributors can ignore this message. |
This would prevent also some "head scratching" when people in the past inherited from IFoo and saw that their class was not working. |
In the past, for the GInterface Foo we used to have: a) FooAdapter: the helper class to use GInterface implementations. b) Foo: the interface with the methods from native side. c) FooImplementor: the interface to inherit from .NET classes. Learning about these special suffixes "Adapter" and "Implementor" was a bit cumbersome and not very API-consumer friendly. Some months ago we modified gtk-sharp's generator to follow the "I" prefix convention for .NET interfaces, which leaves us as: a) FooAdapter. b) IFoo. c) IFooImplementor. This is good because now the name "Foo" is free, so we can rename "FooAdapter" to "Foo", and there's one less thing to learn (so this is one of the things this commit achieves). The next step is, then, getting rid of the "Implementor" suffix, how? Simply switching the way this is exposed, as: b) IFoo -> IFooBase c) IFooImplementor -> IFoo This way, if one wants to create a .NET class that implements the GInterface Foo, she simply needs to inherit from "IFoo". And when consuming, from .NET, native classes that implement the Foo GInterface, the interface they will implement will be IFooBase instead of IFoo (but there's no need to learn this because by using the API you will simply be exposed to it). Reviewed-by: Stephan Sundermann <[email protected]>
We also rename "Implementor" property of adapters to the slightly more convoluted "VirtualImplementor", but the reason is that Atk.Implementor.Implementor wouldn't be a valid property because its name would match with the class name.
Love this, having IFoo and Foo is great! Not sure about the IFooBase naming, though... what's it the Base of? Base is usually used to mark abstract or base classes that provide basic functionality, not really interfaces, and it's a really generic name. Maybe IFooNative? |
Most of the time, IFooBase is a super-set of methods from IFoo, containing the virtual methods that you can override (via inheritting from IFoo in .NET, or by privately overriding in C in GObject), plus the methods that the GInterface provides with a "base" implementation (like a Mixin) which AFAIK cannot be overriden. That's why I used the word "Base", but certainly any other suggestions are welcome (Native suffix is interesting, maybe better indeed, although I have the feeling that someone will come here soon with an even better suggestion :) ). |
I agree that it's not a very intuitive API and that it requires reading some docs and/or code samples before being able to use it. But I'm not sure, if this can be solved by changing the naming, because in my opinion inheriting from any IFoo (current naming) is comparatively complicated - and the current naming reflects that (it doesn't make it worse). I think, the easiest way to improve the current system is to improve documentation about it. About the name suggestions: |
Hello! I'm the build bot for the Mono project. I need approval from a Mono team member to build this pull request. A team member should reply with "approve" to approve a build of this pull request, "whitelist" to whitelist this and all future pull requests from this contributor, or "build" to explicitly request a build, even if one has already been done. Contributors can ignore this message. |
Thanks everyone for this proposal and for your comments. I'd tend to be of the same opinion as Antonius, so in favor of keeping things as-is.
My guess would be that IFoo is currently used more often than IFooImplementor, so better keep the more frequent form as straightforward as possible. Furthermore, after we apply this, I think it would be more confusing for people porting their GTK 2 code: if they were using TreeModel with GTK 2, they should now change it to ITreeModel, even if a TreeModel class still exists. So I think the pain inflicted on existing code is not justified by the potential gains from this naming change. I'm keeping this open for now, maybe I can change my mind. |
Thanks for keeping it open, because I have some more ideas in my head that I would like to explain carefully in the coming days/weeks, which maybe are better suited. |
After a bit less than a year, I've come back to this PR :) I have two questions:
|
@knocte:
And the subclass consumer would use it like this:
With the current model the subclass consumer writes code like this:
ad 2) As I said before, it certainly would be possible to use "IFooImplementation" instead of "IFooImplementor". I'm just not sure whether the gained value is enough to merit the change. |
With all that I wrote in the previous comment, I still think its best to leave things naming-wise as they are, or to change the way GInterfaces are exposed entirely. If it is possible (from a code generation point of view), the easiest to use C# model to expose GInterfaces would be:
with
This, however, is totally outside the scope of this PR. |
In the past, for the GInterface Foo we used to have:
a) FooAdapter: the helper class to use GInterface implementations.
b) Foo: the interface with the methods from native side.
c) FooImplementor: the interface to inherit from .NET classes.
Learning about these special suffixes "Adapter" and "Implementor" was
a bit cumbersome and not very API-consumer friendly.
Some months ago we modified gtk-sharp's generator to follow the "I"
prefix convention for .NET interfaces, which leaves us as:
a) FooAdapter.
b) IFoo.
c) IFooImplementor.
This is good because now the name "Foo" is free, so we can rename
"FooAdapter" to "Foo", and there's one less thing to learn (so this
is one of the things this commit achieves).
The next step is, then, getting rid of the "Implementor" suffix, how?
Simply switching the way this is exposed, as:
b) IFoo -> IFooBase
c) IFooImplementor -> IFoo
This way, if one wants to create a .NET class that implements the
GInterface Foo, she simply needs to inherit from "IFoo". And when
consuming, from .NET, native classes that implement the Foo GInterface,
the interface they will implement will be IFooBase instead of IFoo
(but there's no real need to learn about this latter suffix, as by using
the API you will simply be exposed to it).
Discussed with and reviewed by: Stephan Sundermann <[email protected]>