Saturday, October 12, 2024

The four types of programming languages

There are four types of programming languages.  I'm not talking about the religious differences between object oriented, procedural, and functional languages.  I'm talking about something more fundamental - syntactic structure.  The vast majority of computer languages (excepting esoteric or very primitive ones) fall into the four camps of ALGOL, LISP, APL, and Forth/Joy.  These differ based on how you read and understand the code.

Note:  Examples are not necessarily valid code in these languages.

ALGOL:  Left to right (left or right associative based on what makes sense, usually), prefix (except infix operators like '+' and '*'), inside out.  These are the procedural languages most programmers are familiar with.

    command(arg1)
    command(arg1, arg2)
    command(arg1, arg2, arg3)
    command-a(arg1a, command-b(arg1b, arg2b), arg3a)
    add(1, 2 * 3)
    if (3 > 2) then {print("true")} else {print("false")}


LISP:  Left to right (no associativity), prefix (always), inside out.

    (command arg1)
    (command arg1 arg2)
    (command arg1 arg2 arg3)
    (command-a arg1a (command-b arg1b arg2b) arg3a)
    (add 1 (* 2 3))
    (if (> 3 2) (print "true") (print "false"))

    

APL:  Left to right (right associative), prefix or infix, inside out.  It's easier to read right to left.

    command1 arg1
    arg1 command1 arg2
    there are no 3 or more argument commands in APL
    arg1a command-a arg1b command-b arg2b
    1 add 2 x 3            this is the same as 1 add (2 x 3)
    
3 > 2 ⍳ ⎕  ← "true" ⋄ "false"            I got this from an AI prompt.  APL is weird.


Forth / Joy:  Left to right (usually no associativity), postfix (usually, unless it's immediate, which looks like prefix or infix).

    arg1 command
    arg1 arg2 command
    arg1 arg2 arg3 command
    arg1a arg1b arg2b command-b arg3a command-a
    2 3 * 1 add
    Forth:  3 2 > if "true" print else "false" print then
    Joy:  3 2 > ["true" print] ["false" print] ifte


The ALGOL (procedural) family of languages make regular use of syntactic sugar to make reading the code easier.  The annoying-to-learn syntax is what makes it more readable, and programmers spend much more time reading code than writing it.  That's part of why they have mostly conquered the programming world, despite the niche technical superiority of the other language styles.  



No comments:

Post a Comment

I reserve the right to remove egregiously profane or abusive comments, spam, and anything else that really annoys me. Feel free to agree or disagree, but let's keep this reasonably civil.