]> njoseph.me Git - blog.git/blame - content/posts/of-statements-and-expressions.md
Fix RSS feeds
[blog.git] / content / posts / of-statements-and-expressions.md
CommitLineData
b1833cc7
JN
1---
2title: "Of statements and expressions"
3date: 2017-09-15T17:40:09+05:30
4lastmod: 2017-09-15T17:40:09+05:30
5tags : [ "functional-programming", "lisp" ]
6categories : [ "tech" ]
7layout: post
8type: "post"
9highlight: false
10---
11
12
a37c7a26 13![Punch Card with a Fortran Statement](/blog/punch-card.jpeg)
b1833cc7
JN
14*By Arnold Reinhold [CC BY-SA 2.5 (https://creativecommons.org/licenses/by-sa/2.5)], via Wikimedia Commons*
15
16In the beginning there was FORTRAN.
17Programming was done line by line with each line printed on a punch card.
18There were no conditionals, only GOTOs that pointed to line numbers.
19This is where statements in programming came from.
20
21Then there was structured programming (like in C).
22Structured programming introduced blocks and kept the statements and GOTOs.
23GOTOs were slowly thrown out as they were too troublesome.
24Functions and Structs came to be defined in terms of blocks.
25Modularity increased with blocks.
26
27Then there was object-oriented programming.
28Blocks and statements were kept, and GOTOs were mostly discarded.
29State and functions were bundled together into objects.
30Modularity increased with objects.
31
32This is the story that most people know. But in the same timeline existed
33functional programming which offered modularity on a whole different level.
34
35Before Alan Turing was defeating the Nazis with his legendary computer, his teacher Alonzo Church invented a mathematical formalism known as the Lambda Calculus — a formalism that only consisted of the lambda character (duh!), names and expressions.
36
37Before C with its blocks, pointers and functions was invented, a computer scientist named John McCarthy wrote a paper that axiomatically defined all of programming in terms of just 7 operators. An implementation of these operators on the machine was done and mostly used for List Processing came to be known as LisP.
38A function in Lisp is a lambda expression bound to a name. Nope, no statements, only expressions. Entire Lisp programs were just expressions.
39
40Then came ML, Haskell, OCaml, Scala, Clojure, F# etc., but the concept remained the same. They used expressions, not statements.
41
42Expressions in programming originated from mathematics, whereas statements in programming exist because we were line-feeding the FORTRAN code of yore and are stuck with our old habits.
43Old habits die hard and sometimes they last generations, like the QWERTY keyboard layout that makes no sense to use on modern computers.
44On the positive side, we should probably be happy that we let go of the punch cards that we were writing our statements on.
45
46**Disclaimer**: *This article is written like a story. There’s no guarantee of factual or chronological correctness.*
47