Question

I'm interested in learning C. I have read K & R, and I have even done some simple C extension work in R and Python. What's a worthwhile project idea for doing something more substantial with C? Any good online resources, similar to Dive Into Python? In particular, resources focused on programmers that already know newer languages who are trying to learn C (that mention things like "Asking an array for its length is nonsense in C, you lazy Pythonista").

My background:

Math/stats, day to day programming in Python, R, mostly around natural-language-processing, algorithms, and the like.

Was it helpful?

OTHER TIPS

Several years back, a friend of mine asked me that same question: "How do I learn C?" I told him to write a device driver.

Imagine my surprise when he actually did it.

Somewhat off topic, but since you mention your background is in Math and Stats your should try your hand at Project Euler. There are over 200 math/stat related problems available to solve. In addition, once you arrive at a solution, you can view the problem forum to see how others solved the same solution. Very handy for seeing how others solve the problem... and fun to boot!

www.projecteuler.net

I have a similar background to you. I use Python to do a lot of math and data analysis for my PhD research, and also for web programming. The difference is that I learned C first, way back in the 90s.

If you can write C extensions for Python, then I'd say you have a pretty good handle on what C is good for. In my opinion, C today is best-suited for two things:

  • Writing low-level software that interacts with hardware.
  • Writing code that does repetitive, tedious, CPU-intensive stuff (math, XML parsing, etc.)... perhaps as an extension for a higher-level language.

Of course a lot of higher-level applications are also written in C, especially under Linux I've found, but in large part these aren't really written in the "bare-bones" C of K&R or the standard library. Rather, they use frameworks like Glib, or wxWindows, or the Apache Portable Runtime, or others, which all put use some kind of object-oriented structure or conventions, and often abstract away some of the basic memory-management details of C.

So I think that making your C skills useful in today's programming language environment is largely about doing low-level work, or becoming familiar with one of these higher-level frameworks. I personally like the Glib and GTK libraries a lot, since they use a very dynamic object-oriented model (a lot like Python) without preventing you from using the low-level features of C.

You could write an interpreter for a simple language. Use flex/bison. Make it multithreaded etc. This is fun and tends to exercise pointers a lot. I wrote something like that for a school project: A simple stack based language with two different garbage collectors, TwoSpace and a concurrent version. That was fun. And doable as a first ever c program bigger than "hello, world"!

check out learn C the hard way, it's a free ebook which takes you through many examples of C code and exercises in order for you to learn.

http://c.learncodethehardway.org/

Find or define a problem in your day-to-day work and force yourself to solve it using C instead of Python. That will force you to learn the language while keeping the problem relevent to what you normally do.

Implement a virtual machine (the JVM, for example).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top