8 ms·
Lisp, Smalltalk, and the power of symmetry (2014)
- dang 4y agoDiscussed at the time: Lisp, Smalltalk, and the Power of Symmetry (2014) - https://news.ycombinator.com/item?id=14333157 https://news.ycombinator.com/item?id=14333157 - May 2017 (58 comments)
- sillysaurusx 4y agoAny chance we could hear you talk about Lisp for a bit? I learned a lot from your thread-local comment: https://news.ycombinator.com/item?id=11240681 https://news.ycombinator.com/item?id=11240681 I was hoping you've stumbled on more ideas in the subsequent years. It's surprisingly hard to come up with simple + general. Ever since you mentioned thread-locals, I've been seeing the pattern everywhere. Our current C++ codebase passes around a "Chip" object (basically, a global configuration holding the current settings for the compiler), and it's remarkable how many lines of code it ends up touching. And it's not so easy to port your idea to C++ using thread_local. It turns out that Racket thread cells != thread_local storage. The key difference is that when you spawn a new thread, the new thread needs to inherit the current value -- thread_local doesn't automatically give that! And storing the current "Chip" as a global doesn't quite work either. If we spin up two different compilation threads for two different chips, each thread needs to see its own Chip independently of the other. We sidestep that for now by explicitly passing a Chip to any new threads, but it's not a general solution like your idea was. The moment I realized that, I thought wistfully about your comment from 6 years ago, and I've wanted to bug you ever since for "more like that, please."
- dgb23 4y agoA provocative quote from the article: > Languages such as Java, C++, and even Python seem to think that “object-oriented” means mostly “classes and inheritance.” Which is sort of like saying that “driving” means mostly “buttons and pedals.”
- trashburger 4y agoIt's true. The aforementioned languages not only boil down Smalltalk's object system into a basic "code sharing" scheme, they also perpetuate the unnecessary class and instance dichotomy. There is no reason an "instance" cannot be a "class" by itself. Self (a successor to Smalltalk) gets rid of this dichotomy by assuming a prototype-based object system instead of Smalltalk's classes. In Self, a prototype can be copied and that copy can then be used as its own prototype (this is used heavily in its UI toolkit Morphic).
- skissane 4y agoI think, even in prototype systems, the class-vs-instance dichotomy still exists at a conceptual level, even if the language/runtime doesn't make it explicit. My "window" prototype might be the same sort of thing as an individual window, but it would be a big mistake to try to actually display the prototype on the screen. Being explicit about the class-vs-instance dichotomy is a kind of strong typing – the language and runtime is aware of the conceptual distinction; whereas prototype-based languages are comparatively weak typing – the conceptual distinction still exists in the mind of the developer, but the language/runtime doesn't know about it. Class-based languages catch the "trying to use the prototype as if it was an actual instance" bug at compile-time, prototype-based languages leave it to blow up in bizarre ways at runtime (accidentally treating the prototype as an instance can lead to modifying the prototype, which can then cause unpredictable consequences for all the other objects having that prototype.) One big problem with Java, is the lack of meta-classes. Why can't I subclass Class? There are cases where doing so might be a sensible solution, but Java won't let you. In Java, for my instance methods, I can inherit them from a superclass, or have them implement an interface; but, static class methods cannot be inherited, nor can the static methods of a class implement an interface. This forces people into workarounds such as the factory pattern (which many Java applications/libraries massively overuse), when having a static method implement an interface might be a simpler solution – but that would require us to be able to (effectively) subclass Class. It also produces weird things like 'Class<T>' to mean a class extending class (or implementing interface) T, where meta-classes would offer a much more elegant solution. I don't think the real problem with Java is that it is class-based rather than prototype-based, I think the problem is that its class system is half-baked (no metaclasses, no reified generics, etc) A point this article raises, which is very true – in Smalltalk, reflection is read-write – modifying classes at runtime is as easy as querying them. Java reflection is essentially read-only. It is possible to do read-write reflection in Java, but it involves immense complexity with source code or byte code generation libraries, custom class loaders, etc – to do something which Smalltalk supports trivially. The argument on the Java side, is that read-write makes optimisations (JIT/etc) a lot harder. No doubt true, but there are alternatives which Java has not pursued – for example, support multiple versions of a class, code is JITted to work with the latest version at JIT time, but other versions are detected and cause a fallback to interpreter mode (possibly followed by re-JITting to add support for that other version.)
- didibus 4y agoI'm not sure that objects are data, depending on how data is defined, and I'd like to link to a very interesting discussion between Alan Kay, one of the creator of Smalltalk and Rich Hickey creator of Clojure (a lisp), discussing between themselves the merits of data and the meaning of data: https://news.ycombinator.com/item?id=11945722 https://news.ycombinator.com/item?id=11945722
- layer8 4y agoObjects, as seen from the outside, are entities with an identity and with behavior (hopefully associated with some interface contract). In addition, state may be part of the observable behavior of objects (and of their internal implementation). Data has no identity and no behavior, it is an immutable value. (Mutable data structures are actually objects.) Of course, you can realize objects in terms of data (e.g. machine code is data, and state is commonly represented by data), and conversely you can create objects that behave like data (like an immutable data structure), that is, realize data in terms of objects. That doesn’t mean that objects are data or vice versa.
- tempodox 4y agoThe “identity” and “behavior” encapsulated in an “object” is just more data to be interpreted in the right context. x86-encoded behavior of an object will all be gibberish to an ARM CPU. Or 64-bit code to a 32-bit CPU. You can add more data to say how the other data should be interpreted, but then you need even more data somewhere to state what the set of addressable interpreters is, which needs an interpreter as well. Data upon data upon data…
- discreteevent 4y agoAgreed, but I prefer to think of immutable data as a message because, in line with Alan Kay's thinking, data is always going to be interpreted by something (even if that something is a person).
- didibus 4y agoI think Alan Kay is saying that messages aren't good enough, and so he favors objects over data, because objects are more than data, they are also the interpreter of the data. My understanding is that he'd favor something where the code to interpret the message is also serialized and stored/retrieved and passed around, which is how I think Smalltalk works. Thus Alan Kay favors objects, which are not actually data, but they are data+interpreter bundled together. Where as Rich Hickey favors data on its own, and facilities to represent and model data alone, independently of a given interpreter, and then he favors having various external things apply their own interpretation of the data. At least that's my reading of their discussion.
- mathgenius 4y agoI have this idea that the dichotomy between functional & imperative (OOP?) programming is the "same as" the dichotomy in mathematics between algebra and geometry. Some more discussion of this here [1]. [1] https://www.quora.com/Why-is-functional-programming-seen-as-the-opposite-of-OOP-rather-than-an-addition-to-it/answer/Henry-Story https://www.quora.com/Why-is-functional-programming-seen-as-...
- dgb23 4y agoEven in a somewhat flexible language like JavaScript, it is often painful when you are limited by the lack of this kind of flexibility. The code is _right there_, you can look at it, but you cannot do anything with it. (Exceptions exist where an API provides a sane data representation but that is rare.) As a JS programmer by day and a Clojure hobbyist it feels like being a ghost in one of these movies, where they cannot interact with the world directly anymore. It's very frustrating. I sometimes think about all of the unnecessary work that is being done, the proliferation of libraries, tools and "transpilers" just because we lack this basic thing. I have never played with Smalltalk or some of its dialects or descendants. But judging from articles like this one, I have the feeling that I will end up liking it and then feel even more constrained by mainstream languages.
- Qem 4y agoIf you decide to get a feet wet on the Smalltalk family way of programming, I recommend the Pharo MOOC. I program mostly in Python, but OOP didn't click for me until I took the Pharo MOOC and saw how it was supposed to be: https://mooc.pharo.org/ https://mooc.pharo.org/
- smackeyacky 4y agoAs a former professional Smalltalk developer, I would caution against the experience of greybeards who wax lyrical about the incredible power of Lisp and Smalltalk, because even in their heyday that power was largely illusory. Firstly, anybody who encountered these environments early in their career will always be misty eyed about them. Secondly, ask them how big the team was they were working in and what the mechanism was they were using to deploy their programs. Smalltalk in particular is particularly difficult to package up into a deployable program that somebody else can run, and collaborating on development is fraught with code sharing issues you just don't get with less exciting environments like .NET or Python or Javascript/Node. In a modern context, Smalltalk and Lisp make little to no sense, especially when you have available a rich system of code being shared in more prosaic environments. It's a modern miracle that you can build what you need without re-inventing the wheel. There is no better time to be a programmer than now. Lisp and Smalltalk may well be great for reinventing wheels, for writing un-readable self modifying code and as a challenging intellectual exercise, but all your productivity just went out the window.
- neilv 4y agoSounds like you're evaluating software configuration management for Smalltalk from before that was hardly a thing for any development platform? Decades ago, Smalltalk implementations would let you dump some part of a system (say, the part that held your application) to a human-readable ASCII file (which is pretty Git-able), and also load that. If you were using it today, while we're using Git, I can't think of a reason a Smalltalk system couldn't have more tight integration with Git. Regarding Lisps, I'm not sure which school of thought you're coming from, but there are multiple. To someone without firsthand experience, the things you might've heard someone say, like "Foo is great because code and date are the same darn thing", or "Foo is great because it's dynamic up the wazoo", not only aren't necessarily the strengths that others would claim, or they might not mean the same thing. For example, imagine some kinds of syntactic extension in Lisps, in which some region of syntax isn't a function call. The region is clearly delimited, and it has an identifier right there that can be looked up to tell you the behavior. Someone without experience with that, but who has used an unfortunate kind of "DSL" in some other language, or, worse, has experienced surprise "operator" overloading in a different language, or who's seen unfortunate choices of when to introduce languages and when not, might think this Lisps thing is more of the same thing, when it's not.
- adamddev1 4y agoThere's something magically expressive about S-expressions and processing them. For a linguistic project I was thinking about how to represent sentence syntax as data and then I came across Chomsky's phrase structure analysis[1] which parses spoken language exactly like S-expressions in LISP! It's even illustrated with parenthesis or syntax trees, just like the old SICP vids explain. The phrase structure even uses recursive definitions so processing and inflecting the content of sentences can be done with recursive functions etc, (I did it in TypeScript) like something following a design exercise out of HTDP/SICP. I think the inherent parallel between human language phrase structure and S-expressions is beautiful. [1]: This book introduces the phrase structure in a shockingly LISP-like way. https://www.amazon.com/Grammar-Frank-Palmer/dp/B000S5VSAS https://www.amazon.com/Grammar-Frank-Palmer/dp/B000S5VSAS https://en.wikipedia.org/wiki/Phrase_structure_rules https://en.wikipedia.org/wiki/Phrase_structure_rules
- skissane 4y ago> There's something magically expressive about S-expressions and processing them. A downside I see with S-expressions – you often end up with something like (FOO BAR BAZ), where FOO identifies the type of thing, and BAR and BAZ are parameters/slots/etc – but you have to remember the (sometimes quite arbitrary) order that BAR and BAZ go in. Some Lisp family languages (such as Common Lisp, Clojure, Scheme with SRFI 88/89) support keywords (aka named parameters), so you can do something like (FOO :bar BAR :baz BAZ), which is considered equivalent to (FOO :baz BAZ :bar BAR). However, this is somewhat of a late development in the Lisp tradition, the status of its adoption is mixed, and (arguably) it is moving away (even if only by a little bit) from pure S-expressions. When people say "S-expressions", they normally aren't thinking of CLOS. I think JSON's model, in which lists and objects are independent first-class entities, with distinct syntax, has something to say for it. The downside of JSON objects, is their keys are strings, not symbols, and they don't have any kind of "class slot" (some people make up conventions here, for example a reserved property name such as "$class", but those conventions are not uniform or standardised). Oh, and we don't need all those commas. I think, if I was designing a LISP-ish language, I'd have a first-class syntax for objects which used different opening and closing characters – maybe (FOO bar baz) for a list, but [FOO :BAR bar :BAZ baz] for an object.
- dreamcompiler 4y agoThe article says "Smalltalk classes are powerful because they themselves are objects". This is true of CLOS (the Common Lisp Object System) as well. Every class is also an object. Which itself is an instance of...a metaclass. Which is also an object. Which you can introspect and modify at runtime. One can get wrapped around the axle by modifying such things casually, but when you really need it, it's quite handy.
- dreamcompiler 4y agoAnother power of Lisp is that it can accept functions as first-class arguments and produce functions as returned values. This means you can do obvious things like sort an array given a comparison function, or produce a generator from a static array. But it also means you can convert one function into another kind of function. Functional analysis calls these operators. Differentiation is an operator, as is integration, as is the Fourier transform, as is function composition. Many such things don't even need macros, but macros can help.
- ngcc_hk 4y agoThe dynamic part of lisp and its clos (from smalltalk), smalltalk, objective c (from smalltalk?), and javascript (from scheme abd its object prototype heritage) is the interesting one. The system can be modified whilst running … like a mainframe that cannot shut down but its code can be changed in-flight (strange to say that as it is cics etc role). That is better than cobol, Java …
- timonoko 4y agoI do not think a Seasoned Lisper thinks in terms of S-expression at all, counting brackets and doing other such shit. In his mind he sees only the 3D representation of pointer trees. S-expression is just a way to represent this tree in textual format. I always imagine 3D Lisp-evironment, where you only handle those trees with magical hand gestures like Tom Cruise. But this dream always fails when you go further details, like symbols and numbers: Why would use this archaic system of letters at all? Atoms should be just shapes and sizes.
- lyrachord 4y ago
- bartq 4y agoI can add my 2 cents to the Smalltalk discussion as I've been watching just recently many of the Alan Kay's videos on the YouTube. I can summarize Smalltalk thing this way: existing Smalltalk implementations (Squeak, Pharo etc.) are not something we should use in real world, they are just proofs of concept and food for thought. Real Smalltalk-like/Object oriented systems were bespoke written for specific machine and specific customer. Current day examples of OO (object oriented) systems really are... the Internet with all of its nodes, operating systems UI windowing systems to some degree (although very crippled and simple), maybe something like kubernetes, but again, it's very crippled and awkward. The ultimate goal is to create an environment, where there can exist objects (let's say processes/agents), which talk to the environment and other objects using messages. On top of all them you should be able to create full programming language which would allow you to compose/iterate/send messages to objects in any way you want, creating as many levels of abstractions as you wish, maybe creating new wrapper objects keeping some other objects inside etc. The programming language itself also should be the subject of real object orientation, for example the debugger or running program should be an object reacting to messages like "stop", "resume" etc. Languages like Rust/Go/JS should be used only to implement internals of some object and react to incoming messages in its narrow area when managing memory, data structures and IO. This is partially true today, we use OS to send messages/pipe sockets etc to the objects/processes. Sending messages should ignore the physical location of the object, just like the Internet does. Thinking this way, the glue code we write today should disappear in 99%, we should be able to start thinking in higher abstractions, about running processes, computations in time and space, how they relate to each other, make queries to the processes, create interceptors etc. This is that I see when Alan Kay says the computer revolution haven't happened yet and we're still dealing with bag of bad ideas from 60s and 70s. Just packaged in nicer clothes, because we have faster computers and better screens. We should start thinking longer term and not focus on immediate money as quickly as you see some results, because that's running in circles and real wealth is not created.