Bird Style

Literate Programming style
Tags: programming
Reading time: about 1 minute

What is Literate Programming?

Literal Programming is a programming paradigm in which the emphasis on code and comments are reversed. While comments are secondary in most programming languages, and need to be marked as such; in literal programming every line is a comment unless it is marked as code.

What is the Bird style?

Bird style, developed by Richard Bird, is a style of literate programming that is particularly easy to get started with. The formatting is very simple, and it should be pretty obvious to readers even without editor support.

While it lacks some advanced functionality found in other Literate Programming systems, the ease-of-use should reduce friction when introducing it to other people.

Here’s a small example.

Flipping a coin
===============

A coin flip results in either head or tails. Since it is a random process, we
can use the random module.

> import random

Let's define a simple function that returns the result of a coin flip.

> def flip():
>     return random.choice(["Heads", "Tails"])

Syntax of the Bird Style

  • All lines starting with > are interpreted as code.
  • Everything else is a comment.
  • Leave a blank line before and after code blocks.

Aside from these rules, you can format your documentation and code in any way.

How to turn it into code?

Due to the simple formatting of the Bird style, it is very easy to convert it to code. It can probably be done using grep or sed.

If you would like a standalone tool that enforces the style a little better, you can use unbird to do this.

Additional resources

The following pages link here

Citation

If you find this work useful, please cite it as:
@article{yaltirakliwikibirdstyle,
  title   = "Bird Style",
  author  = "Yaltirakli, Gokberk",
  journal = "gkbrk.com",
  year    = "2024",
  url     = "https://www.gkbrk.com/wiki/BirdStyle/"
}
Not using BibTeX? Click here for more citation styles.
IEEE Citation
Gokberk Yaltirakli, "Bird Style", December, 2024. [Online]. Available: https://www.gkbrk.com/wiki/BirdStyle/. [Accessed Dec. 17, 2024].
APA Style
Yaltirakli, G. (2024, December 17). Bird Style. https://www.gkbrk.com/wiki/BirdStyle/
Bluebook Style
Gokberk Yaltirakli, Bird Style, GKBRK.COM (Dec. 17, 2024), https://www.gkbrk.com/wiki/BirdStyle/

Comments

© 2024 Gokberk Yaltirakli