We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 5 years ago.
The community reviewed whether to reopen this question 3 months ago and left it closed:
开发者_JAVA百科 Improve this questionOriginal close reason(s) were not resolved
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.
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,
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.
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.
- C FAQ
- K & R
- Linux kernel source code
Writing solid code
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.
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.
You must read Expert C Programming by Peter van der Linden.
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
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
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.
精彩评论