Current location - Education and Training Encyclopedia - Education and training - Java Training of Beida Jade Bird: Advantages and Disadvantages of C Language Programming Technology?
Java Training of Beida Jade Bird: Advantages and Disadvantages of C Language Programming Technology?
With the continuous development of Internet programming technology, most software development is now realized by programming languages. Today, let's learn about the advantages and disadvantages of C programming technology.

Some good experiences of C language have learned how to realize object-oriented programming in C language by reading POV-Ray source code.

By reading GTK+ source code, we can understand the clearness, cleanness and maintainability of C language code.

By reading the source code of SIOD and Guile, we know how to implement Scheme parser in C language.

Write the initial version of GNOMEEye in c language to optimize the rendering of micro-files.

Some bad experiences of C language When I was in the evolution group, many things always crashed.

Wharton Park didn't exist at that time. In order to get Purify, you need to buy a Solaris machine.

Debugging gnome-vfs thread deadlock problem.

Debugging Mesa, but nothing.

I took over the initial version of Nautilus-share, only to find that free () was not used in the code.

I want to refactor my code, but I don't know how to manage my memory

I want to package the code, but I find that there are global variables everywhere and there are no static functions.

But anyway, let's talk about something that is in Rust but not in C language.

Automatic resource management Rust draws lessons from some ideas of C++, such as RAII (resource acquisition initialization) and smart pointer, adds the principle of single ownership of values and provides a resource management mechanism for automatic decision-making.

Automation: You don't need to call free () manually.

Memory will be released automatically after use, files will be closed automatically after use, and mutexes will be released automatically outside the scope.

If you want to encapsulate external resources, basically you just need to implement Drop trait.

A packaged resource is like a part of a programming language because you don't need to manage its life cycle.

Decision: Create resources (memory allocation, initialization, opening files, etc.). ) and then destroyed outside the scope.

There is no such thing as garbage collection: when the code is executed, it is all over.

The life cycle of program data looks like a function call tree.

If I always forget to call these methods when writing code (free/close/destroy), or find that the code I wrote before forgot to call them, or even called them wrong, then I don't want to use these methods any more.

Generic Vec is actually a vector of element T, not just an array of object pointers.

After compilation, it can only be used to store objects of type T.

It takes a lot of code to realize similar functions in C language, so I don't want to do it any more.

Trait is not just an interfaceRust, it is not such an object-oriented programming language, it has a trait, which looks like an interface in a computer-it can be used to realize dynamic binding.

If an object implements Drawable, it can be determined that the object has a draw () method.

But in any case, the power of traits does not stop there.

Dependency management needs to be implemented before it: call g-config manually or through automation tool macro.

Specify the header file and library file path.

Basically, people need to make sure that the correct version of the library file is installed.

In Rust, you only need to write a Cargo.toml file, and then indicate the version of the dependency library in the file.

These dependency libraries will be automatically downloaded or obtained from the designated places.

It is very difficult to test unit tests in C language for the following reasons: Internal functions are usually static.

In other words, they cannot be called by external files.

The test program needs to include the source files with the #include instruction, or use #ifdefs to delete these static functions during the test.

You need to write a Makefile to link the test program to some dependency libraries or some code.

You need to use the test framework, register test cases on it, and learn how to use them.

Rust's health macro avoids the possible problems of C language macros, such as something in the macro will cover up the identifier in the code.

Rust does not require all symbols in a macro to use parentheses, such as max (5+3,4).

There is no automatic conversion. In C language, Jade Bird of Liaoning Beida found that many bugs were caused by unintentionally converting int into short or char. This will not happen in Rust because the conversion needs to be displayed.

There will be no integer overflow, so this need not be explained.