Live data from Hacker News

Write More Classes

lucumr.pocoo.org

121–130 of 150 posts

Re: Write More Classes

#122

Earlier quoted context omitted.

I'm not aware of Joe Armstrong having extensive OO experience - either as a programmer or a language designer. Could you fill me in? Perhaps the picture I have is completely wrong. Erlang is from 1986. Did he gather extensive OO experience before? In Smalltalk? Or on the side while developing Erlang?

According to a message he posted[0] on the erlang-questions mailing list, since 1967 he has written in Fortran, Lisp, Prolog, Smalltalk , Erlang, C, C++ , Java , Python , Ruby , Lua , Javascript , Haskell, ML and OCaml. I italicised all the object-oriented ones. Saying that Joe Armstrong doesn't have "extensive OO experience" is pretty comical! [0] http://erlang.org/pipermail/erlang-questions/2013-January/07...

OCaml, as the name ("Objective Caml") implies, also supports object-oriented programming. It actually has a pretty clever implementation of it as well. That said, many people tend to stick to the functional bits of OCaml and don't venture out into the OOP bits very often.

Re: Write More Classes

#123
post #92
post #65

Earlier quoted context omitted.

From http://www.infoq.com/interviews/johnson-armstrong-oop " Is Erlang object oriented? Joe Armstrong: Smalltalk got a lot of the things right. So if your question is about what I think about object oriented programming, I sort of changed my mind over that. I wrote a an article, a blog thing, years ago - Why object oriented programming is silly. I mainly wanted to provoke people with it. They had a quite interesting…

I always asked myself why Alan Kay didn't name it "message oriented" then.

The answer to this question is supposed to be in "The Early History of Smalkalk", though I haven't re-read it.

Anyway, I just asked on the Fonc mailing list, and got an incredibly detailed answer from Alan Kay himself. To sum it up, someone asked him what he was doing, and he didn't quite have a name for that yet. Heck, he was at the stage of narrowing it down mathematically. So he just answered "object oriented programming", because it fitted with the vocabulary of the time, and went back to work.

He did later regretted this label.

Now, it's not even sure a better terminology would have helped much. Alan Kay reckons that "it might have helped to have better terminology", but it would probably have been hijacked too:

> The success of the ideas made what we were doing popular, and people wanted to be a part of it. This led to using the term "object oriented" as a designer jeans label for pretty much anything (there was even an "object-oriented" COBOL!). This appropriation of labels without content is a typical pop culture "fantasy football" syndrome.

Re: Write More Classes

#124
post #99

Earlier quoted context omitted.

> Where is the trend to forcefully avoid classes here coming from? See the "Stop Writing Classes" video. Classes hold state. More state adds more complexity, and typical OO design add lots of layers of indirection which also add complexity. Most of the time, you don't need the flexibility that the extra indirection gives you. So you get complexity for little benefit. If you don't need to hold state, then a collection…

> Classes hold state. More state adds more complexity, and typical OO design add lots of layers of indirection which also add complexity. Most of the time, you don't need the flexibility that the extra indirection gives you. So you get complexity for little benefit. Functions hold state as well, they just encapsulate it. You can still break up your algorithm into a class with multiple template methods and then encaps…

> You can still break up your algorithm into a class with multiple template methods

Template methods are an abomination. They are only widely used because many OO languages don't have first-class functions. A template method means that the method is being parameterized by one or more functions. Parameters should be expressed as parameters! You wouldn't design a Circle class so that you need to subclass it to specify the radius of the circle. The radius is a parameter. Likewise for the callback functions used by a template method. Template methods are intrinsically difficult to understand and spaghetti-like, unless well-documented, because it is not immediately clear what the parameters to it are. And when overriding a callback method, it's not immediately clear what template method the overridden method is paramaterizing. Or that it is even parameterizing anything. (Caveat: Sometimes template methods are warranted, but they are greatly overused.)

> Classes have another advantage: virtual method calls.

You don't need virtual method calls in order to parameterize functionality. See previous paragraph. Furthermore, it is not safe to override a method without knowing if it has been designed for overriding, and what the class expects of the overriding method. See Effective Java, "Item 17: Design and document for inheritance or else prohibit it". Also see "Item 16: Favor composition over inheritance", and a similar discussion in the Gang of Four book.

> If one function in a module calls into another function in the module I can only do two things: a) copy/paste the library and change one of the functions or b) a monkeypatch which modifies a shared resource someone else might want to use with the old semantics.

If a method is not designed to be overridden, you shouldn't override it anyway. (See previous paragraph.) When using a functional approach (in a language with first-class functions), you can usually design for flexibility just as easily or more easily than when using an inheritance-based OO approach for flexibility.

Re: Write More Classes

#125

Earlier quoted context omitted.

According to a message he posted[0] on the erlang-questions mailing list, since 1967 he has written in Fortran, Lisp, Prolog, Smalltalk , Erlang, C, C++ , Java , Python , Ruby , Lua , Javascript , Haskell, ML and OCaml. I italicised all the object-oriented ones. Saying that Joe Armstrong doesn't have "extensive OO experience" is pretty comical! [0] http://erlang.org/pipermail/erlang-questions/2013-January/07...

OCaml, as the name ("Objective Caml") implies, also supports object-oriented programming. It actually has a pretty clever implementation of it as well. That said, many people tend to stick to the functional bits of OCaml and don't venture out into the OOP bits very often.

I thought about italicising OCaml as well, but I'd hesitate to call it an object-oriented language. It's more like a functional language that happens to have an object system.

Likewise Common Lisp has an object system (CLOS) but I wouldn't call it an object-oriented language.

Re: Write More Classes

#126

Earlier quoted context omitted.

> It seems to me that the writer has little experience of not using classes, so wants to solve every problem he has with a class. That's a bold statement. Where is the trend to forcefully avoid classes here coming from? Classes are a perfectly valid tool in Python to solve problems. Someone sent me a mail this morning proposing a dictionary with callback functions in addition to a function as if that would solve anyt…

The question is, what classes do that module systems don't? The answer is generally inheritance, and through it, class polymorphism. With first class function, you hardly need class polymorphism. Just pass the function as argument already, don't bother with writing a whole new class just to override one method. The other use for inheritance is plain code reuse. This is bad most of the time because it promotes thick i…

> With first class function, you hardly need class polymorphism. Just pass the function as argument already, don't bother with writing a whole new class just to override one method.

Here, here! After returning to functional programming after a 30 year hiatus, I am beginning to realize just how detrimental the OO orthodoxy has been, and just how impoverished the world has been without first class functions. If only Scheme had caught on in the mainstream when it was invented, the programming world would be a much happier and safer place.

Re: Write More Classes

#127

Earlier quoted context omitted.

The question is, what classes do that module systems don't? The answer is generally inheritance, and through it, class polymorphism. With first class function, you hardly need class polymorphism. Just pass the function as argument already, don't bother with writing a whole new class just to override one method. The other use for inheritance is plain code reuse. This is bad most of the time because it promotes thick i…

> With first class function, you hardly need class polymorphism. Just pass the function as argument already, don't bother with writing a whole new class just to override one method. Here, here! After returning to functional programming after a 30 year hiatus, I am beginning to realize just how detrimental the OO orthodoxy has been, and just how impoverished the world has been without first class functions. If only Sc…

> Here, here!

Where, where? ITYM "Hear! Hear!"

http://en.wikipedia.org/wiki/Hear,_hear

"Hear, hear is an expression used as a short, repeated form of hear him, hear him. It represents a listener's agreement with the point being made by a speaker."

Re: Write More Classes

#128

Earlier quoted context omitted.

> Classes hold state. More state adds more complexity, and typical OO design add lots of layers of indirection which also add complexity. Most of the time, you don't need the flexibility that the extra indirection gives you. So you get complexity for little benefit. Functions hold state as well, they just encapsulate it. You can still break up your algorithm into a class with multiple template methods and then encaps…

> You can still break up your algorithm into a class with multiple template methods Template methods are an abomination. They are only widely used because many OO languages don't have first-class functions. A template method means that the method is being parameterized by one or more functions. Parameters should be expressed as parameters ! You wouldn't design a Circle class so that you need to subclass it to specify…

> Furthermore, it is not safe to override a method without knowing if it has been designed for overriding, and what the class expects of the overriding method.

This is true, but likewise, its not safe to parameterize functionality by passing callbacks unless you know what the function you are passing the callback to expects of callback functions (in terms of arguments, return values, and side effects.)

Both of these, really, are the same principle: its not safe to call code without knowing what the code expects of you when calling it.

Re: Write More Classes

#129
post #127

Earlier quoted context omitted.

> With first class function, you hardly need class polymorphism. Just pass the function as argument already, don't bother with writing a whole new class just to override one method. Here, here! After returning to functional programming after a 30 year hiatus, I am beginning to realize just how detrimental the OO orthodoxy has been, and just how impoverished the world has been without first class functions. If only Sc…

> Here, here! Where, where? ITYM "Hear! Hear!" http://en.wikipedia.org/wiki/Hear,_hear "Hear, hear is an expression used as a short, repeated form of hear him, hear him. It represents a listener's agreement with the point being made by a speaker."

Yes, I know, but it's not nice to mess with the lysdexics.

Re: Write More Classes

#130
post #92
post #65

Earlier quoted context omitted.

From http://www.infoq.com/interviews/johnson-armstrong-oop " Is Erlang object oriented? Joe Armstrong: Smalltalk got a lot of the things right. So if your question is about what I think about object oriented programming, I sort of changed my mind over that. I wrote a an article, a blog thing, years ago - Why object oriented programming is silly. I mainly wanted to provoke people with it. They had a quite interesting…

I always asked myself why Alan Kay didn't name it "message oriented" then.

Because "communicating with messages" is one of the important features of objects, but objects are the focus.

The confusion, I think, mostly came about because in the late 1980s early 1990s, an explosion of "Object-oriented" programming happend by gluing classes into existing popular structured programming languages -- producing ObjectPascal and C++ which became the popular "OO" languages which became what "OO" meant to lots of people (Objective-C was a contemporary, and despite being C-based like C++ was more like Kay's idea of OO than C++, but didn't become popular until later.)

So what became popularly conflated with "object oriented" programming was statically-typed, class-oriented programming typified by C++ and similar languages (e.g., Java.)

There are certainly ways (often not the same ways between languages) in which newer languages -- Erlang, Python/Ruby, etc. -- are more "object oriented" than Java/C++-style languages.

Post reply on HN