0.3.0 • Published 7 years ago

@pangrr/literate-programming v0.3.0

Weekly downloads
1
License
ISC
Repository
github
Last release
7 years ago

What do I want?

I want to feel natural to write document for my program first, then write code.

Why? Because I feel like to focusing on writing document first without worrying about implementation.

Also, a good document about the whole program and each file makes other people not hate reading your program.

Here is how I'd like to write a program:

  1. Write program/project wise document in a file.

  2. Write a document about the file structure.

  3. Generate files from the file structure.

  4. Write document for each file.

  5. Generate code files from the document files.

How to make it happen?

Write .md files as documents. Because it's easy to write document and easy to sew code. Plus .md enjoys code syntax highlight in a lot of places.

  1. Write struct.js.md for the whole program:

    This is a demo program. We want to show all basic file structure here.
    The file structure is as below:
    ```javascript
    module.exports = {
        foo: {
            "foo.js": "description of this file"
        },
        bar: {
            "bar.js": "description of this file"
        },
        "far.js": "description of this file"
    }
    ```
  2. Run lit init to generate the files from structure.js.md. This will generate .md files for supported file types: .js, .c, .cpp, .h

  3. Write .md files. Write document first. Then insert code into proper places. A typical .md file looks like:

    This file is to ...
    To achieve that, we need a function like this:
    ```
    function foo () {}
    ```
    We also need a function like this:
    ```
    function bar () {}
    ```
    Below are the steps:
    1. Call foo so that ...
    ```
    foo();
    ```
    2. Call bar so that ...
    ```
    bar();
    ```
  4. Run lit undoc to generate code files from .md files.

Todo

  • Add command line option to undoc document files on save.
  • Add command line to delete all code files to focus on writing documents.
  • Add command line to delete all generate-code-file document files. Just to go the old way.
  • Add command line to remove code from document files. For cleaner document display.
  • Generate document files from code files. Code files are easier to debug. Thus it's easier to fix code bugs in code file. But document files needs to be updated too.
  • IDE support of code in document file in par with that of code file.
    • Toggle collapse/expand code in document files.