York Jong's personal annotations on this page
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 minimumlength but
maximuminformation 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 saymaxphysaddr(not) for a global variable, but
MaximumPhysicalAddressnp
notNodePointerfor 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 selfevident. 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 datadriven 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 OO 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.
-
York JongWhat 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. - 13 more annotations...
-
-
Nick GallFrom: 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
-
Rule 5. Data dominates. If you've chosen the right data structures and organized things well, the algorithms will almost always be selfevident. Data structures, not algorithms, are central to programming. (See Brooks p. 102.)
-
Would you like to comment?
Join Diigo for a free account, or sign in if you are already a member.