Live data from Hacker News

Why OO Sucks by Joe Armstrong (2000)

cs.otago.ac.nz

21–30 of 396 posts

Re: Why OO Sucks by Joe Armstrong (2000)

#21

I'm really sick of these 'why blah sucks' posts. Clearly OOP works for a lot of people. If it doesn't work for you, don't use it. My personal feeling is that FP works better when the problem domain is more data oriented, requiring transformation of data streams whereas OOP is good when the problem domain is about simulating or modeling where you want to think about interacting agents of some kind. The whole 'X is one…

> If it doesn't work for you, don't use it.

How many of us actually get a choice in this...?

Re: Why OO Sucks by Joe Armstrong (2000)

#22
post #6

The thing is ‘filename’ is a bad example for a an object. Of course, it should be a string. However ‘File’ object is a better example that favors OOP. When you call ‘.read’ on a file object, you expect its content. It doesn’t matter if it’s a windows file, unix file, an IO string, or a web resource. When you call ‘.read’, it just work. Whereas in the functional world, you’ll have to 4 different ‘.read’ function calls…

> Whereas in the functional world, you’ll have to 4 different ‘.read’ function calls with an if statement.

A good language for functional programming provides parametric polymorphism via traits or typeclasses:

    pub trait Read {
      fn read(&mut self, buf: &mut [u8]) -> io::Result;
    }
    impl Read for std::fs::File { /* ... */ }
    impl Read for String { /* ... */ }
Then you can write a generic function like this:

    pub fn read_kilobyte(r: R) -> io::Result>
        where R: std::io::Read {
      let mut buf = vec![0u8; 1024]; // vector of 1024 0s
      let nbytes = r.read(&mut buf[..])?;
      buf.truncate(nbytes);
      Ok(buf)
    }
And call it like this:

    let kb1 = read_kilobyte(File::open(...)?)?;
    let kb2 = read_kilobyte("foo bar baz quux".to_string())?;
No ifs in sight.

Re: Why OO Sucks by Joe Armstrong (2000)

#23
I don't mind object oriented programming too much: Occasionally, at most a small fraction of the time, it helps me write good code, and then I use it. Otherwise I don't.

Here are some of the things I'd like to see in programming languages:

(1) Some semantics that admit some useful static analysis, that is, tell me some useful things about my code, e.g., for a variable, where does it get used and where might it get changed?

(2) Offer me some useful code transformation properties. For this, a start is the relatively powerful scope of names constructs in PL/I: There can just drop into the source code another function and know that in the more common and important respects that function being there won't hurt anything else already there. So, if I have some function I like for something or other, then I can just drop it in.

There's a lot more: The main point is just to try, so that given 100,000 lines of typing of code, some tools can tell me where the lines of spaghetti and the meatballs are!!!!

So, that code is a system and treat it as such, i.e., instrument the thing and tell me what is going on, both statically before it runs and as it runs.

Re: Why OO Sucks by Joe Armstrong (2000)

#24
post #21

I'm really sick of these 'why blah sucks' posts. Clearly OOP works for a lot of people. If it doesn't work for you, don't use it. My personal feeling is that FP works better when the problem domain is more data oriented, requiring transformation of data streams whereas OOP is good when the problem domain is about simulating or modeling where you want to think about interacting agents of some kind. The whole 'X is one…

> If it doesn't work for you, don't use it. How many of us actually get a choice in this...?

Also, for how many does it really work?

I mean, most devs don't really know anything else, just accept it and try to get by...

Re: Why OO Sucks by Joe Armstrong (2000)

#25
post #6

The thing is ‘filename’ is a bad example for a an object. Of course, it should be a string. However ‘File’ object is a better example that favors OOP. When you call ‘.read’ on a file object, you expect its content. It doesn’t matter if it’s a windows file, unix file, an IO string, or a web resource. When you call ‘.read’, it just work. Whereas in the functional world, you’ll have to 4 different ‘.read’ function calls…

> Whereas in the functional world, you’ll have to 4 different ‘.read’ function calls with an if statement. A good language for functional programming provides parametric polymorphism via traits or typeclasses: pub trait Read { fn read(&mut self, buf: &mut [u8]) -> io::Result ; } impl Read for std::fs::File { /* ... */ } impl Read for String { /* ... */ } Then you can write a generic function like this: pub fn read_ki…

That looks an awful lot like OOP to me...

Re: Why OO Sucks by Joe Armstrong (2000)

#27
post #13

Earlier quoted context omitted.

You getting downvoted for this completely inoffensive (at worst) comment is pretty sad I swear C++ gets a bad rap because most people have only seen a gross mixture of C++98 and C in their codebases A fully modern C++11 codebase is a beautiful thing

Why are you so sure the downvotes are not coming from the opinion of the "ridiculously pedantic OO of Java"?

Maybe because no body had commented as such until now? I am rather practical about this: I don't really like Java because it forces things that make more sense as functions to be under an object. What if I just want a simple global utility function, and don't want to make every single class inherit from a class containing only that? It's a lot of unnecessary hassle for something like that. I'm not saying OO is bad, I said it was too pedantic. I like languages which allow you to do what makes sense.

Re: Why OO Sucks by Joe Armstrong (2000)

#28

Earlier quoted context omitted.

> Whereas in the functional world, you’ll have to 4 different ‘.read’ function calls with an if statement. A good language for functional programming provides parametric polymorphism via traits or typeclasses: pub trait Read { fn read(&mut self, buf: &mut [u8]) -> io::Result ; } impl Read for std::fs::File { /* ... */ } impl Read for String { /* ... */ } Then you can write a generic function like this: pub fn read_ki…

That looks an awful lot like OOP to me...

One of the many difference is that there is no inheritance, and implementations of traits can be added for types long after they are defined. Traits in rust are not like java interfaces.

Re: Why OO Sucks by Joe Armstrong (2000)

#29

Earlier quoted context omitted.

You getting downvoted for this completely inoffensive (at worst) comment is pretty sad I swear C++ gets a bad rap because most people have only seen a gross mixture of C++98 and C in their codebases A fully modern C++11 codebase is a beautiful thing

> A fully modern C++11 codebase is a beautiful thing Can you point to an example of such? It would be nice as someone who’s been away from C++ for a long time.

https://github.com/rigtorp/awesome-modern-cpp

Re: Why OO Sucks by Joe Armstrong (2000)

#30
> Objection 1. Data structure and functions should not be bound together

I don't understand the above:

a. functions do things,

b. objects don't do things,

therefore, we shouldn't combine them together?

Why? I'm not convinced? what's the logic? doesn't seem to be a strong argument to me.

factories make things.

warehouses don't make things.

so we should build them together?

Post reply on HN