When Should I Use C?

Learn about how we can leverage the features of C language to our advantage.

As we learned in the previous lesson, C has an edge over many of the other languages in that it’s fast, has a fine-grained access to the system, and has a small memory footprint. This makes C a language of choice for scientific applications, system programming, and IoT devices.

Let’s look at these in more detail.

C for scientific programming

You should think of C as one of many tools in your toolkit for performing computational tasks in your scientific work: Taking advantage of C when the situation calls for it. Using other languages when ease of use and maintainability is the goal, or when the ecosystem developed around those languages provides features essential for your task.

In a lab I am affiliated with, we use Python, R, (sometimes Matlab), but when we feel the need—the need for speed—we use C.

Processing large data

C may not be the best choice for interactive data exploration, like when we want to load in some data, plot it in different ways, do some rudimentary calculations, plot the results, etc. For this sort of interactive exploratory scripting, a language like Python, Matlab, R, etc., may be entirely sufficient. In particular, these other languages make it very easy to generate great-looking graphics quickly.

However, for cases, where we need to process a large amount of data, you’ll find that these languages are slow. Even for fairly common statistical procedures, like bootstrapping (techniques that involve resampling thousands or tens of thousands of times), interpreted languages will be orders of magnitude slower than C.

In such situations, C starts looking very attractive. If you have a data processing operation or a simulation, and you know it will take a long time to run, then it is often worth it to spend some time implementing it in C. The graph below compares the speed of interpreters for several languages. As you can see, C shines in this regard.

Create a free account to access the full course.

By signing up, you agree to Educative's Terms of Service and Privacy Policy