Doug Moen
06/07/2019, 12:49 PMWhy is shared mutable state considered bad? Isn't it an accurate reflection of the universe we live in?No, it is not an accurate reflection. SMS leads to spooky action at a distance. With SMS, I can nail together two pieces of wood in Toronto, and unexpectedly, a house collapses in Los Angeles. SMS enables unpredictable non-local effects. I can't rely on local reasoning to understand what a program is doing.
Konrad Hinsen
06/11/2019, 11:33 AMjaukia
06/11/2019, 11:53 AMCorey
06/11/2019, 4:22 PMWith SMS, I can nail together two pieces of wood in Toronto, and unexpectedly, a house collapses in Los Angeles.I mean, if a butterfly flaps its wings in Brazil we get a hurricane off the coast of Florida, so that seems legit to me. đ
Daniel Garcia
06/11/2019, 4:48 PMDoug Moen
06/11/2019, 6:22 PMEdward de Jong / Beads Project
06/12/2019, 5:26 AMKonrad Hinsen
06/12/2019, 6:37 AMKonrad Hinsen
06/12/2019, 6:38 AMKonrad Hinsen
06/12/2019, 6:42 AMKonrad Hinsen
06/12/2019, 6:49 AMDaniel Garcia
06/12/2019, 3:41 PMGarth Goldwater
06/12/2019, 3:41 PMKonrad Hinsen
06/12/2019, 6:24 PMDoug Moen
06/12/2019, 8:13 PMtrue becomes: false
. @Daniel Garcia In Smalltalk, objects encapsulate their state, at least in theory. But if you send a message to an object to query its state, the object has no choice but to return another mutable object in answer to the query. Which the caller can then mutate, possibly by accident. If an object returns one of its instance variables in response to a query (which might be the simplest way to write the code), then the caller can mutate the object's internal state without going through the object's message interface. Which could make the object's internal state invalid. So OOP creates this huge problem with shared mutable state, which can be mitigated by design patterns, coding hygiene, and additional language complexity.shalabh
06/12/2019, 11:31 PMshalabh
06/12/2019, 11:38 PMDoug Moen
06/13/2019, 2:13 AMgman
06/13/2019, 3:31 AMshalabh
06/13/2019, 5:25 AMAlan Kay's original pitch for Object Oriented Programming included the idea that "the real world" is made of stateful objects, therefore a programming model where there are no values, and everything is a reference to a stateful object, must be more natural, and if it's more natural, then it's a better style of programming.Do you have a source for this? Object based metaphors pop up all over different domains, not just the physical world. Even the final products of any programming - buttons that push, windows that move, pictures that can be cropped, shipped around etc. - are all virtual objects. People don't want pure functions, they want their computers to have state and be able to manipulate it. This doesn't mean programming has to be OO, of course. But perhaps it means we should start with objects as an underlying substrate (directly modifying these would be considered primitive) and then work up to pure transforms or other ideas that operate on this substrate. So I don't think OO and FP are mutually exclusive, but more like clusters of concepts - some of which can be integrated. This is not just for personal computers but also large scale services. Once you compile and run an FP program, it becomes an object 'in the large'. Because when you zoom out from a single program to a whole system, all the microservices, monoliths, databases, etc. are objects of a kind (have state + communicate via messaging). Again, what we ended up building and reasoning about are object-based models. So does it mean we've just kicked the can down the road? Regarding 'local reasoning' and 'simulating in your head', what I feel is any single programming paradigm is going to fail in some scenario because there will always be some cross-cutting concerns (no matter what kind of slices form the program). So no single paradigm is going to work in all cases - perhaps we should thing about multi-perspective as a base requirement. E.g. a system where you can query the computer about the relationship between one entity and another. And query the system also about the effects of a change to an entity you are about to make. We're way past the point of scaling where mental reasoning can work for us.
Drewverlee
06/13/2019, 2:30 PMshalabh
06/13/2019, 4:29 PMEdward de Jong / Beads Project
06/14/2019, 6:04 AMDoug Moen
06/14/2019, 11:53 AMSo any language that claims to not use mutable state is merely concealing the mapping from pure functions to mutable state.Abstraction is the central idea that underlies high level programming languages. There is nothing "mere" about it.
The inventor of FP, John Backus, had a goal of creating interchangeable parts, and he felt that reducing mutable state would make things more combineable. However, 50 years later his original proposals haven't worked out. There is no evidence that people can take a chunk of Haskell code or any other FP language and inject it into another program easily."no evidence"? The fact that you can do this is why I fell in love with functional programming, and it's a central part of my mental experience when I am writing functional code. Here's a quote from Backus that you might be referencing:
Associated with the functional style of programming is an algebra of programs whose variables range over programs and whose operations are combining forms. This algebra can be used to transform programs and to solve equations whose "unknowns" are programs in much the same way one transforms equations in high school algebra. These transformations are given by algebraic laws and are carried out in the same language in which programs are written.Haskell people call this "equational reasoning". It works. It's high school algebra, applied to programs. It's what you do when you think and program in the functional style. In principle, you can use this kind of reasoning when programming in any language. But imperative languages are not designed with equational reasoning in mind: a lot of algebraic laws are just broken and don't work, which makes them frustrating and klunky to use. You are forced to think imperatively, which sucks, although it's a necessary evil when you are doing performance tuning. Functional languages are specifically designed to have a large set of algebraic laws, which makes them much more satisfying to use if you think this way when you program.
Drewverlee
06/14/2019, 2:02 PMGarth Goldwater
06/14/2019, 5:30 PMDoug Moen
06/14/2019, 8:56 PMGarth Goldwater
06/14/2019, 11:58 PMDaniel Garcia
06/15/2019, 12:27 AMDoug Moen
06/15/2019, 1:43 AMmutable state is (repeating a cliche at this point) a fact of life and there are different options for dealing with itAgreed. "Shared mutable state" (SMS) is only one of the options for dealing with mutable state. SMS is strongly associated with OOP. You put all of your mutable state into objects, and the objects are organized into a graph, which usually contains cycles. That graph of object references makes shared mutable state unavoidable. An interesting alternative to OOP is data-oriented design (DOD). In this paradigm, you put all of your data into a centralized hierarchical data structure, analogous to a relational database. Application logic is kept separate from the data. DOD seems to be associated with systems level programming in C++ and Rust; the video game version is called Entity Component Systems. The claimed benefits of DOD are performance (better cache coherence, better multi-core performance) and maintainability (it's easier to evolve the code in response to changing requirements: you aren't constantly refactoring a class hierarchy). Some DOD practitioners are also claiming smaller code size, which is great if you are compiling to WASM. It's better for Rust programming, because cyclic object graphs in OOP "break the borrow checker", plus Rustacians are interested in performance and maintainability. I'm still trying to get a handle on DOD. Because of that central hierarchical data structure, it doesn't seem to require shared mutable state, and it seems compatible with pure functional programming. It also looks more compatible with GPU programming, because OOP object graphs aren't feasible on a GPU. So I'm investigating these ideas in the context of my Curv project, which can be considered a pure functional language for programming GPUs. A while back, somebody posted a reference to Raph Levian's Druid, a data oriented GUI framework in Rust. There is also Elm, which is a pure functional language for creating GUIs. The Elm Architecture seems to have some resemblance to DOD.
shalabh
06/15/2019, 4:09 AMshalabh
06/15/2019, 4:12 AMNiko Autio
06/15/2019, 7:58 AMObject based metaphors pop up all over different domains, not just the physical world. Even the final products of any programming - buttons that push, windows that move, pictures that can be cropped, shipped around etc. - are all virtual objects. People don't want pure functions, they want their computers to have state and be able to manipulate it.People also want see changes what is have been made, go back in history and undo things. In general: reason about mutations. It's a bit ironic that systems that are pro mutation have actually much harder time to reason about them. Those aspects are therefore currently under shipped in real world products.
Duncan Cragg
06/15/2019, 9:53 AMDoug Moen
06/15/2019, 3:50 PM@Duncan Cragg: Clearly shared mutable state is not even negotiable in programming, otherwise we'd have no disks, no databases, no GUIs, no 3D worlds, no social media.. basically nothing apart from addition and the like.When we say that "shared mutable state is bad", we are not denying the existence of reality. Far from it. We are taking a position on the semantics of expressions in high level programming languages. I think there might be some confusion around what claims are being made. Maybe the issues can be clarified with a slight change in terminology. How about "SMS semantics" or "SMS expression semantics" instead. Some researchers making these claims might use the term "imperative semantics", but I don't like that, it's too broad. My research project is a pure functional language that supports (a growing subset of) imperative style programming, but doesn't have SMS semantics. Of course computers and programs have state that changes over time, but languages with SMS semantics are maybe not the best tools for dealing with state. SMS languages are based on an idealized model of computation where computers have a single core, there is a global memory store where all words of memory have the same cost of access, and there is no networking. That worked well in the past, but not today. Once these assumptions are violated, the model breaks down. The canonical example of the failure of SMS semantics is multithreaded programming. The simple, obvious extension of SMS to support concurrency is shared memory with locks, and that is a nightmare to program with. One response is to patch and extend SMS to work around the problems. Rust supports safe concurrent programming, but at a large cost in language complexity. Another response is to look for simpler, more powerful alternatives to SMS, and that's what some of us in the Future Of Coding group are doing.
fyr
06/15/2019, 4:47 PMDuncan Cragg
06/15/2019, 5:19 PMlanguages with SMS semantics are maybe not the best tools for dealing with state.As I said, a language that doesn't allow many threads simultaneous write access would presumably still have your "SMS semantics" (? not sure what exactly that is?). And why can't you add this "SMS semantics" to FP in a clean model?
Duncan Cragg
06/15/2019, 5:20 PMDuncan Cragg
06/15/2019, 5:20 PMDuncan Cragg
06/15/2019, 5:22 PMDuncan Cragg
06/15/2019, 5:23 PMfyr
06/15/2019, 5:35 PMshalabh
06/15/2019, 5:56 PMDuncan Cragg
06/15/2019, 10:26 PMKonrad Hinsen
06/16/2019, 10:59 AMDoug Moen
06/16/2019, 12:18 PMChris Knott
06/16/2019, 12:43 PMDoug Moen
06/16/2019, 12:43 PMDoug Moen
06/16/2019, 1:33 PMKonrad Hinsen
06/17/2019, 7:29 AMopeispo
06/17/2019, 1:06 PMDoug Moen
06/17/2019, 6:30 PMNiko Autio
06/17/2019, 6:59 PMDaniel Hines
06/17/2019, 7:10 PMNiko Autio
06/17/2019, 7:34 PMshalabh
06/17/2019, 7:39 PMNiko Autio
06/17/2019, 8:10 PMNiko Autio
06/17/2019, 8:40 PMNiko Autio
06/17/2019, 8:46 PMDrewverlee
06/18/2019, 6:00 AMDoug Moen
06/18/2019, 4:12 PM@Niko Autio said So what it would look like if we would keep detailed knowledge how to do X in a functions itself instead of data structure?
@Drewverlee said If you system is limited to types which all share the same polymorphic functions, you need less many conversions.In "Data Oriented Design", unlike OOP, you represent application data using dumb data structures and generic data types, and you put all of your application logic into functions, instead of into classes. You have far fewer data types, and fewer conversions. The Cell programming language uses relations, rather than objects, to model application data, and it claims benefits for the relational model over the object-oriented model. Once again, you use a small set of generic data types to describe your data, and application logic is separated from the data. Here are the Cell data types: http://cell-lang.net/data.html
Edward de Jong / Beads Project
06/19/2019, 4:50 AM