801 karma · joined Sep 24, 2012 (14y ago) · 595 submissions
comment 8y ago · link · parent
> I know some people say polymorphism alone is the essence of OO. Thus Haskell, Rust, Clojure/Scipt, Go, PureScript, and others are all OO languages. I don't know though, I feel the average dev doesn't think of it that way.
I don't think that polymorphism alone is sufficient to be considered OO. I think it's important to recognize you can do OOP without much language support, people even do OOP in C. There's probably someone doing OOP in assembly somewhere.
> But, after this conversation, I wonder if I don't prefer the definition from the wiki link I shared. Where OOP is the combination of all three. A single construct which groups data and behavior, and allows polymorphism as well as inheritance. And this is what is known as an object, and all three must be present to be considered OOP. With this definition, I think Clojure/Script wouldn't fit as OOP. Since, and tell me otherwise, deftype doesn't support inheritance. And multi-methods don't group data and behavior.
Lets work with your definition..
You concede that all of those constructs group data and behavior, since they let you define a type's methods in a manner that has access to that type's internal implementation. You concede that they allow polymorphism because you can substitute any type that implements the trait/protocol/interface/typeclass. I don't think subclass inheritance is necessary to OO because it's there as a means of expressing type polymorphism and in the class-bases languages it was for the longest time the only way of expressing type polymorphism. So.. what's the difference between participating in an interface/trait/protocol and inheriting from an abstract class? I don't particularly think there is any (some of these languages even have default implementations, including Haskell), you get subtype polymorphism from either.. so in my view the inheritance requirement is met even without a full-blown class hierarchy or deep prototype chain.
> Those methods are no longer trait like, they're full blown object methods, with special privileges, and tight coupling to the mutable data fields. They can not be defined separately to the type, and a type can not be extended outside its definition to support such methods.
All of the other constructs work the same way, even typeclasses in Haskell. Trait implementations in Rust can have privileged access to private fields. I assume it's the same with Go interfaces. And in Haskell you can't destructure or even construct a type if you don't have access to its constructor--so if you don't export the constructor from your module.. all your fields are private. But you can export a function that constructs the type. You can export the typeclasses. You can export accessors for public fields, and functions to return a modified version of the instance and so forth.
> I know some people say polymorphism alone is the essence of OO. Thus Haskell, Rust, Clojure/Script, Go, PureScript, and others are all OO languages. I don't know though, I feel the average dev doesn't think of it that way.
Well, they're not all OO languages. They all do have language level support for all of the concepts that OOP is made of and you can use them to do Object-Oriented Programming even though some of them are clearly Functional Programming languages. OOP means classes and nothing else in the mind of the average dev. In my opinion it's really just a pattern that you can apply/implement anywhere with more or less support from the language and in sufficiently flexible languages you can even build your own object system and it might even be nice to use. Supporting OOP doesn't make a Functional language not-Functional, or even a multi-paradigm language. No one would call Haskell a multi-paradigm language, yet it has language level support for OOP. Classes and FP don't really mix, but OO in FP works and doesn't have to compromise the FP paradigm. OO isn't something you need to dedicate an entire language to in order to use or benefit from.
comment 8y ago · link · parent
The object-like construct in Clojure is an instance of a record or a type that implements a protocol. (A deftyped type can even contain mutable fields!) It doesn't matter where the methods live, they apply only to objects that implement the protocol. That's behavior and data bundled together. As far as I am concerned that is an object. A trait is just a different expression of an object from an instance of a class. The interface being defined separately changes nothing; interfaces/traits/typeclasses offer different advantages than subtype polymorphism and inheritance hierarchies.
Would you say CLOS isn't OO?
A trait isn't an object and neither is a class. An instance of a data type that implements a trait is as much an object as an instance of a class.
Rust, Haskell, and Clojure don't advertise support for OOP because in the common taxonomy an object is defined as "an instance of a class".
> Clojure/Script records don't have their methods following them around. You can define the functions for the protocol in another namespace, and then you have to require them separately. They don't tag along with the record.
> Again, the call is made to the protocol functions. Simply importing the record does not make these functions exist within your namespace, you need to require them. And these functions are not scoped within the record. They don't see the fields, they need to access them through the record, like any other function would. Nothing is special about these functions. They're just functions that know how to do something to a concrete datatype.
1. Nothing is special about methods in "OOP" languages either, aside from the dot operator and implicit this. There are object systems that have neither.
2. You have made a factual error here. An implemention of a protocol on a record or a deftyped type(is there a proper non-generic name for this?) DOES have implicit access to the fields of the record or type.
(defprotocol Container
(inventory [this])
(add [this thing]))
(defrecord Box [contents]
Container
(inventory [this] contents)
(add [this thing]
(update this :contents conj thing)))
boot.user=> (-> (->Box [1 2 3])
(add 4)
(inventory))
;; => [1 2 3 4]
The protocol method clearly has access to the contents field of the record, scoped by the record definition. The 'this' argument is a convenience to allow reconstituting the immutable object for return. You could just as easily have been forced to call the constructor again in order to reconstitute the object. If the record contained an atom it would happily carry around mutable state and there'd be no need to reconstitute anything.Building on my previous example:
(deftype MutableBox [^{:volatile-mutable true} contents]
Container
(inventory [this] contents)
(add [this thing]
(set! contents (conj contents thing))))
boot.user=> (let [b (->MutableBox [1 2 3])]
(add b 4)
(inventory b))
;; => [1 2 3 4]
A type with mutable state, its fields in scope. This isn't even used.You're correct that the call IS made to the protocol method. And yes, not having the protocol in scope prevents from calling the object's methods. One might even say that methods you don't know about and thus can't refer to are encapsulated. It's an extremely flexible object system--one that eschews mutable state and works well with a functional style and prefix syntax--but it's still an object system.
Object isn't a keyword in any of the languages we've mentioned. But we know how to find them and what they are. I don't understand why you can't see this one.
comment 8y ago · link · parent
This seems completely circular to me. Your definition of OOP is really "whatever all OOP languages do"?
> I'm not sure I'm explaining myself very well. Think of an object. The object defines some data fields. And it defines some methods together. You can't use those methods with other objects. The ownership is tied to the object that defined them.
In Clojure you can't use a protocol method on a type that doesn't implement that protocol. I don't see it as being that different from D's Uniform Function Call Syntax (a free function can be called as a method of its first argument and vice versa.)
What is OO to you? Is it Class Oriented Programming? Is it a programming paradigm or is it the list of features and practices common to a family of languages? Almost no common OO languages treat method calls as messages. It's just a function call with a (usually) hidden 'this' parameter. Applying a protocol function to a record that implements it isn't really any different, from a perspective of message passing. A message is passed to the record and based on its pedigree it decides how to respond.
Plenty of OO languages don't have private data and allow direct access to object fields. Arguably, by your definition, it isn't OO at all to even provide for public fields. As long as the methods follow the data around or vice versa, in my view, encapsulation has been achieved. Enforcement is another concern, but it's not Jail Oriented Programming so I don't see that enforced encapsulation is a necessary condition for OO.
A record implementing a protocol can receive method calls. All of its method implementations happen with the records own fields in scope (assuming you define them in the defrecord). It doesn't need to restrict access, if you'd like it to have private data.. respect its privacy and don't look.
As I understand it, the state of the art in Class-Oriented Programming has been to define interfaces for everything, and then define classes that implement those interfaces, and then use the interface to type functions and methods. A Trait in Rust or a Protocol in Clojure just knocks out the middle man, the unnecessary and unwanted class. What's left is still OO, you can get rid of the class and all of it's baggage and still have plenty of OO left.
> A record is a set of key/value pairs with an associated type. A Person record defines a type Person, with keys Age and Weight and their values. That's all a record does. It can't restrict access to its data, it can't expose methods, and it can't receive messages (method calls). You can now write functions that take input of this new type. Those functions can be defined anywhere. They have no special access to the data inside Person, there's no `this` or `self`. The functions don't live inside the datatype. Now, if you want a common set of functions to work over many different types, you can specify a protocol. That's all a protocol does. This is just functional programming.
This, to me, is a description of object-oriented programming without the class ceremony. It's also functional programming. The use of records and protocols is functional programming, but the constructs themselves have OO nature. I don't think functional programming and object oriented programming are in opposition to each other. I think functional programming and mutable state heavy/class-happy programming don't mix but the latter is not my definition of OO.
comment 8y ago · link · parent
So, where does that happen? When getting written into the read model? Then what, it emits an event saying clearly that the previous action failed? All while there's a client waiting for results?
I'd love to see a worked example based on discrete resources. Such as two people, a box, and a ball; where the ball can be held by either person or in the box, and a person can take the ball from the box but not from another person.
I find the concept intriguing but I don't really get it and I haven't been able to identify in any of the writing where "the buck stops".
comment 8y ago · link · parent
I think the use case is a little esoteric in our community, I've been seriously thinking about trying my hand at creating an application to address my needs when I get some downtime from my contract work.
comment 8y ago · link · parent
comment 8y ago · link · parent
For an inverted color scheme (light information on a black background) on a display where black pixels don't emit light-- the only emissions your eyes have to take in are information.
Your digital logic analogy is sanitized. If the high logic level is at 10kV your equipment is going to have a hard time.
We're talking about staring into a light source, there's a difference in total energy your eyes have to absorb.
Maybe your argument is self-evident to any theorist, but it completely ignores the physical world.
I'd also add that when reading with reflected light (such as reading on paper), your eyes are going to be taking in the same amount of light regardless of where they look in your environment because you're just reading ambient light. Completely different than staring into a light source.
Try programming while looking through an LCD directly at the sun and have it display characters by darkening pixels of direct sunlight aimed at your retinae then tell me there's no difference between a lit pixel and a dark pixel.
Hey, there's no difference between a one bit and a zero bit, here's a great computer interface idea: Transmit binary data to the user with gamma rays. The only difference is in how their far from perfect human body experiences them.
comment 8y ago · link · parent
I still prefer those themes to black-on-light but I do not love them.
comment 8y ago · link · parent
I think a palette shift would completely remove the retro aesthetic. They should probably do that if they want people to seriously consider using it.
comment 8y ago · link · parent
<label @click="edit(todo)">
> This is not Javascript. If it was, it would assign the result of the function call to @click. It doesn't. It's a Javascript-like scripting language that has magical binding into regular Javascript.You're wrong. The contents of the event handler is JS, the whole snippet is obviously HTML.
<button onclick="alert('Hi')">Say Hi.</button>
This is also plain regular HTML and has been since HTML4 (1997). The value of the onclick attribute is a string of JS. There's no assignment of the result happening. It registers a click handler. The only difference between the two, on a surface level, is that the Vue example has things in scope (edit and todo) that aren't globals.comment 8y ago · link · parent
> My point here is not about using classes or not, but that Vue is using arbitrary object structures instead of language features.
Which language features do you think they should be used that they aren't being used now? Your class example doesn't express the same things that Vue's object structure can.
Object literals are an important, useful, and universal feature of JS. Class syntax doesn't really replace them.
I'd really like to know what your alternative is.
comment 8y ago · link · parent
With the data interface you can reuse or generate part or all of a component definition.
A class declaration can only contain methods. The data object contains much more information.
You could say both are descriptions that will be used to build an object, but the Vue API data object will be interpreted arbitrarily by Vue's runtime while the class declaration will be interpreted by the JS runtime and will only expose methods.
You could use decorators or put properties on the class's constructor, but that has to happen outside of the scope of the class declaration and negates any cleanliness advantage.
You can also put those properties in the constructor but then they are only available after instantiation.
Here's a discussion on class syntax in Vue: https://github.com/vuejs/vue/issues/2371
I think that there's a temptation for class-oriented programmers to want to write everything as classes, but there's nothing inherently superior about using classes in your api and depending on the use case classes may actually be limiting.
comment 8y ago · link · parent
Personally, I don't see it. The class-oriented one is more official looking, but classes almost require instantiation and introspection to be understood at runtime.
Can JS classes even be generated at runtime? I'm sure they can, if you desugar them, but the class syntax isn't composable.
comment 8y ago · link · parent
https://cdn-images-1.medium.com/max/1600/1*EXYbO_qnV2m8fv4mB...
> Adjusting the volume in KDE Plasma — why is there more than one slider for playback? Hardly intuitive
Because there are multiple outputs and you can assign a source to whichever outputs you want. Why shouldn't the controls reflect the actual capabilities of the device?
The next step is saying that the device is too capable and needs capabilities removed to make it easier to understand. No thank you.
comment 8y ago · link · parent
They got me again. I can't believe I let them get me again. I was subscribed to Play Music, then Youtube Red appears and okay, I get that in addition, now they're closing Play Music and forcing me into Youtube?
These motherfuckers.