Programming heuristics

From Site
Jump to: navigation, search

Some of these are obvious, but the main purpose of this list is to remind me of something that I may have forgotten, when I come back to re-read it.

  • If a function from the API is too verbose, or even slightly too verbose, and you are using the function more than once, write a one-line proxy function that simplifies the call.
  • When writing a hexadecimal mask or constant, do this 0xFFFFffff, so that we can read it without having to count the fs.
  • When writing a small test application, include its sample output in a comment, as the first thing in its source.
  • Never use upper-case letters in filenames, in a project of any importance. (For portability reasons: some file systems are case-sensitive, others are not.) For the same reasons, always refer to files from within code by lower-case names.
  • Never use spaces in filenames.
  • With grep, use \W+ to search for whitespace. For some reason, the shortcut \s is not available.
$ grep -rE "define\W+MSG_WHATEVER" *
$ grep -r "define\W\+MSG_WHATEVER" *