开发者

Software design practice in C [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.

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:

Original close reason(s) were not resolved

开发者_JAVA百科 Improve this question

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.


  1. C FAQ
  2. K & R
  3. 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.

Software design practice in C [closed]


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜