News for hackers. Stuff that matters.
Re:Why Are So Many Developers Hating on Object-Oriented Prog... by jehna1 on Friday August 23, 2019 @03:44PM (#20781803)
Have you seen bad OOP code? It's an unreadable mess of ObjectManagerFactory classes where everyone mutates everything.

Have you seen bad functional code? It's an unreadable mess of monads, flatmaps and partial composition where you're not really sure how many arguments a curried function is whitholding.

Have you seen bad procedural code? It's an unreadable mess of nested if-else statements where you're not really sure what state the world is in.

There are no silver bullets, only different solutions to different problems

Re:Why Are So Many Developers Hating on Object-Oriented Prog... by tolmasky on Friday August 23, 2019 @05:30PM (#20782806)
I feel that it is in fact possible to learn from history, and what humans tend to be good at and bad at, and derive useful directions for the future. "Use the right tool for the job" and "no silver bullets" are certainly tautologically correct, but they seem to miss the point of these discussions: we have a choice in what paradigms we teach, what frameworks we write, and what tools we use. How do we choose the right tool? These platitudes often have the (unintended?) consequence of effectively serving as veiled gate-keeping: "silly novice, you thought learning X was sufficient? No no, you must learn all the possible paradigms, and at some point you will become aware of which one to precisely apply for any given problem. Me merely telling you the solution would be cheating!"

Practically speaking, in my opinion, beginning teaching programming with an OOP approach can be detrimental to students. When I see students work in procedural (not even functional!) environments, they seem to piece together "the puzzle" of the programming task, whereas in OOP environments they often seem to devolve into strange taxonomical metaphysical questions "Is a Car a Vehicle? Or does it implement Drivable? Is a Window a Widget itself, or does it only own Widgets? If it's a Widget itself, then could a Window contain sub-windows?" So at least for the very constrained question of introductory languages and techniques, I think there is nothing wrong with specifically calling out certain approaches, vs. vaguely attesting to the truism that you can write bad code in any language. This feels similar to when people discover the concept of Turing Complete, and thus conclude all languages must thus be equivalent and any programming language discussion is thus moot. No. If that were the case, we should have never bothered going past assembly.

Re:Why Are So Many Developers Hating on Object-Oriented Prog... by csande17 on Friday August 23, 2019 @10:32PM (#20784821)
> How do we choose the right tool?

A good rule of thumb is that your code should be as close as possible to a plain-English description of what you want the code to do.

So if you're trying to write a program like "When you click the button, it turns grey, and then sends the message, and then turns blue when the message is done being sent", imperative programming is probably your best bet. If you're writing "find all the posts that contain the word 'donut'", something like SQL or functional programming is probably a good fit. You can usually tell when you made the wrong choice when you end up needing to think really hard about how to fit the behavior you want into your paradigm, or when you have to write a big long comment saying, "This isn't very clear from the code, but here's what it's trying to do..."

And as GP says, there isn't any one paradigm that's good for everything, so well-written programs will often use a mix of them. If someone tries to tell you that one size fits all (all programs should be imperative C! all programs should be object-oriented Enterprise Java Beans! all programs should be functional TypeScript!), that's usually because they aren't a very good programmer.

Re:Why Are So Many Developers Hating on Object-Oriented Prog... by jplayer01 on Saturday August 24, 2019 @05:02AM (#20786089)
Except there's no book or course or whatever that can teach somebody these things. Instead, everybody has to figure it out on their own, and usually they just don't. Engineering disciplines don't work this way. I don't understand why it's okay for software development.
Re:Why Are So Many Developers Hating on Object-Oriented Prog... by csande17 on Saturday August 24, 2019 @02:06PM (#20788660)
University curricula often try to expose students to a wide variety of programming paradigms. I'm not sure how you could walk out of Berkeley's CS 61 series thinking that there's One True Way to write all programs, for example.
Re:Why Are So Many Developers Hating on Object-Oriented Prog... by fanf2 on Saturday August 24, 2019 @09:21AM (#20786966)
There are books and courses that try, eg https://www.info.ucl.ac.be/~pvr/book.html
Re:Why Are So Many Developers Hating on Object-Oriented Prog... by jplayer01 on Monday August 26, 2019 @04:53AM (#20798304)
This looks great, thanks. Definitely gonna give it a read.
Re:Why Are So Many Developers Hating on Object-Oriented Prog... by locoman88 on Saturday August 24, 2019 @07:27AM (#20786553)
Very well put, that's why I cringe every time a fellow soft dev considers himself an engineer
Re:Why Are So Many Developers Hating on Object-Oriented Prog... by brlewis on Friday August 23, 2019 @05:59PM (#20783106)
> How do we choose the right tool?

We choose the right tool the same way a painter chooses among oil paint, watercolor, etc. Step back and look at the subject, and think how well each type of paint would represent it. Also consider one's own skill with each type of paint, one's interest in exploring new paints, and the cost of obtaining and storing another kind of paint.

Re:Why Are So Many Developers Hating on Object-Oriented Prog... by tolmasky on Friday August 23, 2019 @06:08PM (#20783170)
Right -- this is exactly the kind of language that turns people off. It is a vague analogy with no practical advice that compares the act of programming to the art of a skilled painter, giving a field that strives to have the restraint and responsibility of engineering a sort of weird "you have to hear the music" feel.

I want to make clear that I do not necessarily disagree with your assessment, but understand that there are people who are deciding whether to pick up an FP book or OOP book. They have to start somewhere, and this "wholistic" advice isn't tremendous help. Similarly, as an industry, it's hard to translate what you just wrote into the next UI framework. I think we can agree that we feel comfortable enough with loops to not take a completely neutral stance on the "loops vs. lngjmp opcode" debate? If someone asks you whether they should uses gotos everywhere it isn't strictly necessary to say "depends on the problem!" given that they probably aren't writing assembly-level filters for Adobe Photoshop where using a goto might actually make a difference -- since they probably wouldn't be asking in that case?

This isn't even an "all things being equal" situation. We are actively encouraging OOP to entry-level programmers today -- it is fair to ask whether that is the right move, because doing nothing is actually just choosing that OOP should be the default. It is totally fine to say "maybe OOP has not delivered on its promises, and while there may be useful lessons here, I think its safe to say that its probably not the tool you should choose FIRST for any given problem."

Re:Why Are So Many Developers Hating on Object-Oriented Prog... by ljm on Friday August 23, 2019 @06:46PM (#20783481)
I suppose it's an aside to your main point, but after 15 years of doing this stuff (and learning to code by writing procedural PHP first, back in the 4.0 days), I've spent a portion of it investing in OOP and now I'm starting to take a step back from it, and I'm having much more fun writing code without having to worry about classifying the code I'm writing.

The things that OOP does well can be achieved quite nicely using other programming paradigms: you don't need a class system or a hierarchy to encapsulate your state and behaviours. And a good OOP language gives you the resources to model your behaviours in functional and procedural ways so long as you have first-class functions and good support for expressions in favour of statements.

OOP fits much better into an organisational model where you can think about domains, roles, and responsibilities, and all of a sudden your Factories, Validators, Services, Commands, Builders, Entities and Repositories map to the same way of thinking your hierarchy of teams and managers does, with all of the overthinking and bike shedding that comes with it.

You could build the same feature without all that but I think you need an experienced and disciplined team to pull it off well. And I think that supports your point: if the entry point to programming wasn't OOP (like with Java or PHP or even Ruby) but something more fundamental, then maybe that gives you the opportunity to decide when you need the power of abstraction that OOP gives you.

Re:Why Are So Many Developers Hating on Object-Oriented Prog... by brlewis on Saturday August 24, 2019 @03:59AM (#20785918)
What do those entry-level programmers want to make? They should start with something suitable for that, even if it's harder to learn. A motivated novice will do better at learning hard things than an unmotivated one will at learning easy things.

But I'm getting out of my element here; I don't interact with entry-level programmers that much. For all I know it may be good for that group that we have fads. If the crowd decides that now we're always using composition and never inheritance, they'll get to fully explore composition. Emphasizing a single skill for an extended period is probably good training.

But to get to a more concrete example, say you're not a novice and you're making a static site builder. If you go with the fad of avoiding inheritance you'll blind yourself to the fact that a typical static site has a collection of page types with is-a relationships, totally ripe for inheritance. You'll probably go with the "layout attribute" model of grouping pages and miss the opportunity to make a static site builder that's better than the others.

Re:Why Are So Many Developers Hating on Object-Oriented Prog... by andrekandre on Friday August 23, 2019 @07:56PM (#20784034)
> We are actively encouraging OOP to entry-level programmers today -- it is fair to ask whether that is the right move, because doing nothing is actually just choosing that OOP should be the default. It is totally fine to say "maybe OOP has not delivered on its promises, and while there may be useful lessons here, I think its safe to say that its probably not the tool you should choose FIRST for any given problem."

the following is my anecdotal opinion but...

that is mostly an economic effect caused by the java “pop culture” and education being seen as a way to “get a job” which is then self-reinforcing (more educated in java, bigger talent pool, increase in default job requirements, more educators by default choose java

economics is a huge factor in this “i hate oop” bandwagon because java isn’t even “good oop” (again my admitted bias) and people dislike being toldwhat tools to use, either by educators and employers when they can see much better ways to do things than DataManagerFatoryFactoryInjectionContainer<T>...

Re:Why Are So Many Developers Hating on Object-Oriented Prog... by fredthomsen on Friday August 23, 2019 @09:21PM (#20784524)
This. Java took too abstractions to absurd extremes. Contrast that with something like python which does things much better and uses a nice data model.
Re:Why Are So Many Developers Hating on Object-Oriented Prog... by pjmlp on Saturday August 24, 2019 @01:46AM (#20785480)
In Python, specially after 3, everything is an object, easily observable by applying dir() on them.

The only thing that fails short of Smalltalk are the conditional and looping operations.

Python also offers multiple inheritance and proper meta-classes.

Re:Why Are So Many Developers Hating on Object-Oriented Prog... by yoz-y on Friday August 23, 2019 @05:42PM (#20782940)
What courses or universities actually start with OOP? In my uni we started with functional programming (Scheme) and then went to C, only then we learned Java, C++, Prolog and so on.

In another uni when I supervised some exercise classes all students started with Python but using only imperative paradigm.

Re:Why Are So Many Developers Hating on Object-Oriented Prog... by tolmasky on Friday August 23, 2019 @05:45PM (#20782971)
In high school AP Computer Science uses Java (20 years ago when I was in high school, they were just transitioning off of C++). You can see what the earliest programmers are being taught here: https://apcentral.collegeboard.org/pdf/ap-computer-science-a...

Edit: When I was in HS, the AP CS courses (now there is only on since the second one was discontinued) used the "Marin Biology Case Study" ( https://en.wikipedia.org/wiki/AP_Computer_Science_A#Marine_B... ). It has apparently been replaced with the "GridWorld" similar case study. I think it highlights one of the issues of OOP: a fascination with modeling, or perhaps over-modeling, the real world. Throughout the course you are expected to develop deep knowledge of a myriad of Fish and Fish Tank-related classes, which while perhaps an accurate preview into what working in an environment like Java is like, is not something that in my opinion succeeds in either exciting most students nor teaching them the "fundamentals" of algorithms and such. I think it can very much feel like a very complex and convoluted exercise in meeting the abstract goals of "categorizing" the world. Ironically, the insistence on modeling the world makes it feel frivolous and disconnected from any practical use -- which is incredibly sad since IMO CS could be the most practical math/science course you take. In my experience when you show kids the cool things that they can get computers to do for them, it can be more inspiring -- such problems do not lend themselves well to formalized class hierarchy drawing though.

Re:Why Are So Many Developers Hating on Object-Oriented Prog... by topkai22 on Friday August 23, 2019 @09:10PM (#20784477)
They are back to two, and the new one appears much further down the “not only OOP” path. It’s more about the grand ideas of CS and less about programming. https://en.m.wikipedia.org/wiki/AP_Computer_Science_Principl...
Re:Why Are So Many Developers Hating on Object-Oriented Prog... by Rapzid on Friday August 23, 2019 @11:41PM (#20785074)
Went through AP comp-sci 20 years ago too. We learned with C++ via DJGPP. Can't recall if the AP test was in C++ or pseudo code.. Certainly covered data structures, recursion, graph traversal, and etc.

High School. Something to consider for those complaining about basic data structure questions in interviews :)

Re:Why Are So Many Developers Hating on Object-Oriented Prog... by DaiPlusPlus on Friday August 23, 2019 @05:58PM (#20783095)
Don’t most university courses worldwide start with Java - or use Java as a mainstay? There are practical benefits: everyone knows it, it’s easy to learn (the language, while the library is straightforward too), and there’s a huge ecosystem.

...and it’s OOP.

Back when I was finishing HS and touring ~5-6 different universities - every single one said they used Java - one said they were about to switch to teaching most of their first two years using JavaScript (this was a few years before NodeJS was even released so the notion of using JavaScript as a serious didactical language wasn’t taken seriously by me.

Re:Why Are So Many Developers Hating on Object-Oriented Prog... by repsilat on Friday August 23, 2019 @09:59PM (#20784686)
It rings true to me, at least in CS and especially software engineering. In mathematics, physics and "real engineering" departments I haven't seen it at all, though, and my experience may date me.

It was my first semester of university programming in '05. Anecdotally, I wasn't as bothered by "public static void main string args" as I was by

- Starting execution in MyClass.main,

- Instantiating a MyClass, then

- Calling MyClass.run().

That took some head-scratching. It's an argument against Java as an introductory language, but not much of one, because "Just ignore that bit until CS102" (or forever if you're never going to do another CS paper) actually works pretty well.

Re:Why Are So Many Developers Hating on Object-Oriented Prog... by DaiPlusPlus on Friday August 23, 2019 @11:09PM (#20784972)
> It rings true to me, at least in CS and especially software engineering. In mathematics, physics and "real engineering" departments I haven't seen it at all, though, and my experience may date me.

Ah - yes. My friends at uni doing physics said they had to learn C++ - but only enough to write simple C-style programs and using simple classes without going into OOP design, design patterns, and large-scale concerns (I guess because they were all using some physics tool, and I understand it's good for interfacing with Fortran too).

My friends doing EE (excluding those doing embedded work) said they all had to do Matlab, some friends doing mathematics reported the same. EE people also said they did some C too.

Re:Why Are So Many Developers Hating on Object-Oriented Prog... by p1esk on Friday August 23, 2019 @06:09PM (#20783179)
In my school currently they offer intro to programming in Python. For those who already know the basics the first course is using C. The next one is C++ and after that Java.
Re:Why Are So Many Developers Hating on Object-Oriented Prog... by bitwize on Friday August 23, 2019 @05:59PM (#20783100)
Today, Java and, increasingly, JavaScript have supplanted the Pascal, BASIC, and C kids in the past started with.

Scheme is cursed. No one wants to teach it, especially to beginners. MIT abandoned it in favor of Python for its introductory course more than a decade ago, and even the Racket folks are backpedaling hard on Lisp syntax, proposing a conventional infix syntax as the default for Racket2.

Re:Why Are So Many Developers Hating on Object-Oriented Prog... by invalidOrTaken on Friday August 23, 2019 @05:53PM (#20783046)
My university began with OOP.

I had to discover FP myself! Uphill both ways!

Re:Why Are So Many Developers Hating on Object-Oriented Prog... by DaiPlusPlus on Friday August 23, 2019 @06:12PM (#20783201)
My uni had a semester-long course on Haskell which I took - but it was mostly about the syntax, understanding `foldr` and writing trivial programs - I can’t say I really learned anything from the experience - I guess because we never did any large-scale examples (I dare say “real-world examples”). Yes, we can do quicksort in 3 lines - but how can I use Haskell for an OLTP workload? How can I use Haskell to program a GUI? (More to the point: how do we reconcile the mental-model of a GUI (the canonical example of mutable OOP!) with Haskell’s immutability?

Unrelated: Haskell needs a more approachable alternative syntax. People bash VB.NET - but it’s a great way to transition people from beginner and PHB-friendly languages (where people completely unfamiliar with a language can still generally understand what’s going on, like Fortran, COBOL, the BASIC family, etc) into an environment where the full .NET library is available before fully transitioning to the alien-seeming curly-braced C#.

...even as a C# programmer, I prefer writing functional-style code with immutable data. I’m not so far as to write the core of a program using Reactive Extensions - but things like Linq - for example.

Re:Why Are So Many Developers Hating on Object-Oriented Prog... by ferzul on Friday August 23, 2019 @09:38PM (#20784583)

  module Main {
    IO<Void> main() {
      Integer n <- read$(getLine) // or: fmap(read)(getLine)
      print(fib(n)) 
    }

    Integer fib(Integer n) { 
      Integer go(Integer !n, Integer !a, Integer !b) {
         if (n==0) {
            return 0
         } else {
            return go(n-1, b, a+b)
         }
      }
    }
  }
pros: it looks plausibly like Java. cons: all the things that haskell syntax makes easy like partial application become obscure at best. omg, i'm dying in squiggly and round brackets, what is this, lisp? there's too much stuff that has to become ad hoc builtin syntax, like <$> becomes $(...). i don't know if you can program applicatively with this syntax, but i doubt you could have invented it.
Re:Why Are So Many Developers Hating on Object-Oriented Prog... by Multicomp on Friday August 23, 2019 @10:08PM (#20784735)
Based on your last paragraph, it sounds like you are describing F#.

F# is an immutable by default functional-first programming language in .net.

Re:Why Are So Many Developers Hating on Object-Oriented Prog... by ferzul on Friday August 23, 2019 @09:44PM (#20784612)
in retrospect, i wonder if you're proposing an alternative (lazy) language on the ghc runtime with the ghc calling convention, that can share types and code, so you effectively have a lazy java-like language with ghc interop?
Re:Why Are So Many Developers Hating on Object-Oriented Prog... by pjmlp on Friday August 23, 2019 @05:56PM (#20783076)
My degree in the mid-90's used Pascal on the first year, than moved into C++, which back on those days meant 2nd year students would all be implementing their own string, vector, list, double list, priority queue, ... classes.

C was never though, it was thought to be mostly relevant for UNIX coding and students could anyway get into it via the C++ lectures.

Then there was Prolog, Smalltalk, Lisp, Caml Ligh (OCaml's percursor), Algol, x86 and MIPS Assembly.

Those that opted into compiler design/software engineering lectures also got into a myriad of other programming languages even if only as overview of what used to exist out there, namely Ada, Eiffel, Sather, Oberon, BETA, PL/I,...

Re:Why Are So Many Developers Hating on Object-Oriented Prog... by Aeolun on Friday August 23, 2019 @08:16PM (#20784164)
There’s little point in teaching either functional or procedural programming, as they’ll both be more or less covered when you’re learning Object Oriented programming.

There’s nothing preventing certain functions from being procedural or functional.

Re:Why Are So Many Developers Hating on Object-Oriented Prog... by Aeolun on Friday August 23, 2019 @11:03PM (#20784953)
If you disagree, I’d love to know why.

Every time I see a post like this, or my comment get downvoted, I read the Wikipedia article again, and am forced to conclude that no, I still don’t appear to be wrong.

- Procedural programming: programming with procedures (e.g. functions)

- Functional programming: programming with only functions

- OO programming: programming with procedures and classes.

Re:Why Are So Many Developers Hating on Object-Oriented Prog... by grumpyprole on Saturday August 24, 2019 @03:23AM (#20785791)
> I still don’t appear to be wrong.

Procedures are not functions! I can understand the confusion since both Java and OCaml will let you define both. Procedures have side-effects, e.g. mutating global state, (pure) functions don't. Functional programmers work with predominantly immutable values and this requires a very different style of programming - one that many people struggle with if they have not had much exposure to it. Functional programming languages also have syntax and abstractions (often taken from maths) that are not used in object oriented programming. Why program with functions and immutable data? It enables better composition.

Re:Why Are So Many Developers Hating on Object-Oriented Prog... by Aeolun on Sunday August 25, 2019 @06:51AM (#20792273)
> Procedures are not functions

https://en.m.wikipedia.org/wiki/Procedural_programming

I guess I just happen to be reading an article that doesn’t make any distinction.

> Functional programming languages also have syntax and abstractions (often taken from maths) that are not used in object oriented programming.

True, but this is nothing related to functional programming an sig.

Re:Why Are So Many Developers Hating on Object-Oriented Prog... by psetq on Friday August 23, 2019 @05:24PM (#20782747)
I agree. The only way to have this language paradigm discussion productively is if we're all looking at two well written implementations of the same project in each.

Even then, I think the final conclusion (most likely "agree to disagree") will be that it's largely subjective, and heavily biased by familiarity.

Ultimately though, it's really just a distraction to avoid the much more controversial discussion we need to be having vis-à-vis tabs vs. spaces.

Re:Why Are So Many Developers Hating on Object-Oriented Prog... by kerkeslager on Friday August 23, 2019 @05:48PM (#20782993)
"You can write bad code in any language" is fairly proven.

Can you write good code in any language, though? At least, good enough? It's quite hard to study objectively, but my subjective opinion is "no". Trivially, brainfuck certainly doesn't cut it, but even if you're only looking at serious languages geared toward general, production-quality programming, there's a lot of programming languages that are much easier to make mistakes in or abuse than others.

Re:Why Are So Many Developers Hating on Object-Oriented Prog... by akira2501 on Friday August 23, 2019 @05:55PM (#20783062)
> Can you write good code in any language, though?

Yes, absolutely.

> At least, good enough?

I think the better question is, can you write good code in a particular language and still make deadline?

Re:Why Are So Many Developers Hating on Object-Oriented Prog... by fgonzag on Saturday August 24, 2019 @05:08AM (#20786111)
I don't see how anything written in brainfuck could ever be called good code.
Re:Why Are So Many Developers Hating on Object-Oriented Prog... by coldtea on Saturday August 24, 2019 @07:55AM (#20786621)
That's because you focus on surface syntax.

In the end brainfuck is just a fancy assembler.

You could very well write nicely formatted, structured etc brainfuck. It will just look weird because the (otherwise very simple operations) have a weird sigil syntax.

Re:Why Are So Many Developers Hating on Object-Oriented Prog... by jstimpfle on Sunday August 25, 2019 @05:49AM (#20792149)
Come on, that's as objectively false as it gets.

Brainfuck doesn't give you macros, function calls, function structures. It doesn't have names for anything. In other words there is zero syntactic and physical abstraction. The programmer must assemble everything on their own, with extreme repetition, making it extremely hard to see structure, or to change it.

You can't even write efficient code in it since basic arithmetic operations (like addition, indexing) are O(n).

Re:Why Are So Many Developers Hating on Object-Oriented Prog... by kerkeslager on Friday August 23, 2019 @06:45PM (#20783468)
I'd say you can't write good enough code in any language. The most high-profile, extensively tested C networking code still has security vulnerabilities, for example--the best C code isn't good enough. And broadly speaking, I'd say good code meets deadlines, but I guess that's a bit of semantics on my part.
Re:Why Are So Many Developers Hating on Object-Oriented Prog... by ncmncm on Friday August 23, 2019 @07:13PM (#20783697)
Donald Knuth is quite fond of C. He writes checks to people who find bugs in his code. They are quite valuable, because they are very rare.
Re:Why Are So Many Developers Hating on Object-Oriented Prog... by pjmlp on Saturday August 24, 2019 @01:56AM (#20785510)
Tex was implemented in Pascal and uses web2c to generate C code.

https://en.wikipedia.org/wiki/TeX

Had he implemented it directly in C he would be sending checks every day.

Re:Why Are So Many Developers Hating on Object-Oriented Prog... by jstimpfle on Sunday August 25, 2019 @05:59AM (#20792175)
> Had he implemented it directly in C he would be sending checks every day.

He used Pascal maybe not for the reasons you think. Remember it was the early 70s. If you actually look at the TeX source code, I'm pretty sure you won't find the kind of Pascal you envision.

Nowadays, Knuth does use C directly. (FWIW)

Re:Why Are So Many Developers Hating on Object-Oriented Prog... by ahhhhhhhhhhb on Friday August 23, 2019 @09:30PM (#20784554)
so rare, industry defining geniuses can avoid fucking up too much with unquantified effort and no real deadlines or pressure to produce. got it
Re:Why Are So Many Developers Hating on Object-Oriented Prog... by ncmncm on Sunday August 25, 2019 @03:10PM (#20794857)
If you were as productive as Donald Knuth, you would have reason to be very proud.
Re:Why Are So Many Developers Hating on Object-Oriented Prog... by kerkeslager on Sunday August 25, 2019 @10:49AM (#20793296)
Not networking code.
Re:Why Are So Many Developers Hating on Object-Oriented Prog... by akira2501 on Friday August 23, 2019 @07:06PM (#20783645)
> extensively tested C networking code still has security vulnerabilities

Are you familiar with Daniel J Bernstein?

> the best C code isn't good enough

Are you sure _you've_ seen the _best_ code? Are you sure you understood the constraints of those writing that code when you evaluated it?

> I'd say good code meets deadlines

I'm trying to say there's an obvious compromise between the two, which explains the wide spectrum of code quality.

Re:Why Are So Many Developers Hating on Object-Oriented Prog... by mantap on Saturday August 24, 2019 @12:33AM (#20785226)
If you have to be DJB or Bellard to write good code in a programming language, that programming language probably has a problem. I used to write a lot of C back in the day, but I have to admit that C++ code is far more reliable and maintainable, which is a damning thing to say about any programming language.
Re:Why Are So Many Developers Hating on Object-Oriented Prog... by kerkeslager on Tuesday August 27, 2019 @05:16PM (#20814467)
I am somewhat familiar with Daniel J. Bernstein, but you'll have to enlighten me on why you've brought him up.

If you're referencing programs where half the source code is written in a theorem proving language like CoQ, that's not really "written in C", now is it?

Re:Why Are So Many Developers Hating on Object-Oriented Prog... by ferzul on Friday August 23, 2019 @08:33PM (#20784264)
> Have you seen bad functional code? It's an unreadable mess of monads, flatmaps and partial composition where you're not really sure how many arguments a curried function is whitholding.

not yet. can you point to any examples?

Re:Why Are So Many Developers Hating on Object-Oriented Prog... by kjeetgill on Friday August 23, 2019 @04:10PM (#20782068)
This post really needs to be the required reading before any PL paradigm discussion.

If only dang could pin it to the top of every post with OOP in the title

Re:Why Are So Many Developers Hating on Object-Oriented Prog... by nafizh on Friday August 23, 2019 @05:27PM (#20782783)
It's much easier to write bad OOP and procedural code, TBH.
Re:Why Are So Many Developers Hating on Object-Oriented Prog... by ivanhoe on Friday August 23, 2019 @05:41PM (#20782921)
yes, but it's also much easier to write a good OOP code... learning curve is way steeper for functional programming, OOP is easier to grasp as it's closer to how we usually think of the world, while FP is more math like...
Re:Why Are So Many Developers Hating on Object-Oriented Prog... by Barrin92 on Friday August 23, 2019 @06:56PM (#20783555)
I think it's easier to write OOP code period, without the 'good'. I think writing good OOP code is significantly harder than writing good functional code, because OOP gives users significantly more options to go astray.

The limiting nature of functional languages tends to force people into cleaner solutions at the cost of harder constraints.

Re:Why Are So Many Developers Hating on Object-Oriented Prog... by kazinator on Friday August 23, 2019 @07:51PM (#20784002)
The limiting nature of functional languages tends to force people into looking for cleaner problems.
Re:Why Are So Many Developers Hating on Object-Oriented Prog... by kerkeslager on Saturday August 24, 2019 @11:34AM (#20787713)
Like massively multithreaded concurrency? Natural language parsing? AI? Deterministic security? Natural language parsing???

I suppose you're right in a sense, these problems are cleaner if you think of them in functional terms. ;)

Re:Why Are So Many Developers Hating on Object-Oriented Prog... by raverbashing on Friday August 23, 2019 @06:12PM (#20783199)
We also have a lot more of "holier than thou", gatekeeping, guidance that's more subjective than objective but taken as gospel like "SOLID", "clean code", stuff like MVC where your circular system is made to fit a square hole etc in OOP.
Re:Why Are So Many Developers Hating on Object-Oriented Prog... by contravariant on Friday August 23, 2019 @07:37PM (#20783891)
I reckon FP wouldn't have as bad a reputation if the Haskell folks didn't insist that <*> and <$> is perfectly acceptable notation.

FP does force you to pay more attention to state though, and losing track of the program state is the root of all evil.

Re:Why Are So Many Developers Hating on Object-Oriented Prog... by ferzul on Friday August 23, 2019 @09:59PM (#20784690)
actually they don't. many haskellers would prefer to write

  foo <$> bar <*> baz quux
using idiom brackets as, say,

(| foo bar (baz quux) |)

in any case, the problem is that we want a lightweight syntax for a widespread, general purpose abstraction. the former syntax is used since it's an abstraction developed in terms of the language - so only general names and syntax were available.

obviously they're hostile to people who haven't learnt them yet, but i'm not sure that java's . or = is any better in that respect. these do cause learners difficulty, since they're so foreign to anything they learnt pefore programming.

Re:Why Are So Many Developers Hating on Object-Oriented Prog... by kerkeslager on Friday August 23, 2019 @06:19PM (#20783257)
Okay, but how we think of the world is a pretty poor way to program computers. If you write objects to act how we think of the world, then you mutate state within your objects, and when you add threading it becomes a mess. You can avoid this with immutability, but then you start doing stuff like replacing one Person with another with one property changed, and you're no longer treating Objects like they are in the real world.

A lot of good OOP practices like this are built in and somewhat enforced in FP. For example, the single responsibility principle: which psuedocode implements single responsibility better?

    immutable class Schema:
        Schema(self, ...):
            ...

        bool check_document(self, Document document):
            ...

        Schema with_constraint(self, Constraint new_constraint):
            ...

        Schema without_constraint(self, Constraint old_constraint):
            ...

...or...

    ... -> Schema
    make_schema(...) ...

    Schema -> Document -> bool
    make_schema_checker(schema) ...

    (Schema, Constraint) -> Schema
    add_constraint(schema, constraint) ...

    (Schema, Constraint) -> Schema
    remove_constraint(schema, constraint) ...
Sure, you could separate out `class ConstraintChecker` and `class SchemaBuilder`, but you might not think to do that at the time, it costs an extra file, what's the harm, right? And I really doubt many OO programmers would go to the lengths of separating `class SchemaBuilder` into `class ConstraintAdder` and `class ConstraintRemover`. In fact, that would be so verbose that I'd probably argue that it's not good code. Meanwhile, the same functions in a functional style are each already separated because that's the only option for to do it, and it doesn't come with the verbosity cost. Closures are inherently single-responsibility objects, so much so that you don't even need to specify which method on them you're calling, you just call the object itself and it does the only thing it could possibly do!

I suppose it might be more intuitive to do this:

    (Schema, Document) -> true
    check_document_against_schema(schema, document)
Which would force you to leak the concept of the Schema to places that don't need to touch it, but at least check_document_against_schema still has a single responsibility.
Re:Why Are So Many Developers Hating on Object-Oriented Prog... by ivanhoe on Friday August 23, 2019 @07:05PM (#20783641)
Well, it's not like you have to mutate the state or program with side-effects just because you have some classes... once someone starts grasping on OOP principles, you can teach them the best practices, what to avoid, etc. That said, I definitely think that FP is the right way to go, I'm personally moving in that direction, but I think people should first get their feet wet with OOP, as it's easier to learn, and there's a lot of common knowledge between the two. Once you learn OOP and start to feel the problems and limitations, transition to FP will make more sense IMHO. It will not be just because some dudes on Internet said it's cooler, but you can spot the benefits yourself.
Re:Why Are So Many Developers Hating on Object-Oriented Prog... by kerkeslager on Saturday August 24, 2019 @11:26AM (#20787665)
> Well, it's not like you have to mutate the state or program with side-effects just because you have some classes...

That's true, as I said in the post you're responding to. But as I also said in the post you're responding to, then your claim "OOP is easier to grasp as it's closer to how we usually think of the world" ceases to be true: when you give one of your employees a raise, do you replace them with another employee who is identical except for their salary? Obviously not, but that's how you'd give someone a raise if `Employee` is a class of immutable objects. You get to have one or the other:

1. Either OO is similar to how we think of the world and you're writing bad OO code that's got mutation all over the place,

2. OR OO isn't similar to how we think of the world, but you've got immutable objects that play nicely with concurrency.

You can't have both.

> I think people should first get their feet wet with OOP, as it's easier to learn,

"OOP is easier to learn" is a claim I hear a lot, but I've yet to see any evidence that this is the case. Most people's evidence seems to be, "The way I learned it is the easiest." Given that most people start with OOP, it's unsurprising that many people think OOP is easier. There's also more learning materials available for OOP. But if you had completely untrained people learning programming for the first time with equal quality learning materials and instruction, I don't know which group would make progress more quickly, and I don't think anyone does know.

In any case, if the ease of learning OOP comes from being able to start with bad habits (i.e. mutation) that allow you to write code the way you think of the world, I question whether this is actually a good thing.

> and there's a lot of common knowledge between the two.

This I totally agree with you on.

Re:Why Are So Many Developers Hating on Object-Oriented Prog... by env123 on Monday August 26, 2019 @05:04AM (#20798335)
The supreme question really is if you have a really great OOP code, a really great functional code and a really great procedural code, all achieving the same thing, which would be the best? ie. which would be best in front-end? in the back end? in services where you do loads of calculations and analysis? in services where you just need to retrieve data?

It's probably best to be a full-stack developer, or find specialists who are really great at OOP and work on where it properly applies in the architecture system of a project, the same for functional or procedural

We don't need to box ourselves (or a company) in OOP only (or functional or procedural if that's your main paradigm)

Re:Why Are So Many Developers Hating on Object-Oriented Prog... by flukus on Monday August 26, 2019 @08:52PM (#20805255)
> The supreme question really is if you have a really great OOP code, a really great functional code and a really great procedural code, all achieving the same thing, which would be the best?

IME from a maintenance perspective (which is the only place you really find out what is and isn't good code) procedural is nearly always the answer, stupidly simple imperative logic is easy to follow and debug. In the UI you might want some more functional/event driven code but even then the bulk of it should be procedural. Most "great OOP" I've seen isn't all that OOP anyway, it's mostly procedural code with some OOP features used for name spacing.

Re:Why Are So Many Developers Hating on Object-Oriented Prog... by boardwaalk on Friday August 23, 2019 @05:39PM (#20782900)
The difference between them is probably that the OOP was a solution to all problems in its heyday. And a lot of us are probably saddled with the resulting legacy code to this day.

That never quite happened to functional code and procedural code was the only solution to problems at the time.

Re:Why Are So Many Developers Hating on Object-Oriented Prog... by AnimalMuppet on Friday August 23, 2019 @11:52PM (#20785113)
In my opinion, C++-style OOP was a solution to a particular problem: Here's a procedural program. It's got some data. That data is grouped together for convenience in, say, C-style structs. The problem is that any function in the entire program can modify the data in the structs. When the data goes bad (self-inconsistent, say), that gives you a lot of places to look. Someone wrote a function that doesn't maintain the data in a consistent state, and it could be anywhere. In a 10-million-line code base, that could be a long search.

C++ classes changed that. Nobody gets to modify the data except member functions (presuming no inheritance). Maintaining the consistency of the data is easier, because there's a very limited number of functions to look at to make sure they preserve the invariants.

With inheritance, you can still do that for the parts that you make private.

Now, is that the ultimate answer to how to do software development? Perhaps not. It was a step better than the way things were before, though.

Re:Why Are So Many Developers Hating on Object-Oriented Prog... by joelfolksy on Friday August 23, 2019 @05:27PM (#20782777)
I would much rather struggle to interpret a complex expression (monads, partial application) than struggle to simulate a sequence of mutations (that potentially spans the entire object graph).