Why don't by signature! -Response to Zhiqiu yiye

Source: Internet
Author: User

Original: http://blog.joycode.com/qqchen/posts/19255.aspx

Thank you for your patience and explanation. However, I feel that this person is stubborn.

Some friends think that I am not satisfied with. Net generics because there is no special feature. In fact, this is not the case. I understand that. NET is hard to implement special features because. Net has chosen genericCodeSharing, although this makes it difficult to implement the feature, it is not a no-reason choice. (Of course, I think there is no mistake in C ++'s choice, because in C ++, if there is no template, you must write a vector for each class, therefore, it is better to make the template automatically generated because C ++ does not have a public base class system. object)

At the same time, I understand constraints very well. It is precisely because C ++ does not display the concept of constraints (although the constraints are already hidden in the compiler's work) that lead to many errors, (Of course, there is also a typedef error: P). I have not forgotten how I feel about the error information when I do not understand the template Technology (even if it is still very big ). I was very excited when I first heard about the concept of. Net generic constraints.

However, I am disappointed with the implementation of constraints in. net. The constraint I imagine is the implementation of by signature mentioned in your article.

There is a reason to choose a technology. I just want to know the implementation of constraints in. Net to reduce the cost of generic flexibility?

We all know that, even if. Net has such powerful execution period type support, the check on generic parameters is still completed in the compilation period just like C ++. It means that for a generic class, check whether the type parameters meet the constraints. For a generic method, check the passed parameters.Declaration typeIs it compliant with the constraints. Note that it is the declaration type. The experiment I have done for this is my final effort to find the reason for choosing the current implementation of this constraint. However, I actually know that this experiment is boring, because the check for generic parameters cannot be based on the actual object type, not the object declaration type, this is intolerable because the generic parameter check will be postponed to the execution period.

So now I can't think of any reason not to choose the by signature method. The only possible explanation is that the current implementation is more "Object-Oriented. By signature is clearly not tolerable by the purely theoretical people of OO, but by inheritance is very beautiful and very oo. I hope that the above speculation is just my little friend's view.

I think I just have a little regret. But C # always needs to be used. It cannot be changed for me, but it can only be changed by myself. Besides,. Net has a generic type. Although unsatisfactory, the generic hashtable is much more cute than the object version.

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.