For beginners of C Language

Source: Internet
Author: User
For beginners of C Language

Author: LDAP from Cu

A few days ago, I wrote a post entitled "notes worth attention in UNIX C Language", which talked about the issue of learning high-quality code from open-source software outside China, but some friends told me that, in the process of viewing the code, it is very difficult to think about it. If there are tens of thousands of lines of programs without instructions, it is difficult to find the starting point, therefore, I have written this article to help a majority of C language enthusiasts. In this article, I am sorry for a lot of news, because this article reminds me of my graduation, so I am a little touched. At the same time, there are also some personal prejudices in the article. People who want to hold negative opinions may bear with me. Since it is a prejudice, it is only a prejudice.

Do not worry about learning C language. You must step by step. Do not blindly write a large amount of code. This will only pile up a large number of low-grade code, and make you form bad code habits. I have a preliminary understanding of the C language. In fact, I still put the C programming language and C Programming (second edition) on hand) "(university teaching materials), sometimes I will refer to it for some basic concepts.

If you have a high level of developers around you, it would be better to ask more questions. However, as far as I know, most beginners did not receive guidance from a senior software engineer after entering the IT industry, but they were pushed to the front line after entering the company, in this process, many people are struggling to pile up code and make a poor salary. Although I am still holding poor money, I am lucky because I met a mentor who led me to the Unix and C fields in my first company, it was his saying that "UNIX and C language are the technologies you will learn all your life" that made me fall in love with them. It was his saying, "You have a root password, it is not as simple as you have the root password, but more of a responsibility. (The premise for this sentence is that I used the root password to enter the sun server and deleted other people's things, because I think these are useless things), I have a very specific understanding of the word "responsibility. Therefore, I would like to invite readers to express my deep gratitude to yuhj, my mentor of Neusoft. At the same time, I would like to express my deep gratitude to CU's friends. You are my second mentor and I can't do without you.

I hope everyone will be lucky. Don't be discouraged if you don't get any luck. Let's talk about it and discuss it, however, do not give an answer when discussing on the Forum. Many things are not clear in one sentence. Others can only give you one guide, what's more, we only rely on our own research, research, and pondering. In your spare time, go to the essence area and see what you will get.

Do not read English as soon as you see it. Even though I do not understand it (after all, I have received CET4 and 6 levels of dumb English education and can still understand it ). Man's help is the best teaching material and many foreign forums have a clear description of the technology. It is also very simple. More importantly, you will see something you cannot see on domestic forums (computer technology has always been transferred from the west to the east, hoping that foreigners will come to our Chinese forum one day to find technical materials ).

One thing to learn about C language is also necessary, and it is best to learn it at the same time. Some friends may have guessed it. That's right, it's UNIX. UNIX and C language can be said to everyone to mention a lot. If there is UNIX, there will be C language, and at the same time, there will be C language, unix (let's talk about the philosophy of chicken, eggs, and eggs first, who beat me with tomatoes). Some people even say that the C language is designed for Unix, the unusual relationship between UNIX and C language can be seen. It is much easier to learn about UNIX now. In the past, Unix was run on large servers, but now Linux (according to GNU, Linux is not UNIX yet ), you can install a set of Linux on your PC to learn. Do not compare Linux with windows when learning Linux. Linux will let you know what a classic is, always let you expand in one direction, Windows will only let you play a big knife in other people's sets, from time to time also want to change a set of tricks. The following lists some of my UNIX experience:

1. I want to learn about UNIX and C. I would like to recommend a book "UNIX advanced environment programming", which is a classic study of UNIX and C, try to write a practice program for all the system calls mentioned in the book. First of all, let's give a perceptual understanding of what the Linux system provides to users and how to use it. System calling is a function provided by the kernel to apply for Kernel services. For Linux kernel learning, it is a good way to start with system calling. For more information about the learning process, see the Linux Online Help and network materials. When you think it is almost the same, let me give you a contact question: to implement an FTP server and client function, you can define some application layer protocols by yourself, you only need to use simple commands to transfer files.

This topic allows you to practice the basic programming methods of TCP/IP and the basic methods of file operations, which will be helpful for learning the Kernel File System later.

2. When you have some knowledge of UNIX systems and most system calls (the key is about file system calls, it is easier to start with a file system for the Linux kernel.) After a clear understanding of the Linux kernel, we recommend that you use a book "Linux kernel Scenario Analysis". the book is about the Linux kernel. The only drawback is that there is no detailed introduction to the network subsystem. You can start with calling the file system, and you will have a deeper understanding of Linux. Pay attention to the use of many classic methods and ideas in Linux. You will realize why UNIX regards everything as a file and operations on everything as a file. You will gradually understand the classic concept of UNIX.

3. When you have some knowledge of the Linux kernel, you can find a direction for special development. If you want to be interested in the popular network programming, we recommend that you use a book "detailed explanation of TCP/IP", which is a classic topic about TCP/IP protocol. You will learn how the TCP/IP protocol stack works. After reading this book, you can write a DoS attack program and sniffer by yourself.

I am simple. In fact, every book I mentioned is at least enough for you to study for a long time. So I hope that beginners will not be impatient. I believe that as long as they work hard, they will surely become masters.

When writing code, you should be aware of developing good code habits and styles as well as abstract capabilities.

The following provides a 20-word policy for writing code:

Small Functions
Try to get the common points of the function, with fewer lines of code. A function can only complete one simple function. At a glance, we can see whether the function has any code errors. Every function is robust, then your program is robust.

When the Code does not need to complete a function, the fewer the code, the better the logic is. Do not write more code than the code.

The algorithm should take efficiency into account when completing a function. At present, the computer memory is very large, so the memory is no longer the primary consideration, however, in some special cases, efficiency is very important. High-efficiency algorithms do not need low-efficiency algorithms. In this version, there is an excellent post about removing spaces on both sides of a character seek (TRIM). Many people have proposed algorithms, however, an algorithm is the best, the most efficient, and the least code.

The name should be clear, and the so-called object structure in Chinese should be used, such as set_buffsize ()

The file should try to divide a large program security function into multiple files as much as possible, and the file should not exceed 1000 lines as far as possible, so that you can clearly know that the file code is robust, the file may have potential risks. You can check several files in a targeted manner during code check.

Related Article

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.