Monday, February 22, 2016

[zomcxiel] Idiomatic language features

When describing an algorithm, it would be preferable to use pseudocode that is a real programming language, or something very close to a real programming language: this way the pseudocode can easily be executed to verify that it actually works.  (Inspired by the bizarre prefix syntax for object attributes in the pseudocode for the CLR textbook 2nd edition, which, in retrospect, resembles Haskell record accessor syntax. In the 3rd edition (CLRS), object attributes were changed to use the dot syntax as seen in many object-oriented languages.)

The pseudocode should be easily translatable into other languages, so should avoid language features idiomatic to the chosen real language, features that would take a lot of effort or awkwardness to replicate in another language.  However, if some idiomatic feature is "necessary" for the algorithm in question, for an open-ended definition of "necessary", go ahead and use it.  For example, an algorithm may be much more difficult to describe without lazy evaluation as in Haskell.  There is not a black-and-white distinction about what features are acceptable for pseudocode; this is why there cannot be a standardized language for pseudocode.  (The original motivation was to have a standardized pseudocode language for describe algorithms in Wikipedia.  I suspect Wikipedia's use of pseudocode is also mired in political difficulties of not wanting to show favoritism toward any particular real programming language.)

Enumerate the idiomatic features of various programming languages.

generally: Object-oriented features, exceptions
C: pointer arithmetic, stdarg, longjmp, null terminated strings
Haskell: Lazy evaluation, monads, closures

No comments :