Better HN
topnewbestaskshowjobs
Log inSign up

likeclockwork

801 karma · joined Sep 24, 2012 (14y ago) · 595 submissions

Submissions

comment 8y ago · link · parent

> So how would you define OO? I get it your are in the camp that equal polymorphism to OO? And by the way, I do see it. Clojure/Script has object-based constructs. If you think of the more general sense for object, which is identity + attributes, records fit the bill. This is defined here https://en.wikipedia.org/wiki/Object_(computer_science)#Obje.... Now, I also agree with you, it even has a construct that groups data and behavior together in the form of deftype with mutable fields. So at this point, it has support for OOP.

> 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

I am not saying that traits/protocols/interfaces/typeclasses are necessary for OO, I am saying that they are sufficient.

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

> I'd say traits in Rust, typeclasses in Haskell and Scala imlicit views are the equivalent to Clojure/Script protocols. And similarly, those constructs by themself aren't OOP. I think a simple proof is that if they were, then all OOP languages would have them. But because there are OOP languages (the most popular ones at that) which don't have them, then it follows this construct is not fundamental to OOP.

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

Sure, they're immutable, but it's still very much OO. I've never heard of OO requiring mutable state.

comment 8y ago · link · parent

But a record defines implementations of the protocol methods. Would you say Traits in rust aren't an OO construct?

The data and methods are coupled in the record definition. The methods depend on having the records fields in scope.

comment 8y ago · link · parent

Records and protocols meet your definition of OOP exactly.

comment 8y ago · link · parent

Can you really call "fast but wrong/insecure" optimized?

comment 8y ago · link · parent

Thanks for answering. Is Eventual Consistency a necessary property of a CQRS/Event Sourcing architecture?

comment 8y ago · link · parent

I've never quite been able to get my head all the way around "Eventual Consistency". I don't understand how actions that could conflict or resources that could be contended are supposed to work? At some point, something has to say, given two actions A and B that are in conflict, the later action B must fail.

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

You're right on driver support vs application support. There also aren't a lot of new applications in this space. I've been looking for a note taking/diagramming app with both stylus and touch support that will function as "a better piece of paper" in terms of being able to rotate and zoom on an infinite canvas; put down variable lines, grids, and dot grids; easily select and move or resize content; and I've been pretty disappointed by the offerings.

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

I'd rather have more drugs in the country than people being invaded and subjected to these sorts of indignities out of hand.

comment 8y ago · link · parent

Post-it notes for notes that have a lifetime of a few hours or less. One of my notebooks for notes that have a longer lifetime, for math, for figuring things out, for diagrams. Org-mode for planning, documenting research, and structured note taking. Stylus on my phone or laptop for drawing diagrams by hand that I need to share with others. (Also this is the best way I've found to practice my penmanship without wasting paper for no reason.)

comment 8y ago · link · parent

I run Arch on an X1 Yoga (2nd Gen) Krita has good touchscreen and stylus support.

comment 8y ago · link · parent

You're telling me there's no difference between light and the absent of light barring our perception of them as though light isn't a physical phenomenon with measurable effects.

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 actually do, especially on my OLED laptop screen and phone. The backgrounds are often these dark but not black grays that just lower the contrast of the content for no reason. Chrome and Firefox have these reader modes that don't give a true black background, it's just so wasteful.

I still prefer those themes to black-on-light but I do not love them.

comment 8y ago · link · parent

I don't want a single photon of light that isn't carrying information to reach my eyes.

comment 8y ago · link · parent

It really doesn't (look like UI design from the 90s). There is definitely something retro about it but for the web it's definitely beyond 90s. The more I looked at it the more I liked it. I wouldn't use it on a project but I wouldn't harshly judge a site or app that used it.

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

> - No, you can’t do 2-3. If you have 2 apples, you can’t give 3

Well, how soon is too soon to teach children about debt?

comment 8y ago · link · parent

Aside from `as->` which mentioned by others, you can nest thread-last into thread-first if you need to and it behaves appropriately. (You can't go the other way for obvious reasons but it works when you introduce a collection.)

comment 8y ago · link · parent

That sounds like a light version of org-mode.

comment 8y ago · link · parent

When did the sneakernet become a foreign concept to hackers?

comment 8y ago · link · parent

> Let's see how this is false:

    <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

From your article:

> 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

Gladly.

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

Could you explain why you think the class-oriented interface is better than the data-oriented one?

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

From the second part:

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

That same service will eventually also replace Google Play Music, a rival music service Google has inexplicably operated at the same time it was trying to get YouTube Music off the ground.

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.

comment 8y ago · link · parent

Sounds bad. It's vague but it's not permissive. I'd be afraid they were changing overt rules for hidden rules.

comment 8y ago · link · parent

They'll have so much time free to work on waiting in the bread lines.
1
101112
20