4 ms·
expression-based programming Yes! This is the real win of functional over imperative languages. It means you can understand blocks of code in isolation and the
by greener_grass 2y ago
expression-based programming
Yes! This is the real win of functional over imperative languages. It means you can understand blocks of code in isolation and then compose them into larger blocks. Bottom-up programming. This is what is missing from the imperative paradigm, and why that approach struggles to scale with problem complexity.
- netbioserror 2y agoSo very underrated. My program structure for years now has essentially been pyramids made of Lego-stacked functions, and I use value-returning syntactic features as often as I can.
- kalaksi 2y agoI'm baffled. You just described pretty much any programming language to me.
- netbioserror 2y agoI have personally seen production code consisting of C and PHP programs with GLOBAL shared state bounced back and forth between dozens of functions simultaneously, where the parameters reflect only a fraction of the actual input data to the functions' procedures. Expressions and airtight design may seem normal to you, but older generations of programmers either had little exposure to philosophical musings on the constitution of good software design, or received roundly awful early wisdom from the industry's nascence. Of course, C has a habit of enforcing essentially no rules on program design, so it was a wild world of scattershot practices (or anti-practices).
- greener_grass 2y agoIn most languages, the value of an expression depends on two things: 1. The right-hand-side of the declaration 2. Where you are in program execution Consider this JavaScript: let x = 1; x += 1; x *= 3; What is the value of x? Valid answers are 1, 2 and 6. Now lets restrict our JavaScript to pure expressions: let x1 = 1; let x2 = x1 + 1; let x3 = x2 * 3; The values of x1, x2, x3 are full defined by the RHS; they do not change once bound. This makes it easier to reason about the code - you only need to follow the definitions. This is an unnatural way to write JavaScript, but some languages make this easy (Clojure, Elm, OCaml, F#, Haskell, Erlang, ...).
- karmakurtisaani 2y agoOne should write non-functional code so that it's understandable in small blocks. On the other hand, I've seen some undecidable functional code also in small quantities. Mapping arrays of tuples containing functions from strings to integers with no apparent connection to business logic. Nevertheless, I'd take a functional language over procedural any day. The horror of mutable memeber variables changing all over their class is real.