Advantages and disadvantages of mainstream programming languages

Source: Internet
Author: User

The purpose of this article is not to provoke a language competition, but to objectively analyze the capabilities of each mainstream language, identify its length, so that programmers can develop strengths and circumvent weaknesses and effectively use various languages. It allows different languages to provide better services for you.

Programmers should be masters of the language, rather than slaves of the language. Body Here, I will compare several mainstream programming languages: C, C ++, Java,. net, Ruby, and JavaScript. I am not familiar with other mainstream programming languages, such as Pascal and Delphi. I hope that you will be able to fully evaluate these languages. As for basic, its version is very different and its capabilities are not comprehensive, so we will not comment on it here. Comparison of Language Features C ++ Java. NET Ruby JavaScript type no type strong type static type Static/dynamic static test type dynamic interpretation execution dynamic support process-oriented yes no supported Based on Object no No Yes yes, yes, yes, no, yes, no, supported templates, yes, no, no, supported object-oriented, yes, yes, no, you may have some questions about my language evaluation, please first read my other article Discrimination based on object and object-oriented programming paradigm and Application in mainstream programming languagesClarify related concepts. I am not very familiar with object-oriented and Object-based and popular definitions. Advantages and disadvantages of C Language  
C Language
Let's review the history first. The computer uses CPU commands to execute computation through registers, memory, and other items. The earliest programming was written directly using the machine code that represents CPU instructions. Directly use binary data programming, of course, it is easy to make mistakes. As a result, people later invented a way to use English words as a mnemonic, representing various CPU commands. This is the assembly language. Now, programmers can program with English words, then use an interpreter to translate assembly commands into machine languages, and then hand them over to the computer for execution. In 1970, the expert Dennis Ritchie and Ken Thompson of UNIX operating systems invented the C language to better compile the operating system. C language is more advanced than assembly language. It uses a process-oriented programming paradigm. At the same time, it is still a machine-oriented programming language that is very close to assembly language. It is suitable for programming the operating system and other hardware that can be directly manipulated. Process-oriented programming paradigm The following is the definition of a procedural design I have found: Procedural Design: 1. top-down Design: A process of top-down and gradual refinement; 2. Summarize what the entire application needs to do with the main function, and the main function is composed of calls to a series of subfunctions; every sub-function in main can be refined into smaller functions. Repeat this process to complete a procedural design. 3. features are function-centric and functions are used as the basic unit for Program Division. Data is often subordinate. Advantages of process-based design: easy to grasp and understand, in line with people's habits of thinking; disadvantages of process-based design: 1. Unable to adapt to complicated problems or frequent changes in requirements; 2. Data and operations are separated, making it difficult to modify data and operations. 3. The dependency between the program architecture is unreasonable: The main function depends on the subfunction, sub-functions depend on smaller sub-functions. sub-functions are often implemented in detail. These implementations change frequently, resulting in the following structure: the core logic of the program depends on the extended details. A small change in details may cause a series of changes. I understand the process-oriented programming paradigm as follows: process-oriented programming is a process that uses functions to represent processing. The data used by these functions is either a parameter or external data. Using function programming looks like functional programming. However, the process-oriented programming paradigm is different from functional programming. Function programming functions generally do not use external data. Do not maintain the external status. This has many advantages, but it also has great limitations and is not as convenient as process-oriented programming. C language is a typical process-oriented programming language. It abstracts process processing through functions. A function is a C language interface. In C, data is often stored as global variables. In this way, it is difficult to ensure that other code does not destroy the State of data dependent on the function by using C language programming. This is why C ++ emerged based on the object programming paradigm. Let's talk about this later. Let's look at the abstraction of machine commands in C language. C language is a language very close to assembly language. Some people say that C language is both a high-level language (process-oriented, function-oriented) and a low-level language (machine-oriented, directly reflecting the actual computing process of the computer ). The C language uses native types, arrays, and Struct to represent data. In C language, the representation of data in memory is very definite. Programmers can have full control. For example, memcpy () can be used in C to directly copy data in the memory. Currently, most operating system native function libraries use C language as their interfaces. Most languages have the ability to interoperate with C language function libraries. C language can be said to be the world of the program. Advantages of C Language 1. process-oriented development with functions as the center. Simple and effective. Implemented a simple interface. 2. Machine-oriented, allowing users to fully manipulate the machine with high efficiency. C language runs efficiently and is widely used in various computing fields. It is very effective for simple tasks.
Disadvantages of C Language
1. The function cannot effectively control the required data. The external status cannot be changed. It is prone to bugs. 2. the control on the machine is too strong, that is, the dependency is too strong. Because efficiency is too emphasized, when using C language programming, more machines need to be considered, rather than the problem itself. The abstraction capability is insufficient because the machine is too concerned, not the problem domain itself. Various bugs are prone. It is often difficult to write large programs. C language usage C language, as a simple and efficient programming language, is suitable for writing simple programs. In programming, you should pay attention to developing strengths and circumvent weaknesses, use the process-oriented programming paradigm, and use less machine dependencies. 1. When using function programming, use function parameters to pass the status as much as possible and use less global data. Because, you cannot guarantee that the global data is not changed by other code. Using a function in this way is called a pure function ". Similar to functional programming. In addition, due to the absence of global data, you do not need to consider multithreading during multi-threaded development. 2. Structured Programming is used. Do not show tricks. 3. The function is an interface. Try to use function calls instead of direct code. By layering and assigning responsibilities, you can write short, concise, and easy-to-maintain code. 4. Although C language is a machine-oriented language. However, we should rely on machines as little as possible. Consider and abstract problems from the problem domain. For example, use less memory assumptions. Because we will use many similar syntaxes in many languages, such as C, C ++, Java, and C. However, the actual performance varies with different languages. If you think too much about the machine features of C, the wrong code may be compiled due to incorrect mistakes. 5. The code is first presented to people. By the way, run the command on the machine! Do not optimize the code everywhere. Only performance bottlenecks should be optimized. Because of the optimized code, it is often difficult to understand! 6. A large amount of data related to struct should be used. When using C language programming, we should also establish the concept of type and object state. Use struct as a function parameter to transmit data.
Advantages and disadvantages of C ++ Language In C, data is often stored as global variables. In this way, it is difficult to ensure that other code does not destroy the State of data dependent on the function by using C language programming. This is why C ++ emerged based on the object programming paradigm. C ++ was originally used as an extension of C language. Its initial name was "C with class ". Later, C ++ gradually evolved into an independent language. But it is still compatible with the C language. Object-based programming paradigm Object-based programming paradigm, also known as "abstract data type" (ADT ). In the process-oriented programming paradigm, functions cannot control shared data outside functions. This makes process-oriented programming languages unable to write large systems well. To solve this problem, people have invented the object-based programming paradigm. Is to encapsulate data and data processing functions in a class. In this way, the shared data will not be changed by external code! The following is my definition: Abstract Type (ADT) ADT refers to the Organization and related operations of Abstract data. It can be viewed as the logical structure of data and operations defined in the logical structure. ADT description specification an ADT can be described as: ADT-Name {Data: // description of the logical relationship between Data elements Operations: // operation description Operation1: // operation 1. It can be used to describe Input using the function prototype of C or C ++ compiler: Description of Input data Preconditions: the status that the system should meet before executing this operation // can be considered as the initial condition Process: the operation Output: Description of returned data Postconditions: after this operation is executed, the system status // "system" can be viewed as a data structure Operation2: // operation 2 ......} // The ADT abstract data type can be seen as a model that describes the problem. It is independent of the specific implementation. It encapsulates data and operations so that the user program can only access the data through some operations defined in the ADT, thus realizing information hiding. In the C ++ example, we can use the class (including the template class) Description to represent the ADT, and use the class implementation to implement the ADT. Therefore, the classes implemented in C-producer memory are equivalent to the data storage structure and the data operations implemented on the storage structure. The concept of ADT and class actually reflects the two-layer abstraction of a program or software design: ADT is equivalent to describing a problem on the concept layer (or abstraction layer, the class is equivalent to describing the problem at the implementation layer. In addition, the class in C ++ classes is just a common type defined by the user and can be used to define variables (called objects or class instances ). Therefore, in C-producer pipeline, the actual problem is solved through the operation object, so we can regard this layer as the application layer. For example, the main program can be seen as a user's application. C ++ supports multi-model development: process-oriented, Object-based, object-oriented, and template. C ++ is compatible with C. Therefore, you can use C ++ to compile C-language programs. Therefore, it is natural to support process-oriented programming. However, can C ++ be used for process-oriented programming? In addition, it should be noted that the C ++ language is actually a new language different from the C language. In memory, except for some elements of C language, the new language elements are not machine-oriented as C. For C ++, you are not allowed to use memory-operated functions such as memcpy, and may encounter errors. Because the C ++ language is based on some advanced concepts, these specifications do not specify how memory is allocated and other machine details. On Discrimination based on object and object-oriented programming paradigm and Application in mainstream programming languagesIt has been pointed out that object-based and template-based technologies must be combined. The preferred programming paradigm in C ++ is the "Object-based programming paradigm supported by templates. Achieve static polymorphism. Then is the object-oriented programming paradigm. Achieve dynamic polymorphism. Finally, the C language-oriented process programming. How to use C ++ With the C/C ++ development environment, we can use both C and C ++ development. Since C ++ and C are compatible, I think there is no reason to use C language instead of C ++ for development. Even if it is a small problem, using C ++'s "Object-based programming paradigm supported by templates" is also the preferred development method. On the other hand, if we want to provide interfaces to other languages outside the entire class library, we should also provide C-language API functions as interfaces. C language is the world of programming. C-compatible interfaces can be obtained using the basic types of C ++, such as struct, Vector of STL library, and string: c_str () of STL. You cannot use exceptions. C language does not support exceptions, and C ++ exceptions may also be incompatible with different compilers.
  In short1. Use C ++ for development, and only use C language for development in external interfaces. Use the "Object-based programming paradigm supported by templates" or the object-oriented programming paradigm. Do not use process-oriented programming paradigms. 2. Try to put the code into the class, instead of using global or namespace variables. 3. Try not to use Operator overloading. 4. It must be noted that C ++ is not machine-oriented like C, and the memory layout of C ++ objects cannot be assumed. Objects cannot be directly built based on data in the memory. Do not perform memory operations. 5. C ++ is very machine-oriented. Many language rules define the memory layout and must be defined and initialized according to the rules. This is different from Java,. NET, Ruby, and other languages. Programmers who use advanced languages must pay special attention to the tedious requirements of C ++ and C on programmers. In the design philosophy of C/C ++, I have always taken myself as a system programming language and made many optimizations for machines. Therefore, people are not taken care. Many rules are very unfriendly. But there is no way, you must adapt to them! They are born for efficiency. They are the replacements of assembly. Java advantages and disadvantages Java is a static, strong-type object-oriented programming language. It is the product of C ++ and smalltalk. Java is a strongly typed language for static compilation. You must declare the variable type so that the compiler can check whether the code type is correct. This is the same as C ++. Java is a very secure programming language. Java only supports one programming paradigm: Object-oriented programming paradigm. The outdated process-oriented programming paradigm is not supported. Nor does it support object-based programming paradigm, nor templates. The reason may be that, when Java was just born in the middle of 1990s, process-oriented programming had been deprecated. C ++'s object-based programming method is notorious for its lack of integration with templates. C ++ has poor support for Object-Oriented Programming paradigms. As a result, Java was born as a pure object-oriented programming language. Java uses the object-oriented programming paradigm to achieve dynamic polymorphism and abstract programming methods. Great success was made. In Java, there is no value type except that the basic type is the value type, and you cannot create any value type. In this way, the path based on object programming is stuck. Although the efficiency of value type is lost, a large number of Errors Based on Object programming are also avoided. All methods in Java are also virtual functions. This is also to ensure pure object-oriented programming. Java is the peak of the static object-oriented programming paradigm. Using interface-oriented abstract programming is the only way to effectively use Java Development! On the other hand, Java is actually a dynamic language. It is executed dynamically. Like Ruby and JavaScript. This gives java the runtime flexibility. Functions that traditional static languages, such as introspection and reflection, cannot be implemented. Advantages and disadvantages of. NET Language . Net is a Java brother. It is a set of languages developed by Microsoft because Sun is excluded from Java. It mainly includes C #,, C ++/CLI, and other languages. Its design philosophy is basically the same as that of Java, and it is also a platform that supports static object-oriented programming paradigm. For the. NET language platform, I chose C # And C ++/CLI. VB. NET is similar to C. C # C #. Net also supports value types, that is, Object-based programming paradigm. (Of course, the. NET Framework also supports value types) C #. Net generic type replacement is executed at runtime. For reference types (instance types created in heap memory), it uses forced type conversion instead of source code generation of the C ++ template to implement parameterized types. For value types, the msil intermediate code generation mechanism similar to the C ++ template is used. By the way, Java's generic implementation is similar to the C # mechanism. Forced type conversion is also used. In addition, Java does not have a value type and cannot perform generic operations on basic types. Therefore, source code expansion in C # And C ++ is not a problem. But to be honest, Java's generic mechanism is indeed too weak! C # The preferred language is the object-oriented programming paradigm. C # can also use the object-based programming paradigm supported by generics. Using value types is difficult for C # and Java programmers who are familiar with the object-oriented programming paradigm. In addition, the improvement efficiency is not very high. At the syntax level, the C # generic type is a simpler method to implement parameterized types, without the complexity of the C ++ template. In addition, C # does not try to provide all the functions provided by the C ++ template. Therefore, Object-based programming supported by C # generics is much weaker than the object-based programming supported by templates. In concept, generic programming is somewhat nondescribable and has a strong Object-Oriented Programming smell. In C #, the object-based programming paradigm supported by generics is not as good as the object-oriented programming paradigm. In my opinion, the C # language should first use the object-oriented programming paradigm. C ++/CLI C ++/CLI is an extension mechanism provided to enable C ++ to use the. NET platform .. NET platform is similar to Java's execution platform for static and strong-type dynamic execution. It is the framework of the object-oriented programming paradigm concept. C ++/CLI uses the new syntax. When C ++/CLI is used for. NET development, it is similar to C # programming. You can also use the template for C ++/CLI programming. This is a new function in C ++/cli2005. When using C ++/CLI for. NET programming, you can use C #-style object-oriented programming. You can also use the object-based programming paradigm supported by templates for development. It can combine the object-based programming paradigm supported by templates with the. NET Object-Oriented Programming Paradigm. C ++/CLI can use both native C ++ and. NET programming. If the. NET Framework is used for execution, the C ++ native code will be stored in the generated msil intermediate code and compiled into a machine code using the C ++ compiler at runtime.
  . NET Interoperability Mechanism . NET is written by COM and is a COM server. Therefore, the interoperability between. NET and COM is very simple. You can also use COM technology to directly call methods in. NET using C/C ++. In terms of interoperability .. NET is better than java. Java methods cannot be called in C language, but JNI can only be used in java code to call C methods. Overall rating . NET is a java table brother. Another change was made. 1. defines the. NET assembly language. The. NET-based assembly language supports execution in any language on the. NET platform. Java can also be used as a platform. However, the java platform is designed to be a java language, so there is no definition of assembly language, and only java machine code. 2. supported value types. Although it is not very useful, it can improve performance and facilitate interaction with the C function library. 3. The implementation of generics is more powerful than that of java. 4. In particular, C ++/CLI has the powerful capabilities of the template *. NET Runtime Library. Ruby advantages and disadvantages Ruby is a strongly typed dynamic explanatory language. Everything in Ruby is an object. Use Duck Typing to program like a Duck. Ruby has a type, but the variable is not sure about the type. This also achieves dynamic polymorphism. Unlike static object-oriented programming languages such as Java and. NET, they do not need to be used, but only represent type-standard interfaces. When using variables in Ruby, you do not need to declare the interfaces or types used. Any type is acceptable, as long as such a method or data member exists! Similar to C ++ template programming, only the C ++ template needs to specify the parameter type. Ruby does not need to specify the variable type, so it does not need a mechanism like a template. Ruby is flexible to use without specifying variable types. From the perspective of Dynamic Language, since the runtime errors cannot be fully identified during compilation, it is better not to check during compilation or compile. Use unit tests to find errors. However, languages such as C ++, Java, and. NET also have their own advantages: 1. more secure, errors will be found during compilation. 2. Smart prompts of IDE can be implemented. Ruby is not a language like this. Because the C ++ and Java variables all specify the type, you can intelligently prompt possible members in the IDE. The variables in dynamic languages such as Ruby do not specify the type, so you cannot provide smart prompts. When using Ruby, you should use the object-based programming paradigm of "dynamic type language" and use implicit interfaces. The classes used do not need a common base class. Make each implementation class independent of each other. Remember, this is an object-based (ADT abstract data type) programming similar to the object-based programming paradigm supported by C ++ templates! Do not try to write Ruby programs using object-oriented programming methods like java and C! Advantages and disadvantages of JavaScript Language JavaScript is a language that has been ignored for a long time. Its importance and capabilities are greatly underestimated! This is because, since the rise of Java and. NET, the object-oriented programming paradigm of "static type language" has been widely respected. As a dynamic language, JavaScript in Functional Languages has long been regarded as malformed geeks by Java and. NET programmers! To be honest, I have always looked at it with disgust for a long time. How many times does it make me crazy. I still haven't learned JavaScript well till now. Although JavaScript has been born for so many years, it is still a new thing to look at functional languages as a promising dynamic and strong language. We have not seen much research on this and design patterns. Zhou Yimin's book "The essence of JAVASCRIPT language and programming practices" should be good, but I have not read it yet.
JavaScript supports process-oriented programming paradigm
This is the most widely used programming paradigm in JavaScript. Simple, fast, and effective. JavaScript code needs to be transmitted to the user's browser over the network. Therefore, JavaScript usage is generally a few simple data submission and verification functions. If we use Ruby-like Dynamic Object-based programming paradigm encoding, it seems a little complicated and a waste of bandwidth. JavaScript supports the object-based programming paradigm of "Dynamic Language" If JavaScript only supports outdated process-oriented programming paradigm, JavaScript is really a weakness for everyone. Over the years, many programmers have neglected that JavaScript is also a dynamic language or a function language! We can perform object-based development like Ruby. Now, with the user's expectation for the client performance and AJAX technology. JavaScript is doing more and more tasks. A large class library similar to the traditional language library is being developed. For example, the user interface library implemented by EXT. It is very similar to the Swing library of Java. The object-based programming paradigm must be used for such a huge system, and the process-oriented programming paradigm cannot be imagined! Using JavaScript as Ruby is my advice. [Aside: but maybe my JavaScript technology will never be very high. Although I'm more and more familiar with the JavaScript language mechanism. However, I am not very interested in the development of user interfaces. I think the user interface is a gossip. The underlying logic development is more valuable, and I am more interested.] SummaryNow let's take a look at the first "Comparison of language features". Maybe you can agree with my views on these languages. If I need to develop a native system, I will choose to use C ++ and use the object-based programming paradigm supported by the template for encoding. If you need to provide interfaces to other languages, I will use pure C language to implement some interface functions for other languages to call. If you need Java for development, you must use object-oriented programming. A large number of interfaces are required and dependent on abstraction. If you need to use. NET for development. Then I will also use object-oriented programming paradigm encoding. The value type is rarely used. If C ++/CLI is used for development, I will use templates to develop native C ++ programs, and I will also prefer templates to develop. NET programs. You can also use the object-oriented programming paradigm to develop. NET programs like C. I really love the template! Over the years, I have always considered the template a waste of wood! If you want to write scripts, I will use the object-based programming paradigm of Ruby, "Dynamic Language. Both Java and. NET platforms are introducing Ruby, Python, and other dynamic languages. Maybe you can use them to develop Java and. NET programs soon! I used JavaScript For browser development. [a long time ago, I used the VBScript language-I got started with Microsoft. At that time, I thought that Microsoft would be good.] Simple requirements, of course, are developed with a process-oriented paradigm. Large projects, such as AJAX, maps, and GUI, are developed using the object-based programming paradigm of "Dynamic Language.


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: 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.