C ++ Criticism

Source: Internet
Author: User
C ++ critical Criticism

1. Is typedef unnecessary?

A. typedef provides an indirect layer. In object-oriented languages, interfaces mask differences between different types during runtime, while typedef masks differences between different types during compilation, without losing type security
B. Generally, the language can only return "values", while typedef provides the ability to return "types". This is an indispensable mechanism for template metaprogramming, unless the template metaprogramming is not necessary at the moment.

2. Import

# Include and Private Members are put in the header file in different locations, and the inline function is also criticized in the header file. In fact, there is only one reason: C ++ is not a platform and it has no binary standards, it becomes a local code after compilation, and all types of information are lost. Only by solving this problem can we solve various problems related to distribution, reuse, and import.

3. Is the reference redundant? Will be damaged?

A. The resource release reference is clearer than the pointer, that is, the original object is provided to release the resource. Once the pointer is used as an interface parameter, You need to specify who will release the resource.
B. null reference does not exist in the well-formed program, because the only way to generate it is to raise the airspace pointer, and lift the airspace pointer is undefined, the program will soon make an error, instead of some operations wrong, some do not, sometimes error, and sometimes do not

C99 also supports references.

4. Duplicate inheritance

C ++ lacks the "direct repeated inheritance" mechanism owned by Eiffel. But if so, what is the meaning? I have never seen Eiffel.

5. Multi-Inheritance

The elaboration is more incisive. the inheritance of multiple processing is the weakness of C ++. Java prohibits the inheritance of multiple implementations, however, the "single-implementation inheritance + multi-interface inheritance + internal classes" provided lacks flexibility and intuition.

6. Does the internal class destroy object-oriented? Damage reusability?

Unfair. Unless the object-oriented interface is excluded, reuse only ends with source code reuse. 1. Internal classes provide better encapsulation. 2, after simple packaging, internal classes can provide interface-oriented reuse in the form of executable code. An example is "list collections. unmodifiedlist (list) ", which can be elegantly implemented by internal classes (I do not know how to implement it)

7. Virtual/override

C ++ and C # Give the base class authors great responsibilities, and these should be the sub-class authors; including the virtual base class in C ++, subclass changes force the parent class to make changes

8. Virtual type

In this article, C ++ only provides parameterized classes, but does not provide virtual types. From the examples of the virtual types mentioned above, it seems that typedef, despised in the previous article, can be used to complete the process.

9. constraint Polymorphism

In C ++, it is generally referred to as the template parameter constraint and is being considered to be added to the next version of the standard. However, if it is only used in the example in the book, the template parameter constraint is used to implement an interface, so we can use interfaces as parameters. Why do we need generics? Generic expressions indicate a concept. The generic parameter check should also be concept check, rather than type check.

10. Access Control

Without restrictions on the access permissions of sub-classes, Eiffel can be regarded as only one feature, not necessarily an advantage. Based on the two different understandings and focuses on reuse, c ++ and Eiffel have two different attitudes towards sub-classes. The examples cited in the criticism of C ++ private inheritance are not appropriate. The root cause of the problem is forced transformation rather than private inheritance.

11. Expand an object

For ". the criticism of "and"-> "is too isolated. In fact,"-> "is an operator that can be reloaded. It provides an indirect layer that can be used to do many things: Resource Management, the inheritance convenience is obtained in an inclusive manner (the method of automatically "owning" the object to be tolerated), and so on. Eifel provides "expanding the object" without knowing the specific semantics.

12. Duplicate inheritance

Here we can see a usage of directly repeating inheritance in Eifel: It was originally used to call the method of the parent class with the same name in the subclass; this usage can also be discarded as precursor joins the language

13. Change resistance and coordination

The returned value does not seem to have much covariant issues, and the parameter resistance does not seem to have much problem. The problem is that the parameter covariant; Eiffel provides the current and like solutions, c ++ can only look forward to being generic.

14. Force interface-specific programming

The author believes that changing the public member of the parent class to "protected" or "private" in its definition in the subclass will lead to a problem of covariant. In fact, as long as the semantics of the redefinition function is correct, there is nothing to do; in addition, this change will bring about another effect: forcible interface-based programming, because at this time, your client programmer can only reference your subclass object through the parent class to access the redefined members.

15. Garbage Collection

Or those topics, or those arguments, or the outside-memory resource management should not be avoided; isn't it possible to "destructor + stack object + heap object garbage collection "? C ++ only lacks the "heap object garbage collection" by default, and smart pointers can last for a while. Java and Eiffel lack the "Stack object + destructor"

16. Contractual design and CORBA IDL

The author believes that the failure of the Contract Design supported by the corba idl is a defect, but I never dared to use it in my DCOM, RMI ,. use assertions in the net remoting component, including the original socket server. This is exposed in the network environment, and an exception is thrown in violation of the preconditions. WebService is slightly better, clearly defined exception handling with middleware support

 

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.