Post

Words to C Beginners

As a senior student, I’m very happy to gather with you at Tongji University’s Software College. The C language is our Software College’s first professional foundational course. Someone who has just been introduced to programming will inevitably have all kinds of questions. Lately, many freshmen have asked me how to learn C well. Here, I’ll share some of my personal thoughts based on my own learning experiences. I hope you can draw inspiration from them — that is my greatest wish! I also welcome everyone to communicate and exchange ideas with me.

One: Don’t Build a High Platform on Shifting Sand

For any subject, the foundation is very important. If the foundation isn’t solid, nothing else is possible. For C specifically — since it’s a language, just like Chinese or English — it has its own grammatical rules. If your Chinese or English grammar is off, people might still understand you, but a computer will only strictly follow your instructions. So although C grammar isn’t difficult, you must memorize it firmly and become proficient. +=*/ operators, for and while loops, if and switch selection, macros, malloc/free memory allocation and deallocation, pointer and array access — these are the most basic things. Only by mastering these can you communicate smoothly with a computer.

There’s no shortcut for this part. I recommend reading more books, spending more time on the computer, and practicing more. The first programming language I learned was VB. VB’s syntax is relatively simple compared to C, but I still remember the days when I couldn’t even write a loop but tried to write a game, and ended up running into all kinds of frustrations.

Two: Program = Algorithm + Data Structure

Speaking English requires knowing grammar, but knowing grammar doesn’t necessarily mean you can communicate fluently with foreigners. Learning C is the same. Besides mastering the most basic grammar, you also need to learn to use the computer’s “way of thinking” to solve problems. Two crucial aspects are algorithms and data structures.

An algorithm is our method for solving a problem. From swapping the values of two variables to designing a search engine like Google — all require algorithms. As a beginner, you should first learn some well-established, commonly-used algorithms. For example: sorting arrays, searching arrays, splitting strings — these are things you’ll encounter frequently. Just as there are multiple ways to solve a problem, algorithms can be good or bad. Try analyzing how many methods can achieve a goal, which is better, and why.

A data structure is the form in which our data is organized inside the computer. Only by putting our data into the computer in an appropriate way can we process it further. Data structures aren’t mysterious. The simplest data structure is an array, which stores our data sequentially. A slightly more complex one is a linked list, which “strings” our data together.

Algorithms and data structures are worth every beginner’s effort because of their universality. Later, when you learn C++, Java, or C#, the language syntax changes, but algorithms and data structures remain the same across languages. They also lay a good foundation for future courses on data structures.

Three: Diligence Compensates for Weakness

I often hear classmates ask me, “My foundation is poor, I’ve never programmed before, I’ve never even used a computer. The gap between me and some classmates is huge.” Then they ask me how they can catch up.

First, I think this is a matter of mindset. Some people may have gotten a head start and are ahead of us. But we can’t feel that we’re behind and can never catch up. “A scholar who has been away for three days must be looked at with new eyes” — this saying is absolutely true. As long as we’re willing to put in the effort, we can catch up. So please, first adjust your mindset. Take me as an example. I was introduced to computers very late — I didn’t touch a computer until after high school graduation. My university’s computer literacy course was what truly dispelled my computer illiteracy. I first encountered C in my second semester of sophomore year. But I believe that as long as I work hard, I won’t fall behind anyone.

Second, programs are written, so we need to write a lot of code — that is, practice on the computer a lot. At first, you can copy others’ programs, but gradually you should become independent and describe your own ideas in C. This is a very joyful thing. I suggest beginners don’t look at advanced programming yet. First, write code diligently, read lots of code, cultivate your style, get familiar with syntax — the most critical thing is to grasp the way of thinking. When you can write code freely, only then can you say you’ve learned C. You must develop the ability to independently write a complete program. This gives you a sense of accomplishment. Continuously cultivate this sense of accomplishment, progress step by step, and improvement will come naturally.

Also, programming is a very rigorous matter — you must concentrate and not be distracted. I often see some freshmen in the computer lab with VC++ open on one side while chatting on QQ, MSN, or watching movies on the other. How can you calm down and write good programs like that?

Four: A Gentleman is Not Different by Nature, but Skilled at Using Tools

As someone learning a new language, being skilled at using certain tools can improve your programming efficiency and achieve twice the result with half the effort. Please pay attention to two things: MSDN and the debugging features of the VC++ integrated environment.

MSDN is our function reference encyclopedia when writing programs. When you can’t remember a function’s parameters, you can quickly find the answer through MSDN.

VC++’s debugging features can help us better understand how code actually runs. Learning to use the debugger can sometimes quickly identify why our program isn’t running correctly. It saves time and helps us understand the logic of program execution.

Of course, using tools shouldn’t lead to over-reliance. It’s like learning martial arts — mastering 18 kinds of weapons doesn’t mean you can skip the basic stance training.

Five: Accumulated Water Makes a Deep Pool, Where Dragons Are Born

Learning is a long-term process. You need to continuously accumulate and summarize experiences. What we fear most in learning is a lack of persistence. You all understand this better than I do. Once you’ve mastered it, other languages can be understood by analogy. For example: C++, C#, Java, VB, Delphi — learning these will be much easier than for those whose C foundation isn’t solid.

Six: Without Rules, Nothing Can Be Done

When learning C, the two things most easily overlooked are documentation and coding standards. Yet these two things are crucial in software engineering.

Simply put, documentation is text that describes our program. I used to hate writing documentation too. In my mind, so-called documentation was just a bunch of nonsense. For small programs, you can dive right in and write code. But later, when my programs grew larger, without documentation I felt out of my depth. Documentation should actually be created before the program — “food and fodder should go ahead of troops and horses.”

Coding standards mean that our source code should follow certain formatting conventions, such as line breaks, indentation, code alignment, and reasonable comments. This is to improve code readability. Otherwise, after some time, when you look back at your own program, you won’t understand what it means anymore.

Seven: Dismembering an Ox Like a Master Butcher

Now we should also touch on some advanced C topics. For those interested in C with a research-oriented and questioning spirit, after learning assembly, you can go back and study C again from a new perspective. Here, I’ll leave a few questions to spark your interest:

  • How is C translated into assembly, or even machine code? Could I try translating a piece myself?
  • How is function recursion implemented?
  • What happens when I call fopen() or malloc()? How does C interact with the operating system?

If you truly understand these questions and then revisit C, I think you’ll reach the level of seeing the code as a whole without being hindered by individual details.

This post is licensed under CC BY 4.0 by the author.