Skip to content

Instantly share code, notes, and snippets.

@hzhou
Last active August 17, 2017 17:14
Show Gist options
  • Save hzhou/48b9972e76c75b3455e2 to your computer and use it in GitHub Desktop.
Save hzhou/48b9972e76c75b3455e2 to your computer and use it in GitHub Desktop.
Literate Programming

Tim Daly on literate programming: we write down code which is what we do, but we didn't write down why and this why is super important.

Consider the action of "go to school". It is getting the bag, puting on shoes, getting out of the doors, and walking toward the location called school. If we drescibe it action by action, later when we read it it will be a puzzle on what we are doing -- we are missing th e why. So consider following code:

$call go_to_school

subcode: go_to_school
    $call get_bag
    $call put_on_shoes
    $call get_out_of_door
    $call wark_toward, school

subcode: get_bag
    ...

So literate programming is not documentaion + code. It is only when the programming language used for code is primitive and doesn't allow for properl writing, one needs add literate documentaion to explain why, and the result is often overly verbosity, and reviewers stil l need read the code. Even we know someone is "going to school", watching them actually walking the path can still be puzzling.

With proper facility in programming langauge, we can write code directly in literate way.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment