Feed Sign in with OpenID OpenID

Simon Willison’s Weblog

I think that what’s particularly hard with C is not the details about pointers, automatic memory management, and so forth, but the fact that C is at the same time so low level and so flexible. So basically if you want to create a large project in C you have to build a number of intermediate layers (otherwise the code will be a complete mess full of bugs and 10 times bigger than required). This continue design exercise of creating additional layers is the hard part about C. You have to get very good at understanding when to write a function or not, when to create a layer of abstraction, and when it’s worth to generalize or when it is an overkill.

Salvatore Sanfilippo

5 comments

  1. So true! I understand some people struggle with pointers, etc. but the big difference for me between C and any "higher level languages" is normally the standard library.

    Give me C with a library as comprehensive, reliable and consistent as that in .NET (or even Python) and I'm done.

    David - 18th December 2009 17:54 - #

  2. Well, there are a bunch of C "standard libraries" including GLib, NSPR, Core Foundation and more. They tend to include (often portable) implementations of IO, networking, data structures, threading, etc - everything that you get from the base class libraries of most high level languages. Most large scale C projects are either built on a library like this or end up spawning one. We've come a long way since K&R.

    Ian McKellar - 18th December 2009 18:42 - #

  3. Don't forget the Apache Portable Runtime, either. :)

    Salvatore == antirez == redis creator, by the way.

    Jeremy Dunck - 18th December 2009 23:16 - #

  4. Unix is built on small C programs like ls, sort, grep, cat etc.

    The GNU versions of these utilities are admittedly bloated, though if you look at the plan9 unix port, they are genuinely small readable & reliable programs.

    Unix is considered a "large project" and able to solve a variety of problems.

    So no you do not have write a long C program to realise a "large project". In fact you should try keep C programs less that 2-3k SLOC.

    And layers of abstraction is the wrong way to solve a problem. Good C programs do one thing well and are able to work with other programs with stdin, stderr and stdout, which is really simple.

    Have a look at http://suckless.org/ for further well written C projects.

    Kai Hendry - 19th December 2009 22:11 - #

  5. This is exactly how I feel about PHP. Big sites with non-terrible php code bases have many layers of abstraction that together build a cohesive meta-language.

    Erik F. Kastner - 30th December 2009 05:23 - #

Sign in with OpenID

Auto-HTML: Line breaks are preserved; URLs will be converted in to links.

Manual XHTML: Enter your own, valid XHTML. Allowed tags are a, p, blockquote, ul, ol, li, dl, dt, dd, em, strong, dfn, code, q, samp, kbd, var, cite, abbr, acronym, sub, sup, br, pre

A django site