views:

562

answers:

11

For OOP languages, there are many books describing how to design software, and design patterns are mainly for OOP languages.

I am wondering whether there are any books/good articles teaching how to use C in a big project, like it is a good practice to use static functions when this function is only used in a single file.

+4  A: 

You must read Expert C Programming by Peter van der Linden.

alt text

Prasoon Saurav
Just be aware that the deeper aspects of this excellent book are heavily focused on Solaris/SPARC environments.
Rob Wells
Forgot to say +1 for the suggestion! (-:
Rob Wells
Although the book is great, I won't consider "Deep C Secrets" as useful for "how to use C in a big project".
Amit Kumar
@Amit I just scanned the content of the book. It does not say more about "how to use C in a big project". It mentions inheritance and polymorphism in C++, but does not say how C overcomes these.
Yin Zhu
Great book, but I can't see the relevance for using C on large projects. Much better on "understanding the dark corners of C".
Norman Ramsey
+3  A: 

The same principles for OOP apply to C, with the exception you don't have classes. However, an idea which is applicable to C, of which OOP is an implementation, is the concept of Abstract Data Structures - ADT.

The book "Data Structures and Algorithms" is a classic and should be read.

http://www.amazon.ca/Data-Structures-Algorithms-Alfred-Aho/dp/0201000237

In general, the same principles that apply to OOP, can be applied to ADT. Read design books for principles, not details.

Larry Watanabe
I am actually quite good at implementing data structures in C. But this does not give me a big picture in using C in big projects.
Yin Zhu
Ah, but the idea is to simply use ADT instead of Classes, and then apply the whole literature of OOP design to ADT. So, you use C in big projects the same way you use C++ - layer design, encapsulation, abstraction, hierarchical decomposition, TDD
Larry Watanabe
+5  A: 

If you want a more C specific book then you could look at The Practice of Programming by Kernighan and Pike.

NB: I've always thought of OOP as a way of looking at design; the fact that some languages provide explicit support for it is nice but not esssential.

Jackson
It's not a C specific book - it's about programming generally. It uses C, C++, Java, Perl, awk and probably more, in the examples.
anon
+1  A: 

Here is a PDF on object oriented C. This article is fairly old, but worth a read.

http://www.planetpdf.com/codecuts/pdfs/ooc.pdf

Bryan C.
+5  A: 

Writing solid code

Andy
Good call Andy. +1. Lots of great info in that book. His other book "Debugging the Development Process" is also a worthy companion! (-:
Rob Wells
+5  A: 

G'day,

While heavily focused on C++, John Lakos's excellent book "Large-Scale C++ Software Design" has a lot of information that is very relevant to the design of software written in C.

Edit: Oooh. After seeing @Jackson's suggestion for the excellent "The Practice of Programming" I'd also highly recommend Eric Raymond's excellent book "The Art of UNIX Programming.". Thanks for the reminder @Jackson.

HTH

cheers,

Rob Wells
Agreed, +1 for Lakos
Matthew Murdoch
Although everyone seems to love Lakos's book, I feel it is out of date and too verbose. Is there any advice for me?
Amit Kumar
@Amit, a lot of the recommendations don't date, e.g. directory layout for a project, efficient #includes, etc.
Rob Wells
+4  A: 
  1. C FAQ
  2. K & R
  3. Linux kernel source code
grokus
None of these have anything much to say about large scale projects. The last of course IS a large scale project, but that's a different thing.
anon
Rob Wells
+1 for Linux kernel source code. Probably the best resource for C.
Amit Kumar
The design principles of the Linux kernel hint at how to build big C projects; if you read a bunch of the kernel, plus, say, BIND and Apache, you'll have a pretty good idea how to go at it. Just don't go thinking the internals of gcc are a good guide to anything.
Andrew McGregor
+5  A: 

I know sometimes it can't be avoided, and that is probably your situation, but you shouldn't be using C for large projects if you can at all help it.

I know this is the kind of statement that leads to knee-jerk responses from fans, but for everybody else, including the language's own authors, it is an obvious fact. For instance, here's an excerpt from the history the the DoD's search for a language to support way back in the late 70's (the High Order Language Working Group):

Other languages were considered for formal evaluation, but were not included because preliminary examination led one to believe that they would not meet the requirements so were not viable candidates for the purposes of the DoD. One such language was C. At that time DARPA was working with Western Electric/Bell Labs on UNIX, contractually supporting some DARPA contractors and other government facilities using UNIX. It was the evaluation policy to have the owners provide assessments of their own languages, in addition to the contracted evaluations, so HOLWG took advantage of this connection between DARPA and Bell Labs to request their cooperation. When Bell Labs were invited to evaluate C against the DoD requirements, they said that there was no chance of C meeting the requirements of readability, safety, etc., for which we were striving, and that it should not even be on the list of evaluated languages. We recognized the truth in their observation and honored their request.

T.E.D.
+1  A: 

Dave Hanson's book C Interfaces and Implementations is a wonderful example of how to do large-scale programming in C: by dividing your system into interfaces and implementations. At one go, the book provides good examples and also useful building blocks. For people who have been around, this is very much a rebadging of object-oriented design as practiced by Barbara Liskov (who recently won the Turing Award for it). Think of it as OO programming but without inheritance.

A terrific book for anybody who has to write C.

Norman Ramsey
I've read this book these two days. Great book!
Yin Zhu
+1  A: 

The Cheshire Cat idiom is a useful way of reducing coupling in C and is very helpful when designing large projects.

http://en.wikipedia.org/wiki/Cheshire_Cat_Idiom_(programming_technique)#C

Simon Elliott
+1  A: 

Code Complete 1st Ed by Steve McConell is more oriented towards C, that may be worth a look as well. At any rate his books are great reading for any professional programmer.

Anders K.