Virtues and Challenges
Become aware of the benefits and limitations of coding in C.
We'll cover the following...
Pros and cons of programming in C
Every language has some strong points, but no language is perfect. Let’s see why this is true for C.
Virtues of C language
-
Fast: C is fast. It is a compiled language, close to the machine hardware, and doesn’t require any intermediary to interpret each line of code.
-
Portable: Because of its popularity, a compiler exists for just about any hardware platform. This makes it possible to port your code to any platform.
-
Small memory footprint: Its compiled nature, minimal runtime environment, and lack of extensive object-oriented features generally give it a smaller memory footprint than languages like C++ and Python.
-
Low-level access: C programmers have direct access to memory and low-level system features as needed. This gives a lot of flexibility and fine-grained control to the programmer.
-
Strong ecosystem: It is one of the old languages. Because of this, it has matured over time. It has a vibrant community, with a strong ecosystem, lots of resources, and a combined experience available.
-
Availability of tools: Several tools have been developed to make programming easier. These include various development environments, and compilation, debugging, and optimization tools.
Challenges associated with C
-
Memory management: Memory has to be managed explicitly, and a C programmer needs to be mindful of how memory is used behind the scenes.
-
Minimal runtime checking: As C allows direct memory access and does not enforce runtime checking, it’s easy to get into trouble when programming in C.
-
Mastering the APIs: Although the language is small, many APIs and libraries must be mastered to become an effective C programmer.
-
The compile-test-debug cycle: Each piece of code has a compile-test (crash)-debug cycle. Even though the compiled code runs fast, there is a flip side to it as well, since each minor modification requires a time-consuming recompilation, unlike interpreted languages like Python.
-
Object-oriented programming: It does not support object-oriented programming.
-
Verbose code: The code is usually more verbose than in high-level languages like Python.
Now that we know C’s strengths and weaknesses, it’s time to examine some specific scenarios in which it’s preferred over the other languages.