When Should I Use C?

This lesson will show how can we use the optimizations that C offers compared to other languages to our advantage.

C for scientific programming

My take on scientific programming is that I think of C as one of many tools in my toolkit for performing computational tasks in my scientific work. I wouldn’t necessarily suggest only programming in C. On the other hand, I would recommend taking advantage of C when the situation calls for it. In our lab, we use Python, R, (sometimes Matlab but increasingly less often), and when we feel the need, the need for speed, we use C.

Interactive data exploration

For interactive data exploration, like when you want to load in some data, plot it in different ways, do some rudimentary calculations, plot the results, etc., then C may not be the best choice. 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.

Processing large data

For cases where you need to process a large amount of data, you will 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.

This is the situation when C starts to become 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