Views on C # language evolution

Source: Internet
Author: User

I just saw an interesting article about misuse of Dynamic Features in C #4.0. I very much agree with the author's point of view. With the development of C #, the syntax is becoming more and more complex, no matter whether you are showing off, following the trend, or failing to understand the language features, misuse is growing. Of course, everyone has different perspectives and opinions, because most of the programs I write are real-time Programs , most of the Code is running more than 60 times per second, so it is more sensitive to performance. Here is my personal opinion. I am not afraid of jokes. Most of my code has been written in 1.0 or 2.0. It can be said that after 1.0, most Syntax Evolution aims to write more concise code and accomplish more tasks with less code, which is expected by everyone. Unfortunately, most of these features are not evolved from the language itself, including delegate inference, anonymous methods, VAR, etc., but through compiler extension. There is no free lunch in the world, and the code is the same. Although we write a lot less code through the new features, it does not mean that much code is executed, these less written codes are generated by the compiler. What's more, the compiler needs to generate more code than Manual Optimization for some seemingly simple expressions. The hidden complexity is terrible, but what's even more terrible is that not all programmers are aware of the potential complexity, and they use the new features of these languages to write code, but I don't know what the code is written ".

For example, for the same code: button. Click + = new eventhandler (addclick) and button. Click + = addclick. For the latter method, many people will only think of "we subscribe to an event", but for the first write rule, they will think of "We * created * a delegate, and subscribed to the event ". New is very helpful here. It tells us that this line of code creates an object with additional memory overhead! Furthermore, you won't write such code when writing high-frequency programs, because even the smallest memory allocation, 60 calls per second, may consume a large amount of memory in a short time, or create a massive amount of garbage. Of course, I believe that experienced programmers will not make such mistakes, but who can ensure that when the project reaches a certain scale, when we are used to the convenience brought by the new syntax, will there be no similar problems? Therefore, although the old-fashioned syntax is complex, it gives you a clearer reminder of what you are doing *.

Let's take a look at dynamic in MySQL 4.0. The advantages of dynamic are not mentioned. It has been widely used since beta.ArticleBut the question is, do you really need to use dynamic immediately to change the existing code to the dynamic style? Even though dynamic greatly improves the flexibility of code writing, it also increases the chance of errors, not to mention the corresponding performance loss. Even android himself said that he prefers static languages. I have seen many people complain that Ms updates are too fast. In fact, this does not mean that we must update at the same speed. New features only give us more choices, also, depending on the actual situation, if the static C # is sufficient to meet the current needs, then there is no need to care about dynamic (of course, I am not opposed to learning more ). When time and energy are limited, it is hard to follow the trend blindly.

For 4.0, I am most interested in thread management and GC optimization, and parallel programming (PP ). Obviously, both of them are performance-related. In fact, I have written an article about PP, but I haven't published it yet. Here is a brief description. It is undeniable that PP will be a revolutionary Programming Method in the future, but there are two reasons for me to give up the current engine of PP applications. 1. Task objects cannot be reused, after a task executes a program, if you want to perform the same operation, you must create a new task object. 2. Whether it is a task or parallel for, it will bring about a certain amount of memory allocation (see, this is a hidden complexity ). Like the previous delegated example, applying task or parallel for to the main loop of the game engine means a lot of GC pressure, it is difficult to determine how much performance improvement can be achieved in complex situations. As a brand new technology in 4.0, PP is not completely mature like DLR. MS is always available only in the third version, so there is no need to rush to use it :)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.