-
Notifications
You must be signed in to change notification settings - Fork 695
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
Get consistent on events: Either Action or event, not both #447
Comments
I did a code review of the project to get an inventory of just how good/bad of shape we are in. Here it is:
|
If an |
Commented here #621 (comment) |
@tig is there any change from yesterday? It’s because I’ve read it several times and it’s always the same thing, or else I’ll step aside :-) |
Literally just updated it ;-) |
It would be easier to read if you highlight the changes than to be reading everything again because it always looks like the same text that I end up giving up on reading it all over ;-) |
Roger. Next time I will do that. We're almost done though :-) |
I'm dealing with Button's unicode. Only in justified alignment is it a little difficult to get the hotkey position but I will get there. |
This was mostly taken care of as part of the push to 1.0. Closing. |
First, I'll point out that none of this really matters. I'm investing blood & sweat into this project because it's fun. It's a low-risk project that potentially 10s of others will use ;-). I don't really care about these topics because I'm not a professional developer. I just play one on TV.
That said, I'd love to have people using
Terminal.Gui
and say "wow, this thing is really easy to use and work great! The people who worked on it sure were thoughtful.". Of course, 99% of the credit for that will always go to @migueldeicaza.To this end: This project has become confused on whether the idiom for events is based on
Action
orevent
. In addition there's gross inconsistency between naming of events. E.g.static public Action OnResized
toApplication
.View
derived events useevent
as inpublic event EventHandler Enter
.public event EventHandler OnOpenMenu
vs.public event EventHandler TextChanged
.I'm guilty of contributing to this myself. I hereby commit that moving forward, no more. I will do better.
The best guidance on naming event related things I've seen is this:
https://docs.microsoft.com/en-us/dotnet/standard/design-guidelines/names-of-type-members?redirectedfrom=MSDN
I found this article to be especially clarifying: https://www.codeproject.com/Articles/20550/C-Event-Implementation-Fundamentals-Best-Practices
We are not consistent along these lines in
Terminal.Gui
at all. This leads to friction for adopters and bugs.Because I'm so familiar with WinForms and classic .NET
event
I have a bias for theevent/EventHandler
model.Action
seems well suited for internal APIs, butevent/EventHandler
seems to scale better for public APIs. I'd like us to minimize use ofAction
.I would like to take on fixing this (it speaks to my OCD). There's no way to do this without breaking changes, I'm afraid. But the longer it waits, the harder it will be.
My proposed Event rules for
Terminal.Gui
moving forward:Action<T>
idiom for internal APIs, not for public APIs. For public APIs we use theevent/EventHandler
model.virtual
event raising function, named asOnEventToRaise
. Typical implementations will simply do aEventToRaise?.Invoke(this, eventArgs)
.event
as inpublic event EventHandler<EventToRaiseArgs> EventToRaise
theobject.EventToRaise += (sender,, e) => {};
EventToRaise
can overrideOnEventToRaise
as needed.EventArgs
should be provided and the previous state should be included.At the very minimum, can we agree that moving forward we will follow the above rules?
You'll note that my
toplevel_ready
PR attempts to follow these rules: #446What enhancements, changes would you make to these rules?
The text was updated successfully, but these errors were encountered: