Earlier quoted context omitted.
Isn't the real difficulty of undo the implementation of the undo method for each action? T The action list seems easy.
Store a list of actions, and represent your state as a sum of said actions. That way, no matter what the action is, "undoing" an action is literally just popping it off the list. actions = [append("The"), append(" quick"), append(" brown"), append(" fox")] state = reduce(actions, some_combiner) // This might give you a string "The quick brown fox" If you pop the last element `append(" fox")` of the actions and rebuil…
Does OO really match the way we think (1997) [pdf]
121–130 of 253 posts
Re: Does OO really match the way we think (1997) [pdf]
#122I think the big problem with OOP is that it's designed to simulate the real world but has the real world backwards. Real world objects are a composition of parts. The taxonomy of those objects, and its constituent parts, is am artificial construct independent of how those objects are composed. A frog is a frog because it fits some definition that experts agree on. The taxonomy comes afterwards - the composition just…
I think you'd benefit from taking a look at Entity Component Systems. Generally used for games, this programming pattern assigns behaviour to entities based on the components that they have. Moreover, neither entities nor components on their own actually own any behaviour. Behaviour occurs by systems that operate on entities with the associated component "signature". For example, an entity with a position and a veloc…
I was amazed when I saw the ECS architecture when I filled my toe into game development.
I remember wanting to apply it to other areas outside of game development.
It's interesting though that a paradigm that intends to help simulate the real world has been eschewed for speed and maintainability in favour of something like ECS in game development, which is all about simulation.
Re: Does OO really match the way we think (1997) [pdf]
#123A common sentiment expressed in threads like this is that people can write bad code in any language, therefore language doesn't matter. While that may be true, I don't think judging a language by the worse parts is a useful exercise. I'd rather judge a language by its best parts. To that end, can someone point to me an example of object-oriented code that they feel is elegant?
Re: Does OO really match the way we think (1997) [pdf]
#124Earlier quoted context omitted.
State doesn't magically disappear in FP. It just isn't given a name but it's still here, in your closures.
Functional programming languages do not capture mutable state in closures.
Yes, they can. In ML, you can build a function that returns a set of closures that manipulate or use shared mutable state. I'm quite sure you can do something equivalent in Haskell, too.
As always, “it depends” whether you would actually want to do that.
Re: Does OO really match the way we think (1997) [pdf]
#125Earlier quoted context omitted.
I love how much this comment makes me think. Thank you! To be honest, this sounds like a hell hole no matter what you did. It's a complex program that services two domains. I would say that in the real world, a frog studied in a pond and frog studied at a molecular level share the same properties. A frog is a complex object that has many parts. Naturally for a pond view, you provide the properties needed for that, th…
As I mentioned above, an Entity Component System would have no issue solving this. You'd add the molecular frog components (foobigate and brozigate) to wherever you create frog entities and then you'd also create and add a system that synchronizes between the entities that have pond frog components and these new components. None of the original code would change minus the instantiation function for a frog entity. Sim…
Re: Does OO really match the way we think (1997) [pdf]
#126Earlier quoted context omitted.
So LISP and Caml aren't functional programming language nowadays ? Because both allow you to modify what's in a closure.
There is no language definition or implementation called "LISP". Both Scheme and OCaml lexically capture variables by value, as if they have been passed in as arguments. This is not how it works in e.g. Python.
Re: Does OO really match the way we think (1997) [pdf]
#127Earlier quoted context omitted.
I have the polar opposite view. I love OOP because it provides a way to elegantly solve so many problems. To take a concrete example, consider the undo-redo mechanism in a text editor. It seems natural to create a list of objects with each object representing the action that can be undone or redone, and a pointer to the most recent action object. Undoing executes the 'undo' method and moves the pointer to the previou…
In functional programming you would store actions in lists with funs/closures inside those data. For example in erlang list of undo actions would look like this: Undo = [ { RemoveJpeg, JpegData} ] where RemoveJpeg is a fun (like closure) and JpegData is what would be given as argument to this fun. The implementing undo looks like this: undo_action(Document,[UndoHead|UndoTail]) -> {UndoFun,UndoData} = UndoHead, UndoFu…
RemoveJpeg
As possible implementation of undo could be undoAction: document with: undoList
undoList do: [:aBlock|
aBlock value: document].Re: Does OO really match the way we think (1997) [pdf]
#128No comment about OO in general, but I think Java/C# is a damn fine language design, avoiding many problems of newer paradigms. Here's an example: 1) Java: starts out with one opaque string type, because that's what OO methodology says. Changes the internals when needed. All clients continue to work forever. 2) Haskell: starts out with strings as exposed linked lists of characters, because functional methodology says…
Basically, when you have the notion of ownership/lifetime in a language, you have to make a distinction between an owned and a borrowed thing. When you pass an owned thing to a function, you give up your ownership of it, and can't use it anymore. When you pass a borrowed thing, you keep the ownership, and the compiler tries to prove that, based on ownership info it has, it lives long enough for the operation to be safe. Just as String and &str are owned-borrowed counterparts, you also have e.g. Vector and &[u8] (the former is an owned vector, the latter is a read-only, borrowed view into that vector) and many more examples of this dichotomy.
I don't see how this could have been solved in Rust without having those two types.
Re: Does OO really match the way we think (1997) [pdf]
#129Earlier quoted context omitted.
Rust is neither OO nor FP, it's procedural (like C and Fortran) but borrows concepts from OO and FP. OO requires data structures to support dynamic dispatch, and although you can have dynamic dispatch in Rust via trait objects your code is heavily gimped - no generics, you can only pass by reference, lifetimes have to be explicitly annotated, etc. It feels like OOP-emulating C code from back in the day. Likewise, if…
Contrary to mainstream knowledge there isn't one single truth of what OOP or FP actually are, rather multiple approaches of applying a set of abstract concepts.
Re: Does OO really match the way we think (1997) [pdf]
#130Earlier quoted context omitted.
Functional programming languages do not capture mutable state in closures.
So LISP and Caml aren't functional programming language nowadays ? Because both allow you to modify what's in a closure.