Hacker News new | ask | show | jobs
by akarambir 3424 days ago
One thing I always not see people recommending is what small open source projects I can study or do while or after reading these books. Like for web development, people try to implement a small todo, blogging software. For someone coming from higher level languages like Python, Ruby, studying low level library is very tough to grasp. Having small but a proper project in itself will be helpful. I have heard praises about Redis and SQLite, but for beginners, they are quite big.

So any suggestions?

4 comments

A personal preference of mine is to write a simple http server with GET and a few error codes implemented. It usually covers networking, file IO, exceptions in some cases, multi-threading, string parsing, etc. If it feels like too much then you can always start off with a smaller subset of features.
Threads? That is not for beginners.However, your idea is great last summer I was told to code such in an interview that with a hook to Lisp. I learnt so much even though I failed the interview.
Presently coming from Python to C, I'm trying to figure this out myself. One issue that occurs to me is that someone coming from a higher level language like Python or Ruby might have to re-calibrate what they consider 'small'. Since C itself is a smaller, lower level language, functionality that might be small and simple in say, Python, is probably going to be bigger and more complex in C. There are no lists, tuples, dictionaries, strings or sort functions from a batteries-included standard library in native C. If you want such, well, here's your ints chars and pointers, have fun implementing them yourself. (That's not intended as a slam against C)

As for suggestions, all of the following are guesses because of my own n00b status with C. That said:

The runtime of the higher-level language of your choice. If you already know Python well, looking under the hood and seeing the C code that actually implements all the convenient and useful bits may well be instructive.

Rsync. I was able to get some small understanding of how it worked by browsing the source even though I knew hardly any C at the time.

Postfix. I don't think is a small project, but I have heard it spoken well of from a security standpoint -- in part because it is actually several small programs/modules that specialize in one task. Those individual binaries/modules might be comprehensible on their own.

The Python/C API is pretty straightforward and can be a good intro since you'll see how some of the Python types are represented with the curtains pulled back. Try porting a small module of your own from Python to C. Then refactor it so it can be used in a stand-alone C program with just a few wrappers for the Python API. Then try plugging it into a C program instead.
Not quite a direct answer, but book(s) missing from op is:

http://aosabook.org/en/index.html

("Architecture of open source applications") and siblings.

I'd say reading the section on "git" there, and then having a look at the git source - or "nginx" and looking at the source - etc - might be one place to start.

Other than that, off the top of my head (suggestions from a hobbist): sqlite, the samba lightning db lmdb, the new openbsd daemons like httpd, opensmtpd, and the NaCl crypto library.

Hopefully more battle-hardened c-programmers can comment/add to the list.

[ed: and seeing rsync mentioned below, I recalled spiped along with a handful of other utilities by Colin Percival (former FreeBSD Security Officer, founder of tarsnap and active hn-er) http://www.tarsnap.com/spiped.html ]

If you're going to try to learn C by looking at any of my code, I highly recommend that you pick spiped for that purpose. Tarsnap is built around libarchive, which is good code but much bigger and less coherently organized; scrypt and kivaloo sacrifice clarity for performance in many places.

But spiped is just 6500 lines of code, of which 4300 is segregated library code; a novice C programmer should be able to start by treating those as black boxes and read through the rest of the code to get a clear sense of how the entire program works -- something which is almost impossible for a program as large as even OpenBSD's minimalist httpd.

And reading spiped will expose you to a lot of the concepts which experienced C developers take for granted -- non-blocking network I/O and callbacks, threads, "extending" the language by creating more sophisticated data structures, workarounds for non-POSIX platforms, etc.