When Should I Use C?
Learn about how we can leverage the features of C language to our advantage.
We'll cover the following
As we learned in the previous lesson, C has an edge over many languages in that it’s fast, has 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
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. Take advantage of C when the situation calls for it. Use other languages when ease of use and maintainability are the goal or when the ecosystem developed around those languages provides features essential for your task.
In a lab we are affiliated with, we use Python, R, and (sometimes) MATLAB, but when we feel 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 sufficient. In particular, these other languages make it easy to quickly generate good-looking graphics.
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 data 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 spending some time implementing it in C is often worth it. 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.
Continue your learning journey with a 14-day free trial.
By signing up, you agree to Educative's Terms of Service and Privacy Policy