"C language is dead"

Source: Internet
Author: User
"C language is dead"

Xu Shiwei
2007-1-7

Nowadays, many C/C ++ programmers are always arrogant and look down upon other developers.In fact, others may look down on him more!
> The biased one is always an individual, not a group. The author adds the following sentenceWithout a doubt, it is true that C/C ++ programmers are not biased, but they are themselves.

I was also fascinated by C/C ++ in the age of students.So I always think that I will not use C/C ++. Over the yearsI have been searching for the best mode to write c ++ code. But to be honestI have never seen any c ++ programmer who is a master, nor have I ever seenVery good C/C ++ code. C/C ++ code is always uglyBug!
> This paragraph is even more ridiculous. Have you ever seen good C/C ++ code? The C ++ standard library (STL) is so elegant. Moreover, there are so many classic open-source C/C ++ works and windo files that are unintentionally leaked.What is the core source code of ws NT? I am very sorry for the author.

I have been programming in C language for more than 20 years. I have written a C language compiler.C language debugger, other languages developed with C, games, client programs and serversProgram! I have never written any more. And my bookshelves are full of broken corners.K & R and Steele books. I know the C language too well, but I hate him.. Very annoying!

When I read a blog titled "Why should every programmer learn C language?", I really have goose bumps. If you are a professional programmerYou must think this is a big joke, although the author's intention may not be like this.. This refuted article is a bit interesting, but still does not grasp the essence.. So I expanded it. There are five reasons to explain why the C LanguageAnd C language programmers should not only use other languagesAnd should forget the annoying things they learned in C language.

  1. Memory Allocation

I can write a whole article about this. Maybe I can write a book.And may even write so much content that can be filled with library technical books.. Memory Allocation and storage unit allocation are indeed very troublesome.. You need to allocate too little memory, or allocate too much memory to waste.. The question here is: How to initialize it to zero? Or simply don't initialize it.. However, the initial step is to release the memory. All existing toolkit will help you confirmWhether you have released the previously allocated memory for each bit, and whether it is alwaysIf you do not use it, it will stop you and never release it twice. More seriously, Memory allocation and the release of the C language are both very slow and very slow.. When I use memory allocation, I don't even want to think about the special situations that need to be considered.As long as the problem (object) size is appropriate, I prefer to use the stack space or pre-allocatedStructure space. If I do this, I will have more troubles. Come backThe man who invented the garbage processor should have won the Nobel Prize.
> Memory management is the most classic topic in programming. GC is undoubtedly a great change in memory management, but I just think of it as a solution for memory management, rather than the only solution. More elegant solutions than GCSee no. I prefer to select an appropriate memory management solution under specific circumstances.Instead of having no choice, this is exactly the greatness of C/C ++. All GC languages (such as Java and C #) impose this solution on the process.This reduces the burden on programmers to a certain extent, but it also limits the programPersonnel's initiative. "Allocating memory and releasing memory are slow in C Language"? I do not know where the author draws the conclusion.

  2. Multithreading

I used to like C language, really. Until I start to develop and maintain multi-threaded servers with CServer. In terms of protecting data for conflicting threads, C language is not provided for programmersI am afraid of a little help. Every intuition you get when using a single thread, Experience, used in multithreading is wrong. At least Java indicates synchronization.Key and memory with proof files (but a strange file)But even so, unless you use the new javax. Concurrent, it will only crash in front of the huge parallel hosts. Return to C Language: Debug a deadlock in the data center for one week in a simulated production environment(This happened ). Java only needs Ctrl + break! Oh, my God !!!
> The C/C ++ language does not have much support for multithead.This situation is expected to change after C ++ 0x is released. But remember C/C ++ You will always prefer to use mature libraries to solve problems.

  3. pointer

Pointers are too difficult to control, so they are too sinister. I don't even have a way to describe them.. Every year, I spend several months debugging strange pointer problems every year.. I used to try to get all the secrets, for example, components that are hard to understand., Consortium and offset, and reuse the last two tags, and all other tricks. But I find that this is not worthwhile at all. Static references in other languages can be solved.
> Pointer is a reflection of the flexibility of C/C ++. Code with pointers can be ugly.But it can be elegant. -- There is no difference in the language used for this. I believeYou can write elegant Java code, and write the same elegant C/C ++ code.. Otherwise, it is not necessary (because some C ++ paradigms are not supported by Java). There are too many choices in C/C ++, which is indeed confusing.But not necessarily a disadvantage. My advice to C/C ++ programmers is:, Learn more about and use the C ++ standard library, rather than getting too entangled in pointer-related details.

  4. Premature Optimization

Speaking of tricks, have you ever wasted brain cells to study whether * P ++ is better than P?[I] fast? Have you ever spent time trying to make some changes to replace multiplication?Or try to make the inversion in the loop run faster? Still passing a parameterThe speed is the same as the speed at which the structure is opposed to being added and passed? Stop.! Algorithms are the key to speed. The programmer's level determines which algorithms he will use.. Knowing this will make your program better, faster, and less powerful.. Well, there are some examples that can be done in this way ...... No, you just need to stop doing that!
> Algorithm optimization is the key to program design. But normally, all languages (including c/C ++) programmers are studying the optimization of key paths. Study * P ++ Is it faster than P [I? I believe this is something that should be considered by the implementers of the standard library.. The difference is that C/C ++ programmers can also consider this as the authors of the standard library.Some details, while programmers in other languages are deprived of this right.

When it comes to optimization, there will be more topics. I used to insert data to the dictionary of C #.0.1 billion integers (read from more than 10 thousand text files ).The whole afternoon is still incomplete. I switched to C ++'s STD: MapIn 20 minutes. Try sorting 0.5 million custom struct data againI believe that, like you, You will deeply like the efficiency and elegance of C ++.

  5. Test

Which of the following is your favorite unit test tool for C? Well... I cannot think of one.? Unit Testing is definitely not important at all, right? Or it's too troublesome., It is difficult to keep up with the progress, a waste of time. You can use this time for more useful things.So that it only takes 1% of the working time, it is more appropriate. Or in the data center, Debug this image by optimizing the unlabeled image, which is only used by 100 concurrently online users.Problems.
> The author cannot even think of the C ++ testing tool. I can only guess that he is a comparison.Those who like to make their own wheels. Can't you think of cppunit corresponding to JUnit? When it comes to cppunit, I used it for unit testing.But in terms of implementation architecture, I Think It inherits the bloated Java code.. In winx, I provide a mini version of cppunit.The Code volume is about several hundred lines, and the function is no weaker than cppunit. (For more information about winx, see here ).

I should have said some more reasons, but five are enough now.Now it feels better. C used to be great... It was in 1984.. Today, I was pleasantly surprised by the new code written in C... If you want me to compareI think C ++ is just a little better than C. If you want to learn some older languagesTry forth, list, or APL. These old languages can at leastTeach you to think about your programs in different and elegant ways.
> New languages must be improved on the basis of absorbing old languages.. Looking at the vitality of a language doesn't mean looking at its shortcomings.. Things will develop and tend to improve. I believe that after C ++ 0x is released, C/C ++ The language will gain new vitality. Java, C #, and other new-generation languagesSo many c ++ brands prove that the impact of C/C ++ is huge.. It is a simple language.

(Source: Ed Burnette, author of 51cto.com, compiled by Li Anmin)

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.