Comment on C # event processing

zhaozj2021-02-08  589

A few days ago, I learned a little C #, not very real. Because I have to engage in "MSDN development selection", I don't understand at all. Didn't look at what language book. That is, Jefferey Richter's "Applied .Net Framework" (Li Jianzhong translation) is also turned over. I am annoying that the part of Event is annoyed. The original C # Delegate and Event are just surface light, the following implementation is still very cumbersome. A long linked list, put a closed pointer inside, the type is safe enough, the space and time efficiency pay is not small. Those who have huddled from the C language from the C language, I feel uncomfortable.

The event handling mechanism is one of the largest soft ribs of C and its succeeds (Java, C #). Essentially because of the choice of C , the common message transfer of the object is solved by the member function call. The member function call is fast enough, but it has led to the tight coupling between the message sender and the recipient. In most cases, this is not a big thing, but in the event handling, the practice needs to be loosely coupled, so the problem with C is exposed. I don't see it, all GUI Framework written with C is on Event this matter. Comparison, such as MFC's global mapping table, smart, such as QT's signal / slot, one exception is VCL, Borland implements the Closure pointer, and the Caller Context is brought to Callee, Java compares the medium rules, according to the most OO The event handling mechanism is implemented, but the expansion is not good. C # delegate is actually a new version of the Closure pointer in the VCL. In short, it is the eight fairy through the sea, each showing it. But I think it is discouraged in the old road that C has already gone. As long as this idea is still there, the event handles cannot be very elegant. C # can make the whole thing look very beautiful on the surface, but it is still in the bones.

For personal concern, I still have a way to appreciate C: Provision a protocol, I am ready to put Event data in a place, then no matter what the incident's recipient goes with the data, paying own, I decide how to deal with it.

Such an acceptor, in the object classification, called active object --active object. In the middle of the Embedded System Programming, everyone is more and more discovering the advantages of active objects. I personally think that the mainstream programming field should also consider this problem.

The problem with the active object may be type unsafe, but actually type security is not so important, there is no need to die. Original C language: int (* compare) (); declared pointer can point to any function returned to an integer, regardless of its parameter list. In C , this pointer can only point to a no-array of returning integers, and the flexibility is greatly reduced. It is also no wonder that Open Source is still preferred C. Although security and flexibility are equally important, real hackers can guarantee safety in their own technologies, but they cannot accept the lack of flexibility.

Length.

In short, the more you can see, the more C is really a great language, probably only Fortran and Lisp are in the same level.

Incidentally, Li Jianzhong translated is extremely high, so that I am sighred.

转载请注明原文地址:https://www.9cbs.com/read-83.html

New Post(0)