Originally, I have to continue writing to the other two of the Foreach series of articles. But I have reviewed the C # event handling, there are some feelings.
I don't have a good point about the language, the higher the efficiency of running. The lower the language, the less the compiler can decide, the more you can't optimize the execution code. Everyone thinks why the C language compiler, generally ignore the register keyword, C generally ignore the Inline keyword? Many times, the compiler can make a wise decision as long as the compiler has mastered enough information. I used to measure the code generated by Delphi and C , and the code of Delphi is much efficient than C . Because the pointers are widely used in C / C , the position of the variable, the arrangement of each member of Struct, and the call agreement are very strict restrictions on the compiler. The compiler can only be faithful to translate and miss a lot of opportunities to optimize the code. In order to enjoy various code optimization techniques, both C compilers provide a lot of compilation optimization options, but most of them are not 100% secure. Because C / C programmers can always complete a lot of low-level operations. For example, use const modified variables that will not be modified, the compiler can utilize this knowledge to deliver the value of this variable in the register. However, in C , this optimization cannot be performed because the C programmer can force Cast to drop CONST restrictions. Maybe everyone thinks that the compiler can monitor this CAST, automatically turn off this optimization, but who can ensure that the code in other. Obj file has been modified this const variable?
The same private member is also difficult to truly implement access tracking in C . How can the compiler do not have 100% confident knowledge?
The best car in the world is hand-made, but it is not good to say that the craftsmanship must be better than the industrial batch.
What I want to write the most important thing is how the clearest expression we have to solve, not too much to resolve the issue of the problem. We want a report, order; rather than memory, pointers, functions. If we can describe the problem from a higher, more abstract level, it will leave a space for the underlying software. For example, the underlying software can choose low operating efficiency, high development efficiency method completion, and fast production prototype, display design; or underlying software to select high-speed operation, the operational time requirements are high; or select low memory occupancy Target, etc.
Rules are not constrained in creative power, but motivated to creatively foundation. There is no stable rule, what will be created? I think .NET rules, is the beginning of stimulating creation, is the beginning of a new world.
Some people question C # Complete the event model is too concealed, bloated, and IL is not directly corresponding, too complicated. The EVENT keyword completes multicast events, asynchronous events. Think about Java in order to achieve a multicast event, clearly using a list. Although C # also uses a list to implement multicast, the fact is not clear in the syntax using the list. What is this difference? This is of course different! This list is not generated when there is only one function pointer in Delegate, and the call is also straightforward and there is no call loop. In addition, C # can also achieve asynchronous events through Delegate, unified asynchronous I / O programming model, recently ADO.NET also performs an asynchronous execution SQL statement. The Interface implementation of the Java event, to complete the asynchronous event, don't know how much code you want to use. And as long as the code is written, it is dead, and the operating environment can no longer be further optimized.
For example, do a taxi, if you tell the driver, the driver can integrate the length, congestion of the road, and choose a optimized solution. On the contrary, if you tell the driver your route, then everything is fixed, rigid, and the driver has more knowledge, it can't be used. The difference between advanced language and low-level languages is a truth with this real life. Maybe many people don't agree, think that they are both passengers and drivers. But do you think you really know all your computer knowledge? Different CPUs, the difference in Cache efficiency, the difference in bus efficiency. The hardware impact software has a lot of elements, and the impact of software is more. Modern software relies on a large number of operating systems calls, library functions calls, compilers, and more, who can know that in tens of thousands of functions, that is high, that is low. We optimize the performance improvement of several weeks of code, will be easily engaged by a wounded library function. Is it possible to optimize a system, change an environment or high efficiency? For example, the user machine replaces the graphics driver? No one will have the ability to make a good driver. Let the C # language that truly operate knowledge, .NET running the environment to complete 95% performance optimization for us, we can do a good passenger, saying that our destination is great success.