Programming Style: Examples and Counterexamples

Brian W. Kernighan, P. J. Plauger

Research output: Contribution to journalArticlepeer-review

26 Scopus citations

Abstract

Computer programs can be written many different ways and still achieve the same effect Until recently, programmers have had little reason to favor one method of expressing code over another. We have come to learn, however, that functionally equivalent programs can have extremely important stylistic differences. Good programming style cuts across application areas, technique alad language. Programs written with good style are easier to read and understand, and often smaller and more efficient, than thOse written badly. Yet few programmers have ever been taught what style is, as we can see from even cursory inspection of their code. Even the techniques of structured programming do not ensure that code will be good; “structured” programs can be just as bad as their unstructured counterparts. This paper is a survey of some aspects of programming style, primarily expression and structure, showing by example what happens when principles of style I are violated, and what can be done to improve programs. To add the ring of truth to our discussion, the examples are all taken verbatim from programming textbooks.

Original languageEnglish (US)
Pages (from-to)303-319
Number of pages17
JournalACM Computing Surveys (CSUR)
Volume6
Issue number4
DOIs
StatePublished - Dec 1 1974
Externally publishedYes

All Science Journal Classification (ASJC) codes

  • Theoretical Computer Science
  • General Computer Science

Keywords

  • control-flow structures
  • programming style
  • structured programming

Fingerprint

Dive into the research topics of 'Programming Style: Examples and Counterexamples'. Together they form a unique fingerprint.

Cite this