]>
Commit | Line | Data |
---|---|---|
b1833cc7 JN |
1 | --- |
2 | title: "Of statements and expressions" | |
3 | date: 2017-09-15T17:40:09+05:30 | |
4 | lastmod: 2017-09-15T17:40:09+05:30 | |
5 | tags : [ "functional-programming", "lisp" ] | |
6 | categories : [ "tech" ] | |
7 | layout: post | |
8 | type: "post" | |
9 | highlight: false | |
10 | --- | |
11 | ||
12 | ||
13 | <img src="https://cdn-images-1.medium.com/max/2000/1*XUB8BR4mGQKtmiFsZt4_1w.jpeg" width=800/> | |
14 | *By Arnold Reinhold [CC BY-SA 2.5 (https://creativecommons.org/licenses/by-sa/2.5)], via Wikimedia Commons* | |
15 | ||
16 | In the beginning there was FORTRAN. | |
17 | Programming was done line by line with each line printed on a punch card. | |
18 | There were no conditionals, only GOTOs that pointed to line numbers. | |
19 | This is where statements in programming came from. | |
20 | ||
21 | Then there was structured programming (like in C). | |
22 | Structured programming introduced blocks and kept the statements and GOTOs. | |
23 | GOTOs were slowly thrown out as they were too troublesome. | |
24 | Functions and Structs came to be defined in terms of blocks. | |
25 | Modularity increased with blocks. | |
26 | ||
27 | Then there was object-oriented programming. | |
28 | Blocks and statements were kept, and GOTOs were mostly discarded. | |
29 | State and functions were bundled together into objects. | |
30 | Modularity increased with objects. | |
31 | ||
32 | This is the story that most people know. But in the same timeline existed | |
33 | functional programming which offered modularity on a whole different level. | |
34 | ||
35 | Before 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 | ||
37 | Before 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. | |
38 | A function in Lisp is a lambda expression bound to a name. Nope, no statements, only expressions. Entire Lisp programs were just expressions. | |
39 | ||
40 | Then came ML, Haskell, OCaml, Scala, Clojure, F# etc., but the concept remained the same. They used expressions, not statements. | |
41 | ||
42 | Expressions 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. | |
43 | Old habits die hard and sometimes they last generations, like the QWERTY keyboard layout that makes no sense to use on modern computers. | |
44 | On 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 |