tags:

views:

284

answers:

4

Object-Oriented programmers seem to have all the fun. Not only are they treated to major framework revisions every two years, and new and Improved languages every five, they also get to deal with design practices tailor-made to their programming style. From test-driven development to design patterns, Object-Oriented programmers have a lot to keep up with.

By contrast, the C programming world seems far more sedate. The last major revision to the language was in 1999, and the next one is likely to be far less impressive. K&R 2nd edition is still held up as a good introductory text by many, despite being twenty years old now.

If we, as C programmers, have developed and improved our skills and practices (and I think we probably have), we don't seem to be very good at communicating them. We don't sell books about them, post about them on blogs, or organise workshops around them. Not in the way the rest of the software development world seems to.

So, let's share.

What are your preferred 'modern' C programming practices?

Do you use `template' libraries of long, involved preprocessor macros to squeeze the last inch of performence out of hardware in the same way C++ programmers can? Do you use a allocation library like halloc to minimize the time you spend on managing memory, or do you use a full-blown automatic garbage collector?

Of course, if you've been using these things since 1987, feel free to chime in as well; the point of this question is to share practices that are out of the ordinary but might benefit others.

What are your preferred 'modern' C software design practices?

Design considerations are at least as important, of course. Do you adapt design practices from the Object-Oriented world? Do you use UML? Or you opt to iron out specifications in a language-neutral style (flowcharts, Z, weakest precondition calculus, anything)?

+6  A: 

I try to use ready-made libraries for basic functionality when possible. I find glib (part of the GTK+ GUI framework) absolutely brilliant when it comes to general data structures and such. No more writing your own hash table, linked list, dynamic array or whatever.

I also think the object-oriented ideas in the GTK+ toolkit are great, and often structure my code the same. There's nothing stopping you from adopting paradigms in C, it's flexible enough to express many things that are just made "first-class" in other languages, even if doing so often involves a certain ... verbosity, of course.

unwind
Voted down, huh? Seems a bit harsh ... The OP lists example libraries, so I felt it was proper to continue that. Oh well. I'll leave this around for a while at least.
unwind
I can only add that posts like this one were amongst the kinds of answers I had in mind when composing the question.
Michiel Buddingh'
+1  A: 

1999: Use C, it is fast, low-level, efficient

2009: Use Python, it is fast-enough, productive, multi-platform, popular and fun

flybywire
I hate to sound like a bore, but to other posters who feel the same way, only about C++/C#/ruby/Erlang/whatever, could you just edit/upvote this answer?
Michiel Buddingh'
"Fast enough" never is :)
MadKeithV
+4  A: 

Not really a C programming practice, because I'm one of those newfangled object-oriented programmers working in C++, but this:

Object Oriented Programming is not a silver bullet

I wish my company had more pure C programmers to teach the juniors that there is life beyond Object Orientation.

MadKeithV
+5  A: 

To be honest, my answer would be that I finally gave in to C++ after fighting it for a long time. I've come to really enjoy its advantages.

I like being able to let the compiler take care of the OO plumbing, being able to use exceptions and RAII instead of littering return codes and resource releases all over, not reimplementing a linked list or an automatically expanding vector or a smarter string library for the umpteenth time, operator overloading instead of vector_add() everywhere, etc. Granted, there are libraries for much of this in C, but it seems like such things are rather fragmented between competing solutions. It's nice having such amenities standardized in C++.

The nice thing is that I'm still free to drop down and do all the stuff I might have done in C if I feel like that's what suits the program best. There's no OO straight-jacket like in Java.

Boojum