-
Notifications
You must be signed in to change notification settings - Fork 5.9k
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
Update event.md - the description is hard to understand #42509
Conversation
The description is hard to understand. It uses circular references to the word event and refers to an undefined term, namely `pub;lisher class".
Hi @mpostol I agree that the existing text needs updating. However, I have a number of concerns with the proposed changes. I want to avoid the use of the term "pointer". Pointers are valid in C#, and are different than events. Accessibility is also related, but not really part of the use of the I'd start with the first sentence in the standard on events:
That still requires more, but from that start, we can add how events build on delegates: A type raises an event by invoking all the event handlers (which are delegates) interested in the event. An event handler is a delegate that has been added to the list of delegates to invoke when an event is raised. Does that sound like a better approach? What else do you think is needed? |
@BillWagner thanks for the answer. I agree with you that the documentation must be consistent so if there is a definition we must follow it. So for me, the priority is consistency. But we must also avoid logical errors like "enables an object or class ". Talking about objects we are talking about run-time. Objects are created at run-time by instantiating reference types. The documentation is about compile time so we can only talk about class as a type. But type (including but not limited to class) is only a text (snippet of a program). so the sentence "enables an object or class to provide notifications" is logically inconsistent for me, because the class is only a text so it doesn't have any behavior (it describes behavior but it is a huge difference). Let me give you an example public class MyClass
{
public delegate void MyDelegate(string message);
public event MyDelegate MyEvent;
} Can we agree that BTW where I can find the definition of the pointer term? |
@BillWagner again, Using Unfortunately in this definition, there is a next error because delegate is also a variable not only a type, for example public class MyClass
{
public delegate void MyDelegate(string message);
public MyDelegate delegateVariable;
}
Let me stress
|
@BillWagner Sorry for step by step refinement. Let's look at the event_declaration
: attributes? event_modifier* 'event' type variable_declarators ';'
| attributes? event_modifier* 'event' type member_name
'{' event_accessor_declarations '}'
;
Why not member_name = variable_declarator; |
The term pointer was used in another discussion but I think it was used inappropriately in that discussion. In the context of .Net the appropriate term is reference . The term pointer is relevant to unmanaged languages and interfacing with them. |
The following is my understanding and possible confusion. If any of the following is incorrect then it might be a deficiency in the documentation. I think the fundamental problem is that the event keyword is used in C# in a very confusing manner. A fundamental design criteria for the language is that it be readable yet I think this is an example of a violation of that. The term event is a term used with all multiprocessing operating systems. Events are synchronization objects. IBM Mainframe operating systems had events half a century ago. Windows had (has) events in the original 16-bit versions of Windows, as in Using Event Objects (Synchronization) - Win32 apps | Microsoft Learn. In .Net there are ManualResetEvent and AutoResetEvent classes. Yet the event keyword seems to mean something very different. I wish people would not call everything a keyword. When there is a specific name for what something is then the documentation should say what the keyword is. I can't find an explanation of what the event keyword is. Is it an attribute? A modifier? A type? Something else? The language specifications even does not specify what the event keyword is. Very frustrating. event keyword - C# reference | Microsoft Learn is the (this?) programming documentation of event. Note that it says that the event keyword declares an event. Further down is something interesting. It says:
Whereas in other contexts, such as for other operating systems including the Windows API, an event is very different. Microsoft's use of the term event in the context of .Net seems to be inconsistent with the typical use of the term. If that is correct then the documentation definitely needs clarification. |
My point is that we must state without any doubt if we are talking about keywords or a generic term. If we are talking about a keyword (we are talking about a programming language) we must provide
In this context, a field is a variable defined as a member of the class. If we are talking about generic terms we must provide descriptions that improve the common-sense meaning of derived terms, e.g. communication, notification, publisher, callback, method invocation, polymorphism, level of abstraction, etc. Let me stress that all are derived from the delegate and event variables. Again, in terms of the language:
The best should be if both are consistent Check out this section of my book to learn more Inter Layer Communication |
Hi friends, Good discussion, but I think this may be expanding a lot in scope. First, the language reference is meant to be an informal companion to the standard (the C# Language Specification). It shouldn't disagree with the spec, but it isn't as complete. It also isn't as formal. From that goal, here's some specific answers: I also understand the concern regarding non-English speakers. I want to be very clear on terms both so the reference is consistent with the specification and to make our translations more correct. By using consistent terms, those are translated consistently. With that, a number of specific comments:
No. A field like event isn't a variable. Field like events support
Yes.
Yes, but see "variable" comment above.
I'm not certain I understand your question. But I think I agree, and this is because a field like event isn't a variable.
Yes.
Yes.
Yes.
I think so. On the grammar questions:
Yes to both.
Because member_name might include an explicit interface implementation. (Something like
Pointers in C# are allowed only in unsafe code. We shouldn't use that term when discussing these concepts.
Well, C# And, to close this:
I think that's very close: The I hope that helps us get to a good definition to edit this PR. |
HI @BillWagner; thanks for the discussion, One more thing. Look at It is a declaration defining the event and an assignment statement simultaneously. The assignment statement, as far as I know, is available only for variables, isn't it? This operation is visible at compile time only and only inside the class, so the visibility is not symmetric. I agree that it is a special variable because it holds a reference to set. Hence we can only add or remove members of this set. Review the mathematical set theory. Unfortunately inside the class (publisher), we can also remove all members (assign null) or assign a set with a single member, can't we?
public event Func<int, int> square = x => x * x; Can we agree that the There is only one question, how broad the meaning must be scoped to make the documentation consistent, and how to explain this to someone wanting to only use this language, say engineer? In my opinion, by "Simplifying" the language syntax we are making semantics hard to understand. Fortunately, according to my experience, event implementation is always the same but the description is completely different so it could create frustration. In all the cases I know event always is a set of references to methods. The signaling event can be read as "invoking all members of this set". Rdgs, |
IBM documents computer languages differently. See Enterprise COBOL for z/OS documentation library. They have both a programming guide and a language reference. The programming guide is like the documentation that Microsoft provides. I think it is unfortunate that Microsoft omits details from the documentation that is relevant to the use of their software that is considered too technical.
My understanding is that when the
That is very confusing. The term variable is essentially synonymous with name. I do not understand what more that it implies in this context. If it is appropriate to say that
That helps. I think it is important that the documentation make that clear. Except, does |
Hi All,
I disagree, for me the variable is a placeholder for a value, so there is an available assign operation, for example, field. local variable, parameter, etc, Identifier of the variable is only a name that must be unique in the visibility scope used to distinguish it from others.
Yes. But the "set" and "reset" in your sentence I read as requests to change a condition and notify the result by activating sth (callback, scheduler, etc)
public event Func<int, int> square = x => x * x;
@SamHobbsOrg the According to my understanding, we must distinguish between the |
This conversation has expanded in scope. I'd like to do one of two things:
What are your thoughts? |
@BillWagner, I opt for point 1. It is imperfect, but I recognize it as a step in a good direction. In your proposal, consider only the definition of the subscriber and publisher roles. You are referring to subscribers, but there is nothing about publishers. You said, Go ahead. Independently I will work on a video explaining this topic in more detail. By design, it will be a section in my new book addressing delegates, events, communication, callback, and reactive programming in the context of program architecture and anonymous function. Hopefully, this video will be a good starting point for entering a discussion and proposals for conceptual docs on events later. |
The fundamental topic is the
Attach as in adding to the list, correct?
Remove as in detach, correct? Remove as in removing from the list, correct?
That is consistent with an empty list, correct? I think discussions here of the use of the term event in other contexts is relevant to any developer familiar with the term in other contexts. The most important point I think is that the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @mpostol
I made an edit to your original text this morning. LMK what you think.
Yes. However, the can't be declared as members of |
Just suggestions: An ***event*** is a member that enables notifications to be triggered. Clients can attach executable code for events by supplying ***event handlers***. The `event` keyword declares an ***event***. The event is of a delegate type. While triggering an event all supplied event handlers are invoked. Event handlers are delegate instances added to the event. Event users can add or remove their event handlers to/from an event. Co-authored-by: Bill Wagner <[email protected]>
The description is hard to understand. It uses circular references to the word event and refers to an undefined term, namely `pub;lisher class".
Summary
Describe your changes here.
I propose a new description of the
event
keyword without referring to the meaningless event word.The
publisher class
must be defined as a placeholder of the event variable but must not be defined referring to the event term.Fixes #Issue_Number (if available)
Internal previews