What is pseudocode?

What is it used for?
How should look and what qualities should have a good pseudocode?

    1 answer 1

    What is pseudocode?

    Pseudocode is a kind of mixture of code and natural language.

    Pseudocode is a compact (often informal) language for describing algorithms using keywords of imperative programming languages, but omitting irrelevant details and specific syntax. Wikipedia

    It should be easy to understand, but at the same time writing good pseudocode can be quite a challenge.

    What is it used for?

    Pseudocode is an attempt to maintain a balance between the comprehensibility of a natural language and the accuracy of the code.

    • When we describe an algorithm in a natural language, the high-level abstractions can unnecessarily complicate both the analysis of the algorithm and its implementation in a specific programming language.
    • On the other hand, when we describe an algorithm in PL, we have to spend a lot of time on describing the details of the algorithm, which we probably will not implement (after all, we usually analyze the algorithms before deciding which one we will implement)

    A good pseudocode should:

    • Looks like good code and simple language .
    • Ignore irrelevant details
      If you think about where in your pseudocode to put a comma - you are doing something wrong.

    • Omit the obvious
      For example, do not specify obvious variable types from the context

    • Consider Context Expression Отсортировать массив с помощью quicksort - it only makes sense if it is not written in the description of the quicksort algorithm.

    • Do not be too abstract
      Through your pseudocode, it should be possible to see the model being described, otherwise the algorithm cannot be analyzed, it is too abstract.

    And most importantly, watch the result , how your pseudocode works in practice.
    If you find that your colleague is not able to parse your pseudocode, or transfer it to PL, then it is probably worth working on pseudocode.


    Pseudocode example:

     Пузырьковая сортировка: для j от 1 до n-1 для i от 1 до nj если aᵢ < aᵢ₊₁ поменять их местами 

    On mobile devices, the code above may not display correctly: it says a[i]<a[i+1]

    • @Andrey, your proposed revision contains unimportant implementation details that complicate the perception of the basic idea of ​​the algorithm. Pseudocode is not required to be academically accurate. - vp_arth