News for hackers. Stuff that matters.
Re:Was object-oriented programming a failure? (2015) by delinka on Sunday March 12, 2017 @09:20AM (#13850526)
Why are there still those who think any advocate of OOP is an advocate of "OOP or Nothing! All things are Objects! All things are an instantiation of a class! All things must derive from a root class! etc."?

OOP is a tool. And generally a useful one. Every new programming paradigm at its inception was going to Save The World and make programming A Better Place. Turns out, every one if these paradigms is a tool with uses at various times.

So OOP might only be useful in a limited number of cases. I find it comfortable for categorizing functions: "Here's all the stuff you can do with a String" or "All windows behave like this..." And if your language is dynamic enough, you can add functionality to all Strings, not just your String subclass.

I don't typically find OOP useful for processing many records of data. Perhaps I might compose an object from a record of data so that a user might edit their profile in a GUI, but batch processing doesn't usually lend itself to OOP. But that's my experience and opinion; I bet someone has a good use case for using OOP while dealing with copious amounts of data.

Back to the topic at hand: Was OOP a failure? No more than lathes are failures. Not every handyman needs a lathe; not every programmer needs OOP. But when you do need it, it's a useful tool.

Re:Was object-oriented programming a failure? (2015) by thehardsphere on Sunday March 12, 2017 @10:04AM (#13850688)
> Why are there still those who think any advocate of OOP is an advocate of "OOP or Nothing! All things are Objects! All things are an instantiation of a class! All things must derive from a root class! etc."?

Because there are many low skill, poorly-informed people who write code still believe these things. In particular that "OOP" is automatically equivalent to "better quality code." It’s a sort of cargo cultism that is present in a few places.

Re:Was object-oriented programming a failure? (2015) by shadowmint on Sunday March 12, 2017 @12:04PM (#13851237)
The irony is that it probably does mean better quality code for most people.

Quality in practical outcomes for building projects, that is, not code asthetics.

The problem is that 'functional code' means 'spagetti code' for many 'low skill' people, and 'write once maintain never' perl style code for many other 'smart' people.

Both are rubbish, terrible low quality useless code outcomes.

OOP doesn't fix everything, but its a great lowest common demoninator for code that does the job. Its not exciting. It has stateful bugs. ...but anyone can do it and it gets the job done at scale; orders of magnitude better than any other coding paradigm I'm aware of.

You want a hard problem to solve?

Go figure out a way to make functional programming scale the same way, you'll start a revolution.

...but in my experience, its the frustrated 'smart' folk who want to write their maintain-never code who push FP as a replacement for OOP.

Re:Was object-oriented programming a failure? (2015) by Buttons840 on Sunday March 12, 2017 @01:17PM (#13851740)
> The problem is that 'functional code' means 'spagetti code' for many 'low skill' people

I don't see how that is the case. Even in the most poorly written function you have code that's working mostly on it's arguments (and maybe some global or something, since it is poorly written) and then returns a value. How is this function connected to the surrounding code? We know the answer, it's called in a single expression and given arguments. You have a single isolated call for a single run of the function.

In OOP you have to both instantiate a class and then call it's methods. By simple line count it is twice as complicated to call as a function, and it is twice as coupled to the code that calls it.

When I look into the internals of functional code I often find myself in a single isolated function and the functions tend to be on the short side. When I look into the internals of OOP code I often find myself in a large method that is part of a class in an inheritance hierarchy and the method uses a bunch of globals (err, I mean "object variables") and I have to read several other methods to understand what's happening, because the method I'm interested in depends on the state left over from other method calls.

In short, objects are a lot more powerful than functions, and thus "low skill" developers have a lot more rope to make spaghetti with.

Re:Was object-oriented programming a failure? (2015) by eveningcoffee on Sunday March 12, 2017 @06:41PM (#13853602)

  In OOP you have to both instantiate a class and then call 
  it's methods. By simple line count it is twice as 
  complicated to call as a function, and it is twice as 
  coupled to the code that calls it.
And in FP a state falls out of the sky?
Re:Was object-oriented programming a failure? (2015) by shadowmint on Monday March 13, 2017 @09:45AM (#13857745)
It's not about hidden state; that's just bad OOP. You shouldn't be looking at the internals, that's the point. It's about modular encapsulation and reusable components.

> a single isolated function and the functions tend to be on the short side

I can almost guarantee that code was not written by an inexperienced or low skill coder.

If it was, you'd have a large complex function that took large complex state as its input, and probably maintained some kind of hidden internal state in some kind of async deferred loop after it returned or some combination of the above.

Have you worked with inexperienced FP programmers?

It's not fun.

Inexperienced OOP is a lot easier to deal with, because the entity level API validation is all you care about; you don't care about how hideously the internals were implemented as long as the tests pass. There can be any number of bugs and spaghetti inside the object, but you don't care, because you don't see it (until it manifests as bugs; but then you just add more tests and make them go away until all the tests pass).

I think there's a pragmatic aspect to OOP that involves large scale organizations collaborating on projects that you're not taking into account.

You could argue that a test suite for FP does the same job, and maybe it does... but the point here is that someone has to define the module level interface, and how it behaves as a state machine (regardless of if the state comes in 'pure' and is passed around or is encapsulated internally); and that's OOP, not an inheritance hierarchy.

Re:Was object-oriented programming a failure? (2015) by rdnetto on Tuesday March 14, 2017 @07:20PM (#13872458)
> I can almost guarantee that code was not written by an inexperienced or low skill coder. > If it was, you'd have a large complex function that took large complex state as its input, and probably maintained some kind of hidden internal state in some kind of async deferred loop after it returned or some combination of the above. > Have you worked with inexperienced FP programmers? > It's not fun.

No pure FP language will allow you to do that without the function's type signature reflecting that - it would need to return its value in some kind of state/async monad.

Now, if you're talking about FP in a traditionally OOP language, then I agree with you, but that's an apples to oranges comparison.

> Inexperienced OOP is a lot easier to deal with, because the entity level API validation is all you care about; you don't care about how hideously the internals were implemented as long as the tests pass. There can be any number of bugs and spaghetti inside the object, but you don't care, because you don't see it (until it manifests as bugs; but then you just add more tests and make them go away until all the tests pass).

This approach doesn't work for things that are difficult to test. e.g. you can only ensure your types are thread safe by reasoning about their use of locks, volatile, etc., because any attempt to test this is dependent on the implementation details of your runtime (e.g. the JVM) and the amount of load its under. Best case you get a flaky test, worst case you miss a bug that blows up in production.

But this is a tangent, because TDD is not specific to OOP - it works just as well with FP.

> but the point here is that someone has to define the module level interface, and how it behaves as a state machine (regardless of if the state comes in 'pure' and is passed around or is encapsulated internally); and that's OOP, not an inheritance hierarchy.

Pure state is an oxymoron. The idea is not that you pass a mutable argument in, but that you don't have the ability to mutate data at all. At best, you can return some instructions on how to mutate (e.g. the state monad), but its the consumer of your code who decides what to do with that, which prevents you from hiding side-effects, and simplifies testing.

Defining a module level interface and behaviour is just API design, not OOP.

Re:Was object-oriented programming a failure? (2015) by aaron-lebo on Sunday March 12, 2017 @10:22AM (#13850769)
Indeed, but what is more disappointing are the high-skilled, well-informed people who believe these things. In particular that "functional" is automatically equivalent to "better quality code".

It's dogma either way. There is no single true religion just advantages and disadvantages

Re:Was object-oriented programming a failure? (2015) by notalaser on Sunday March 12, 2017 @12:14PM (#13851311)
> Because there are many low skill, poorly-informed people who write code still believe these things. In particular that "OOP" is automatically equivalent to "better quality code."

This about sums up my experience with these discussions, too. I know a lot of people who are absolutely convinced that C++ "is better" than C because you can write object-oriented code in it -- you have native support for "classes and stuff".

The whole "is better than" thing is a little childish to begin with, but this argument is on the thin and confusing border between "meaningless" and "but why?"

Re:Was object-oriented programming a failure? (2015) by naasking on Sunday March 12, 2017 @11:05AM (#13850956)
> So OOP might only be useful in a limited number of cases. I find it comfortable for categorizing functions: "Here's all the stuff you can do with a String" or "All windows behave like this..."

That's a module. This scope creep is part of the problem with OOP, as it slowly encompasses features that are orthogonal to their main purpose.

OOP is mainly about procedural abstraction: any type implementing a protocol (set of methods) should be indistinguishable from any other type that implements that same protocol. This enables the open extension that characterizes OOP.

So amending your statement to make it truly about objects, "here's all the stuff you can do with String-like values".

Re:Was object-oriented programming a failure? (2015) by eveningcoffee on Sunday March 12, 2017 @06:54PM (#13853713)
One of the core principles of the OOP is encapsulation - your object does not appear in inconsistent state to the outside world. So in sense of the OOP, object methods are all the functions that can have access to the internal state.

Naturally you can do the same in FP with modules, but honestly, how different it is from OOP then (considering that you can use some form of polymorphism)?

For me OOP and FP stand for abstract concepts, not as specific languages.

Re:Was object-oriented programming a failure? (2015) by naasking on Sunday March 12, 2017 @09:23PM (#13854512)
> One of the core principles of the OOP is encapsulation - your object does not appear in inconsistent state to the outside world.

This is not a defining feature of OOP, because it's a characteristic of abstract data types which predate OO. William Cook managed to distill the essence quite clearly I think [1].

[1] http://www.cs.utexas.edu/~wcook/Drafts/2009/essay.pdf

Re:Was object-oriented programming a failure? (2015) by gpderetta on Sunday March 12, 2017 @09:27AM (#13850554)
Exactly. "Everything is an object" was an extremism (today's extremism is the crusade against 'mutable state'), but otherwise OoO has been useful. For example it has seen great success in GUIs.
Re:Was object-oriented programming a failure? (2015) by marktangotango on Sunday March 12, 2017 @09:46AM (#13850627)
If you're creating final immutable everything in Java using effective Java chapter 1 immutable objects, sorry but you have the wrong language for the job. Even with Java 8 Optional and Lombok annotations, it opens a can of worms. What is optional and what are sensible defaults for non optional value? These are often non trivial questions in legacy code bases.
Re:Was object-oriented programming a failure? (2015) by eveningcoffee on Sunday March 12, 2017 @06:55PM (#13853724)
And yet Clojure immutable datatypes were written in Java.
Re:Was object-oriented programming a failure? (2015) by fpoling on Sunday March 12, 2017 @09:57AM (#13850663)
I can definitely state that OOP allows to implement GUI. But "great success" I can see only for vendors selling OOP tools for GUI development.

Consider web frameworks. Given a choice I select React and similar functional frameworks than OOP based ones. They are just more productive and scale better.

Or consider QT. My colleagues with a lot of QT experience use QML to create GUI. They avoid any C++ GUI code unless it is really a must.

Re:Was object-oriented programming a failure? (2015) by coldtea on Sunday March 12, 2017 @10:53AM (#13850908)
>Consider web frameworks. Given a choice I select React and similar functional frameworks than OOP based ones. They are just more productive and scale better.

That's because there are no decent OO based web UIs, because the web development experience and stack is a total mess to begin with.

Re:Was object-oriented programming a failure? (2015) by Pxtl on Sunday March 12, 2017 @11:12AM (#13850992)
The web UI objects, with their collection of global namespaces for IDs, Classes, JavaScript functions, etc., are aggressively resistant to compontentization.

You can see the disastrous implications of this feature with the ID mangling needed for Asp.net webforms, and the utterly miserable workflow that creates.

Re:Was object-oriented programming a failure? (2015) by braveo on Sunday March 12, 2017 @04:41PM (#13852973)
ASP.Net Web Controls was an attempt at bringing the desktop technologies like MFC to the web, and it was a horrible horrible idea.

The worst part is that everything else about the original ASP.Net was mostly really good ... but Web Controls completely destroyed it's reputation.

Re:Was object-oriented programming a failure? (2015) by ziotom78 on Sunday March 12, 2017 @03:37PM (#13852599)
Well, I used to bash C++ and OOP programming till not a long time ago, but I am slowly reconsidering my ideas.

I am now learning Rust, and for this purpose I am trying to implement a small TUI (Text User Interface) framework. In order to get some ideas, I dug in my library and found the Turbo Vision User's Manual that was bundled with Borland Pascal 7.0 [1]. Reading it after so many years made me wonder how could they create such a complex and well-thought framework that was truly usable for your own stuff, given the technology and knowledge available 30 years ago. The text often underlines that a lot of features were possible thanks to the OOP constructs implemented in Turbo Pascal, and I believe them. I think that OOP importance might have faded today, but its historical significance for the development of GUIs and TUIs should not be underestimated.

P.S. I am trying to implement my library in Rust, which is not an OOP language, and so far have found no blocking point: traits and containers are more than adequate replacements for the kind of polymorphism and inheritance used in libraries like Turbo Vision. But my point still stands: once we learned that polymorphism and inheritance were useful to solve some specific problems, we have derived better ways to achieve the same purpose.

[1] https://archive.org/details/bitsavers_borlandTurrogrammingGu...

Re:Was object-oriented programming a failure? (2015) by mmjaa on Monday March 13, 2017 @06:11AM (#13856525)
Ex-Turbo Vision user here .. I continue to be disappointed by modern GUI technologies, by comparison. Every time I pick up some React tutorial, it makes me sad as hell that we've come so far, and yet have to deal with such errant crap as React and the Web itself as a whole.

Its gotten so bad that I feel strongly about killing the browser-based ideology and just returning to native clients for everything .. I mean, its really not an easy decision to "do the whole GUI in Web", even though by now it should be. It just seems like such a mess by comparison with where we should be by now, given the work done decades ago ..

Re:Was object-oriented programming a failure? (2015) by watwut on Sunday March 12, 2017 @10:30AM (#13850804)
React itself does much less then what component oriented oop frameworks used to do. Achieving same functionality with react is more work. They were not on the Web tho, so the comparison is a bit weird.
Re:Was object-oriented programming a failure? (2015) by zzzzzzzza on Sunday March 12, 2017 @12:48PM (#13851548)
"achieving same functionality is more work" this is part of the advantage of react (and fp in general over oo). you don't need to incorporate an entire object to use a single extra function. The increased modularity also allows you to spread the maintenance burden of the project over a much larger community.
Re:Was object-oriented programming a failure? (2015) by charles-salvia on Sunday March 12, 2017 @11:26AM (#13851057)
People sometimes think that OOP means "OOP or Nothing!" probably because of the popularity of languages that enforce such a mentality (i.e. basically because Java).
Re:Was object-oriented programming a failure? (2015) by jt2190 on Sunday March 12, 2017 @11:55AM (#13851186)
> OOP is a tool. And generally a useful one.

OOP is also a tool that others have used to build things that many of us use all the time (I'm looking at you DOM API and CSS) so it's difficult to truly escape from OOP. You may never like it, but learning it will deepen your understanding of many other tools.

Re:Was object-oriented programming a failure? (2015) by erikpukinskis on Sunday March 12, 2017 @11:43AM (#13851147)
> Why are there still those who think any advocate of OOP is an advocate of "OOP or Nothing! All things are Objects!

Well, that's what the OP in OOP means. It means you are oriented towards objects, and away from everything else.

What's the difference between writing a test and doing TDD? In TDD the tests are the center of your universe.

Plus there's the fact that "Everything is an Object" was a very common slogan for OOP.

Of course you can write non-objects in your object oriented code... An object is made of non-objects! But OOP means when you are asking architecture questions you sort out your names and your methods first, and functions fill in the gaps.

Compare to (old school) JavaScript where everything is a function to start, and you add prototypes and methods only when you really need them. (RIP JavaScript, long live OOP/ES6)

Re:Was object-oriented programming a failure? (2015) by pjmlp on Sunday March 12, 2017 @01:46PM (#13851902)
Old school JavaScript was already OOP, given that prototype inheritance comes from Self, which was OOP.
Re:Was object-oriented programming a failure? (2015) by ljw1001 on Sunday March 12, 2017 @08:03PM (#13854102)
Because straw men make the best targets