C #: Yesterday, Today and Tomorrow: Discuss with Anders hejlsberg, part 2

Source: Internet
Author: User
C # : Yesterday , Today and Tomorrow : Discuss with Anders hejlsberg, part 2

Source post address:


C #: yesterday, today, and tomorrow

Author: John Osborn
10/17/2005
Translation: I want to go to Guilin

Osborn:

Back to the language-related questions, I still want to talk about LINQ. Tony goodhew, product manager of Microsoft Visual stuido. net, said in an interview that Microsoft's research shows that more and more people tend to work in two or more languages in programming. It seems that there is a feeling that the language is just a sugar block in the syntactic sugar syntax. You choose a language because you are most satisfied with him.

Do you think there is such a change? We have not talked about this before.

Hejlsberg:

Well, I have never talked about it, but is the syntax coming to an end? I mean, we only use XML documents to describe the abstract syntax tree to show what you want to do. This is also a syntax, but obviously it is not very useful for programmers. Therefore, I think that programming languages occupy this special position in people's minds. If people speak in languages, they can express themselves, programming languages are also used to express yourself like natural languages.

In fact, syntax is the composition and expression of a programming language. In many ways, syntax affects how you think about your program, and so on. Therefore, I think the syntax is very important.

Osborn:

From the perspective of syntax, what is special about C? Can you describe it to us?

Hejlsberg:

Well, I think the feature of the component-oriented class we are talking about now is extremely important. There is no other way to do this. We try to find the synergy between syntaxes. I mean, this is hard to be accurately described in languages. Let's take a look at the language-level integrated LINQ query. This scalable model is implemented by calling methods.When you use where, orderby, and select statements to write query statements, we call the following methods to convert them into pairs: Where, orderby, and select. We pass the query you wrote to the related method as a Lambda expression statement.

In this way, the query becomes a method call that is connected together, so that the query and selection become more readable, just like a language glue. The preceding conversions are executed immediately, just as a foreach loop is converted to a number obtained from a while loop. This small improvement helps you think about problems at a higher level. Do you understand what I mean?

Osborn:Yes.

Hejlsberg:In this regard, the syntax affects how you think about the problem to a large extent, even though these syntactic things have nothing to do with things themselves.

Osborn:

Yes. From the perspective of Book Publishers, our company's own historical data shows that the ancient C ++ language has its own territory, and there is only a small growth in the volume of books published; VB sales fell by 20 to 25 percent last year. C # The book sales volume is still stable. But it's plain.

Hejlsberg:Oh, that's it.

Osborn:

The situation is clear. From our sales volume, there seems to be a shift from VB to C #, or something else. However, C ++ has been a part of the market from start to end.

Hejlsberg:

Yes. VB and C # compete with each other in the same programmer group. C ++ plays this special role, but the core of C ++ is to write unmanaged code, which is relative to the underlying programming. I know that I just explained the generalization. You can also use STL for Template-based programming. The standard template library has its greatness. I just said that in a broader context, the applications written in C ++ and those written in VB and C # are used for different purposes.

Hejlsberg:I am not surprised at the decline in the C ++ application field.

Osborn:

I know that a person cannot use C ++ to write managed code.

Hejlsberg:

From my perspective, I will not use it to write managed code. However, if you want me to write a compiler that cannot host code, I will still use C ++.After so many years of development, I think there will be more and more reasons to write managed code as a general rule. The reason is simple. Hardware becomes more powerful, and it becomes more important to sacrifice CPU and memory for higher production efficiency. I think this is a very valuable proposition. In addition, I firmly believe that this will gradually become a consensus. In addition, hosting the world has become even more exciting. That is to say, the more innovative there are, the more applications applied by enterprises.

Generic and C #

Osborn:

With so much ridicule, let's talk about C #2.0. Obviously, C # has been developing towards generics for a long time.

Hejlsberg:Yes.

Osborn:

So what is the difference between C # generics in other languages?

Hejlsberg:

Haha, come on. Obviously, I 'd like you to say: just compare it between C # and Java.

Osborn:That's what I mean.

Hejlsberg:

First of all, I am very happy that we have added generic programming in 2.0.As you can see, many of the things in C #3.0 are being processed by generics. This is indeed far-reaching. The introduction of generics opens up a new space for the Type System and opens the door to achieving more possibilities.For example, without the help of generics, we cannot perform language-level integrated query of LINQ. In this sense, this is the engine behind more interesting functions. Generics are also a good helper for solutions in the real programming world.

Yes, it is good to have more types, which means you can find errors faster, because there are only a few types of dynamic check programs at runtime, therefore, you can write good code.

Now, let's take a look at Java and C #. From the perspective of grammar, we can see that the two forms of implementation of generics are very similar. They are all like C ++ templates, which are inherited.

Now let's look at the essence., JavaAndC #The generic implementation mechanism is completely different. In my opinion, the biggest difference is that generics on the. NET platform are not just a language feature. Generics are rooted in Clr and. Net Type Systems. This is why generics can be displayed during running.

WhileJavaThen, a different method is selected to implement generics.,In a word,They are implemented during compilation. In addition, the Java compiler removes generics from the code and injects objects. Valid objects replace the type parameter information.That is to say, Java has no generics at runtime. This is interesting. On the one hand, the generic model can be run on an unmodified Vm, and on the other hand, many surprising restrictions and rules can be imposed on you. Compared with our generic implementation, Java Generics do not bring performance benefits. Obviously, no matter how generic the list <t> looks, java has no generics at all during runtime. You have to perform dynamic check and type conversion at runtime on your own.

Even more subtle, Because Java does not have generic information at runtime, you have lost generic information from your compiled code .. If someone gives you a set of custom objects during luck, all they send to you is objects, if you want to guess from the object that more information about these objects cannot be done, because the additional information has been removed.

In the real world, we are increasingly dependent on the dynamic generation and check of code and dynamic behavior in the running process. Java's generic implementation is a big problem for me, he lacks the real performance when the program is running.

Osborn:

So, the wildcard implemented by. Net allows us ......

Hejlsberg:

That's right. If I define a list <t> as an object, I can ask "what is this"? The system can tell me that this is a list. He can also tell us that this is a list <t>, and t represents the MERs class. I can also say: Why not give me a list of system. Type <t>? Why didn't you bind t to order? In other words, we can convert the type to list <order> and create an instance of this type. I have said so much. In short, I can implement the above functions during compilation and running through reflection. This is a great feature.

 

Related Article

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.