Sashmark / Blog

Pseudocode template in Markdown: inputs and indented steps

Bobby Huang ·

Describe one algorithm in a Markdown file before writing real code. Give it a title, one sentence about its purpose, its inputs and its output. Put the pseudocode in a text fence, indent branches and loops, and name what each return path gives back. The single block below uses a fictional reading-group routine as its example.

Key takeaways

  • A replaceable title identifies the routine; its purpose follows in a single sentence.
  • Input and output lines state what goes into the invented routine and what comes back.
  • Jane Doe's fictional example groups invented reading-list notes by made-up tags for the Doe reading group.
  • Indentation places each branch and repeated action beneath the line that governs it.
  • The readability note discusses short actions, consistent names and explicit return paths.

A pseudocode template gives an algorithm a written shape before anyone writes real code. It describes the data arriving, the choices made along the way, the actions repeated and the value returned. The wording stays language-neutral: it says what the routine does without choosing a programming language.

This template describes one invented algorithm. Its steps belong to the routine; they aren't directions for a person to carry out a task. Here the subject is the algorithm's text, rather than fence mechanics or a drawing of its paths.

What the pseudocode file holds

Begin with the routine's title and one plain sentence naming its purpose. Input lines name the data it receives. The output line names what it returns. Those lines set the boundary of the routine before its first action appears.

Keep the description in an .md file. The introduction to the .md file format explains that file type. Here, the surrounding prose explains the choices in the algorithm, and one fenced block holds the reusable shape filled with invented details.

The pseudocode template and invented example

In this invented setting, a writer called Jane Doe sketches a routine. Her Doe reading group is fictional too. Every note and tag below is invented. The note texts are fragments made up for this example, unrelated to any book or author. The tags neral, vesh and drel have no meaning beyond this routine.

The block keeps a title placeholder so it can become a different routine later. Its remaining lines show Jane Doe's example: group reading-list notes by tag, putting a note without a tag in the drel group. Replace that purpose, input, output and pseudocode together when describing another algorithm.

Title: [routine title]
Jane Doe's routine groups invented reading-list notes by tag for the Doe reading group.
Inputs: notes with text and an optional tag
Example input: "folded moon" tagged neral; "glass path" tagged vesh; "blue hinge" without a tag
Output: groups of notes, with one group for each tag

Begin
    Set groups to an empty grouping
    If notes is empty
        Return groups
    Otherwise
        For each note in notes
            If the note has a tag
                Set chosen tag to the note's tag
            Otherwise
                Set chosen tag to drel
            If groups has no group for chosen tag
                Add an empty group for chosen tag
            Add the note to the group for chosen tag
        Return groups
End

The sentence beneath Title names the whole job. Inputs describes each note, and Example input supplies three invented fragments. Output describes the returned grouping, rather than an action to perform after the routine ends.

The empty-input branch has its own return. The other branch contains a loop over the notes, a choice about each note's tag, and a branch that creates a group when needed. Adding the note sits outside that last branch: the note goes into its group whether the group was just created or already existed. The final return sits outside the loop, after all input notes have been considered.

These are descriptive lines, with no language-specific punctuation required. The block uses a plain-text fence tagged text; Markdown code blocks covers the fence itself. This post keeps the example to one block so its input, choices and output stay together.

A short note on readability

Give each action its own short line. Use the same noun for the same thing throughout: this example keeps notes, chosen tag and groups unchanged as names. Indent a branch's actions beneath its condition and a loop's actions beneath the line that starts the repetition. Bring a line back out when it no longer belongs to that branch or loop.

A return should say what comes back. Both returns here name groups, including the empty grouping on the first path. The prose beside the block can explain a choice such as the drel fallback without making each pseudocode line carry that explanation too.

Naming the algorithm file

For this routine, group-reading-notes.md describes the file's subject. Keep a separate file when the purpose or inputs describe a different algorithm. See Markdown file naming for lowercase naming and hyphen separators.

Where Sashmark fits

The Markdown desktop app Sashmark remains in development. Its planned purpose combines reading with editing for people receiving files from agents. For an algorithm description, that role would mean reading the text or changing its wording.

Questions

Which parts does this pseudocode template include?
A title, a purpose sentence, input and output lines, and language-neutral pseudocode with indented branches, loops and return paths.
What happens when the example has no input notes?
The first branch returns an empty grouping. With input notes present, the routine groups them and returns the grouping after the loop.
How does the example handle a missing tag?
It uses the invented tag drel for that note, then adds the note to the group for that tag.

What Sashmark plans for v1: Features · Roadmap

View as Markdown