[–] 3 points 1 year ago (1 child)

If your experience with FP is as limited as you say, then, respectfully, you lack the requisite experience to compare the two. It's an entire paradigm shift that requires you to completely change how you think if you're accustomed to OOP, and really requires one to program in a language designed for it. The features that OOP languages have cribbed from FP languages are very surface-level and not at all representative of what it actually is (and I'd say they largely miss the point of FP).

I have been writing Haskell professionally for the last 5 years over the course of 2 jobs developing database-backed web services for web and mobile apps, and spent about ~5 years before that developing in OOP/imperative languages. I have a good deal of experience with both paradigms.

OOP is more useful as an abstraction than a programming paradigm.

It's a very poor (and leaky) abstraction, and you can achieve much more powerful abstractions with FP languages (especially Haskell, which has a type system that is far more powerful than any OOP language is capable of). This is evidenced by the fact that a whole slee of design patterns exist to solve problems created by OOP itself. FP languages, on the other hand, have little need for design patterns, because useful patterns are easy to abstract over and turn into libraries.

Real, human, non-computer programming is object-oriented, and so people find it a natural way of organizing things.

I have no idea what this even means. Programming is taking input and producing output. That, at its core, is a function. Pure and simple. Many useful ideas are quite difficult to express as a noun, which is how you end up with a whole array of super awkwardly named classes that try to "noun-ify" verbs (think classes named like Serializer, Resolver, Initializer, and so on).

It makes more sense to say "for each dog, dog, dog.bark()" instead of "map( bark, dogs)".

This entirely misses the point of FP. What data is actually being transformed here? It's a nonsensical example.

A good use case for OOP is machine learning. Despite the industry's best effort to use functional programming for it, Object oriented just makes more sense.

Not really sure what you're talking about. No one uses functional programming for machine learning outside of research. To be clear, Python is not functional programming. The reasons for that having nothing to do with the paradigm and everything to do with social reasons and inertia. Python was already used by a lot of academics for some ecosystem reasons, and the ecosystem has grown since then. Had the history of things been different, functional programming absolutely would have excelled at it and would have been a much better fit, because machine learning is fundamentally a pipeline of transformations on data.

You want a set of parameters, unique to each function applied to the input. This allows you to use each function without referencing the parameters every single time. You can write "function(input)" instead of "function(input, parameters)".

This is trivial to do in functional programming languages with a variety of methods. Commonly this is done with the Reader Monad, or even simply partial application of functions (also known as closures).

  • source
  • parent
  • context
  • [–] 7 points 1 year ago (1 child)

    I mean, I have an OOP background. I found FP as a result of my dissatisfaction with OOP. In fact, I used to teach OOP languages to new students and saw the same mistakes over and over again, mistakes that are simply not possible in FP. It's a very similar story for everyone I work with, too. We all had jobs in various OOP languages before we managed to get jobs writing Haskell.

    Oh, and I'm currently teaching Haskell to someone at work who has a CS degree and has only done OOP languages (and C), and while it's different than what he's used to, he's still picking it up very quickly (working towards making him a junior engineer, which I think shouldn't take too much longer). In fact, just the other day we pair programmed on a bug ticket I have and he was not only following along with the code, he spotted issues I hadn't seen yet. Part of it is certainly that's he smart (which is why I'm doing this in the first place), but part of it is also that, with a bit of familiarity, FP languages are incredibly easy to read and follow. The primary difference is that FP does everything explicitly, whereas OOP encourages a lot of implicit (and hidden) behavior. When you organize code around functions, there's necessarily more explicit arguments and explicit return values, which makes it far, far easier to follow the flow of logic of code (and test!). Recently I was trying to read through our Kotlin codebase at work (for our Android app), and it was so much harder because so much is implicit.

  • source
  • parent
  • context
  • [–] 5 points 1 year ago (1 child)

    I was required to take an ethics class, but it was a complete joke. Guy just wasted a bunch of time on very surface-level, Philosophy 101 stuff like talking about who Aristotle was. I'm not sure we even had homework actually. Real ethics were nowhere to be found.

  • source
  • parent
  • context
  • [–] 2 points 1 year ago (8 children)

    FP has been around a long time, and yes, it is outright better than OOP. Sorry. I write Haskell professionally, and never have I ever felt like something would be easier done in an OOP language. Quite the opposite.

    Unrestricted mutation makes programming really hard, and OOP and mutability go hand-in-hand. If you try to make immutable objects, then you're just doing FP with worse ergonomics.

  • source
  • parent
  • context
  • [–] 3 points 1 year ago (1 child)

    Eh, it's just different. Other languages are hard in other ways. Haskell's at least have very good reason behind them.

    I write Haskell professionally and and am teaching to people without any experience, and it's really no different than anything else. Though I will say that my experience is that university professors are often pretty clueless about the language and don't teach it well.

  • source
  • parent
  • context
  • [–] 4 points 1 year ago

    Just looking at the image, yeah he's a little parser combinator library entirely from scratch.

    Not sure what you mean by verbose type declarations. It looks to be 2 type declarations in a few lines of code (a newtype for the parser and a sum type to represent the different types of JSON values). It's really not much at all.

  • source
  • parent
  • context
  • [–] 2 points 1 year ago

    Yep, that's exactly what we do, and it tends to work. Can take a bit for some foods and sometimes he's just really into just one thing right now, but overall it's much better than trying to force feed him broccoli or whatever.

  • source
  • parent
  • context
  • [–] 4 points 1 year ago (1 child)

    It's not bullshit. Research shows that kids need multiple exposures to new foods before they're willing to accept them. It's important to keep offering foods a child has refused before (without pressuring them to eat them, by the way).

  • source
  • parent
  • context
  • [–] 19 points 1 year ago* (2 children)

    It's not performative. Research shows that kids can need 8-10 or more exposures to a new food before they're willing to accept it. It's important to keep offering foods even if they've refused it before.

    I've personally seen this effect with my 2 year old son. Had absolutely no interest in noodles of any kind for a long time, yet we kept offering them, and one day he decided to try them and loved them. In fact, most new foods he eats are a similar story.

  • source
  • view more: ‹ prev next ›