Skip to main content

Diigo Home

Rob Pike: Notes on Programming in C - The Diigo Meta page

www.lysator.liu.se/...pikestyle.html - Cached - Annotated View

York Jong's personal annotations on this page

yorkjong
Yorkjong bookmarked on 2008-05-11 C programming concept

What follows is a set of short essays that collectively encourage a philosophy of clarity in programming rather than giving hard rules.

  • Length is not a virtue in a name;
    clarity of expression is.
  • When the variable names are
    huge, it's harder to see what's going on.
  • As in all other aspects of readable programming,
    consistency is important in naming.
  • I prefer minimum­length but
    maximum­information names, and then let the context fill in the
    rest.  Globals, for instance, typically have little context
    when they are used, so their names need to be relatively
    evocative.  Thus I say maxphysaddr (not
    MaximumPhysicalAddress
    ) for a global variable, but np
    not NodePointer for a pointer locally defined and used
  • Stepping
    through structures using pointers can be much easier to read
    than with expressions: less ink is needed and less effort is
    expended by the compiler and computer.
  • if you find code containing many similar,
    complex expressions that evaluate to elements of a data
    structure, judicious use of pointers can clear things up.
  • Procedure names should reflect what they do; function
    names should reflect what they return.
  • If your code needs a comment to be
    understood, it would be better to rewrite it so it's easier
    to understand.
  • Most programs are too complicated - that is, more
    complex than they need to be to solve their problems
    efficiently.  Why? Mostly it's because of bad design
  • Fancy algorithms are slow when n is small, and
    n is usually small.
  • Use simple algorithms
    as well as simple data structures.
  • Data dominates.  If you've chosen the right
    data structures and organized things well, the algorithms
    will almost always be self­evident.  Data structures, not
    algorithms, are central to programming.
  • Perhaps the most intriguing aspect of this kind of
    design is that the tables can sometimes be generated by
    another program - a parser generator, in the classical case.
    As a more earthy example, if an operating system is driven
    by a set of tables that connect I/O requests to the
    appropriate device drivers, the system may be `configured'
    by a program that reads a description of the particular
    devices connected to the machine in question and prints the
    corresponding tables.
  • Combining data­driven programs with function pointers
    leads to an astonishingly expressive way of working, a way
    that, in my experience, has often led to pleasant surprises.
    Even without a special O­O language, you can get 90% of the
    benefit for no extra work and be more in control of the
    result.
  • Simple rule: include files should never include include
    files.  If instead they state (in comments or implicitly)
    what files they need to have included first, the problem of
    deciding which files to include is pushed to the user
    (programmer) but in a way that's easy to handle and that, by
    construction, avoids multiple inclusions.

This link has been bookmarked by 8 people . It was first bookmarked on 09 Jul 2006, by craig hancock.

  • 11 May 08
    yorkjong
    York Jong

    What follows is a set of short essays that collectively encourage a philosophy of clarity in programming rather than giving hard rules.

    C programming concept

    • Length is not a virtue in a name;
      clarity of expression is.
    • When the variable names are
      huge, it's harder to see what's going on.
    • 13 more annotations...
  • 01 Apr 08
  • 22 Mar 07
  • 09 Jul 06
  • 30 Jan 06
  • 30 Dec 05
    ironick
    Nick Gall

    From: Rob Pike: Notes on Programming in C. There's another reason that data dominates: in the context of the distinction between "code" and "data", data is simply the set of bits that we intend to frequently change, while code is the set of bits that do t

    Web Architecture - REST

    • Rule 5. Data dominates. If you've chosen the right data structures and organized things well, the algorithms will almost always be self­evident. Data structures, not algorithms, are central to programming. (See Brooks p. 102.)
  • 29 Jul 05