Ask HN: Learning C and Using Libraries

7 points by girvo ↗ HN
So, I'm a web developer who has lately decided to get into "desktop" programming, and to suck it up and finally learn C.

I'm coming from the web world, Ruby, PHP, Python. Each of these languages has an excellent repository for libraries -- these repos let me search for what I'm looking for, check out the matches, and decide what I should use; either through a web interface or the command-line tool of choice.

C is fun to learn, but I'm basically just searching for "<functionality> C library" in Google, and hoping for the best. Surely there is a better way?

I'm developing on Linux and Mac (I use homebrew). I know that a lot of libraries can be pulled in through apt or similar, but they don't seem to have the same breadth or focus that the other languages have.

What am I missing? Or is it merely a case of myself having the wrong mindset perhaps?

6 comments

[ 2.8 ms ] story [ 26.2 ms ] thread
I'm learning ye ol' C as well. I usually concentrate on pure C, and try not to rely too much on libs. But your post got me thinking.

"I'm developing on Linux and Mac (I use homebrew)." I don't know about Mac, but at least you're on Linux, I found C on Windows to be more annoying.

IMO, the ideology behind C expects you to do more of the code by yourself, especially regarding the infrastructure. As an example, a few months ago I typed up a program to compute the square root of two without using <math.h>.

I'm at the point where I rely less on books or stinkoverflow and read other people's code. It might be an idea to look at what libraries other coders use. Right now I'm snooping around github.

> Right now I'm snooping around github.

I just spent an hour doing the same! I did see ccan on the front page here, that has some great snippets in it.

> IMO, the ideology behind C expects you to do more of the code by yourself, especially regarding the infrastructure.

See, I agree with you here, that's why I asked whether my mindset was wrong perhaps. The thing is though, I come from other languages where reinventing the wheel is seen as a really dumb idea, but perhaps in C it is the right way to go? I'm honestly not sure!

Cheers for the reply, it made me feel less lost ;)

Your welcome, I'm learning Python as well, love the bignum.

"The thing is though, I come from other languages where reinventing the wheel is seen as a really dumb idea, but perhaps in C it is the right way to go? I'm honestly not sure!" They often say that about assembly, and I think I may have to pull my foot out one day and learn it.

The C programming mindset requires one to think like a machine. Very few people are born with that skill, it has to be beaten into programmers with a keyboard.

BTW I only started learning coding last year, but I started with C++. Did you do the same or jump straight to C? I tend to agree more with Stallman and Torvalds these days: "A horrible language".

There are a lot of libraries out there and over the last dozen or so years, based on functionality, some have become much easier to work with than the same functionality was awhile back. Then again, some libraries like libcurl have generally been quite good and straightforward to use.

As someone mentioned, CCAN was on the front page, but generally there hasn't been the same sort of organized directory to find the C library best for a particular problem.

For myself, I go off of what I've used before, what others maybe have recommended, or sometimes just search for something that does most of what I want. If I need to write it, so be it.

I came across one called "Simple Directmedia Layer" or SDL, I found an example using it to create some simple graphics in a teach linux magazine. You can download it via apt-get (this is Ubuntu, it might be a different command on another distro). There is a libsdl1.2-dev and a libsdl2.0-dev. Hope that gives you a pointer (pun not intended).
Yes, Google is your friend, basically. That said, there are various libraries that implement a lot of generic, useful functionality. E.g. glib for data structures in a desktop application, libevent/libev/libuv for event-based programming, libpcre for regular expressions, various string libraries, SAMBA's libtalloc for a different take on memory management, etc.

What are you trying to do?