Books / Introduction to C Programming Language / Chapter 1
There are two purposes to this course: to teach you to program in the C programming language, and to teach you how to choose, implement, and use data structures and standard programming techniques.
Why should you learn to program in C?
- It is the de facto substandard of programming languages.
- C runs on everything.
- C lets you write programs that use very few resources.
- C gives you near-total control over the system, down to the level of pushing around individual bits with your bare hands.
- C imposes very few constraints on programming style: unlike higher-level languages, C doesn’t have much of an ideology. There are very few programs you can’t write in C.
- Many of the programming languages people actually use (Visual Basic, perl, python, ruby, PHP, etc.) are executed by interpreters written in C (or C++, an extension to C).
- You will learn discipline.
- C makes it easy to shoot yourself in the foot.
- You can learn to avoid this by being careful about where you point it.
- Pain is a powerful teacher of caution.
On the other hand, there are many reasons why you might not want to use C later in life. It’s missing a lot of features of modern program languages, including:
- A garbage collector.
- Minimal programmer-protection features like array bounds-checking or a strong type system.
- Non-trivial built-in data structures.
- Language support for exceptions, namespaces, object-oriented programming, etc.
For most problems where minimizing programmer time and maximizing robustness are more important than minimizing runtime, other languages are a better choice. But for this course, we’ll be using C.
Why should you learn about data structures and programming techniques?
For small programs, you don’t need much in the way of data structures. But as soon as you are representing reasonably complicated data, you need some place to store it. Thinking about how you want to store and organize this data can be a good framework for organizing the rest of your program.
Many programming environments will give you a rich collection of built-in data structures as part of their standard library. C does not: unless you use third-party libraries, any data structure you want in C you will have to build yourself. For most data structures this will require an understanding of pointers and storage allocation, mechanisms often hidden in other languages. Understanding these concepts will give you a deeper understanding of how computers actually work, and will both let you function in minimalist environments where you don’t have a lot of support and let you understand what more convenient environments are doing under their abstraction barriers.
The same applies to the various programming techniques we will discuss in this course. While some of the issues that come up are specific to C and similar low-level languages (particular issues involving disciplined management of storage), some techniques will apply no matter what kinds of programs you are writing and all will help in understanding what your computer systems are doing even if some of the details are hidden.
Attention - Java Developers
If you are are coming from a Java background, please read the CodeAhoy free book A C Primer for Java Programmer