I finally took the compulsory software engineering course notorious for its very difficult course project – writing a bitcoin client in C. Alhamdulilah, we successfully completed the project: about 18k lines of code, automated builds/documentation/tests and lots of other stuff. I figure we rank around 7 or 8 on the Joel 12-point scale even though some don’t apply to our project. :D Big UPs to the team!
I decided to do a review of all the languages I have used or been forced to use while taking the course; the story behind learning these languages, their strengths and weaknesses; quirks, advice for beginners and some wisecracks too :).
C is first on the list. Here goes!
How I learnt C
I somewhat got forced to relearn this language this year but my first attempt at C was self-study in 2007 or 2008 as an undergrad. Despite my dreams of building the most AWESOME program ever, my C adventure ended abruptly after I read about 3 to 5 chapters of a C book. I was discouraged by apocryphal reports which insinuated that C was no longer relevant; so I left C for C++ and then Java. That story is here.
Well, this year I had no choice but to learn it. Well, there was another choice: getting a poor grade in the software engineering course.
- C packs a powerful punch, who doesn’t like power and speed?
- It has a concise grammar and you can learn the language fast.
- Purity: its simplicity forces you to think.
- I think function pointers are kind of cool too.
- Forces you to learn how low-level computer stuff like stacks, heaps and memory allocation work.
- It doesn’t support as much abstraction as I want.
- Bah… why do I have to call free() all the time? Can’t the language help me with this? I already know and agree am spoilt but why make programming harder?
- No hashtables? No string support? Beats me… every language seems to have these.
- There is some redundancy in the methods available in the C library; e.g. strtol and atol; seems PHP got a predecessor in C.
- Pointer tangles; what does this point to or mean? ***a.
- Uninitialized values can hold all sorts of values; woe betide you if you make the mistake of using them straightaway; C won’t raise any errors.
Writing code in C
It’s one of two things: you’ll either learn code purity and write pretty nifty code or massacre lots of innocent computer bits à la segmentation faults, memory overwriting and stack overflows…
I think everyone starts out in the latter group and moves to the former :).
Recommended For Beginners?
7[a] == a if a is an array; it was even on my exam! :P
while(*s++ = *t++) copy a string t to a string s.
Pretty powerful, compact and small although lacks a lot of expected features and development is sometimes painful. There are a couple of libraries that you can use though.
I hear C++ is more challenging… Do the ++ signs signify difficulty? :)