Functional OOP????? | Prime Reacts

Поділитися
Вставка
  • Опубліковано 26 бер 2023
  • Recorded live on twitch, GET IN
    / theprimeagen
    MY MAIN YT CHANNEL: Has well edited engineering videos
    / theprimeagen
    Discord
    / discord
  • Наука та технологія

КОМЕНТАРІ • 385

  • @figloalds
    @figloalds Рік тому +193

    This is how chaotic evil programmers write code

    • @mkwpaul
      @mkwpaul Рік тому +30

      Too much philosophy behind it to be chaotic.
      This very much feels like Lawful Evil.
      They're extremely determined to do *bad* things. And they'll follow rigid rules and guide lines to do *bad* things.

    • @benjaminmathis9044
      @benjaminmathis9044 Рік тому +8

      As a Chaotic Evil, I prefer not being grouped together with this fellow. Makes too much sense.

  • @Wolfeur
    @Wolfeur Рік тому +290

    Feels like _a lot_ of effort to just do something you can do better and more easily.

    • @ThePrimeTimeagen
      @ThePrimeTimeagen  Рік тому +92

      i feel this heavily

    • @victornpb
      @victornpb Рік тому

      bro just re-created the worse parts of javascript in userland. i heard you like slow runtimes

    • @diadetediotedio6918
      @diadetediotedio6918 Рік тому +9

      @ThatGuyJamal
      ?

    • @OcarinaOfVali
      @OcarinaOfVali Рік тому +3

      ​@ThatGuyJamalbut one is fast and robust while the other isnt

    • @chudchadanstud
      @chudchadanstud Рік тому

      @ThatGuyJamal This is true.

  • @TJPedenTheBeard
    @TJPedenTheBeard Рік тому +21

    Dude saw a wheel and said "I could do a better job" and added corners. Stop reinventing the wheel, your square wheel is not better! 😂

  • @adambickford8720
    @adambickford8720 Рік тому +439

    My entire OOP experience. Hours of philosophy to create code that doesn't make sense w/o that philosophy and blows up on a simple structural change due to all the coupling.

    • @guillemgarcia3630
      @guillemgarcia3630 Рік тому +33

      my functional experience as well. I remember eric elliott, guy from medium, overcomplicating things with transducers and react hocs
      naturally the js ecosystem is a mess, if guys like this have much influence

    • @tsalVlog
      @tsalVlog Рік тому

      @@guillemgarcia3630 I despise people who add React to other languages. It's a disease. Cancerous.

    • @bobbycrosby9765
      @bobbycrosby9765 Рік тому +16

      @@guillemgarcia3630 I just read his article on transducers, and it seems a bit misapplied in JavaScript.
      They're great for Clojure because they solve real problems the language had. I wish people would analyze tools in context rather than thinking they apply to every language. Similarly, I think monads are a bad choice for dynamic languages, but great for static languages. Yet you still see people trying to stuff them into Elixir.

    • @nowave7
      @nowave7 Рік тому +4

      @@guillemgarcia3630 Good ol' procedural FTW!

    • @detaaditya6237
      @detaaditya6237 Рік тому +1

      ​@@bobbycrosby9765 Totally agree. It feels like JS is not designed for complex FP patterns. It becomes super awkward and unreadable af

  • @mihai-gabriel-07
    @mihai-gabriel-07 Рік тому +190

    Sounds like a 'junior' trying to over-engineer something and they end up with a mess, also being very opinionated about it

    • @ThePrimeTimeagen
      @ThePrimeTimeagen  Рік тому +60

      i mean, the concept of message passing passing is a popular concept, but what was created here...

    • @telnobynoyator_6183
      @telnobynoyator_6183 Рік тому +1

      "former CTO" he says in his bio

    • @pingmetal
      @pingmetal Рік тому +2

      @@stringnerd 😂

  • @weiSane
    @weiSane Рік тому +112

    Oh my gosh ...if I were a jr programmer at Netflix I would be so nervous whenever Prime is reviewing my code. 😂

    • @ThePrimeTimeagen
      @ThePrimeTimeagen  Рік тому +138

      hah. i would assume you wouldn't take a silly 10 line function and turn it into 30 lines....

    • @weiSane
      @weiSane Рік тому +13

      ​@@ThePrimeTimeagen that would be atrocious.

    • @ClowdyHowdy
      @ClowdyHowdy Рік тому +9

      You could avoid half the chaos energy by using prettier.

  • @dthe3
    @dthe3 Рік тому +34

    The origins of object-oriented programming (OOP) can be traced back to the development of the Simula programming language in the 1960s by Ole-Johan Dahl and Kristen Nygaard at the Norwegian Computing Center. Simula was originally designed for simulating real-world systems, and it introduced the concepts of classes and objects, which are now fundamental to modern OOP languages.
    Simula's innovations in OOP inspired the development of other programming languages, such as Smalltalk. It's annoying when some people wrongly cite the history of OOP, then proceed to be is super opiniated it.

  • @jonaskoelker
    @jonaskoelker Рік тому +7

    This looks kinda' similar to how objects are implemented in the Structure and Interpretation of Computer Programs video lecture series.
    I guess the point of the article was to teach how you can build a thing which behaves like built-in objects using simpler parts-ignoring the fact that what you have created is a monster. That is, the point was not to teach a programming technique but to transmit a conceptual understanding.
    For comparison: I could roll my own vtables in C if I needed them. I hope I won't need them, but I really like knowing how to. This article might have expanded someone's mind the same way my mind was expanded when I understood that.
    With that in mind, I don't find the article objectionable.

  • @sleepiboi5133
    @sleepiboi5133 Рік тому +115

    Imagine a function that I could pass any array of grades in. One student or the whole school, the function wouldn’t care. It would just return the best grade of the input set.
    Now wouldn’t THAT be cool 🤔

    • @equivocator7727
      @equivocator7727 Рік тому +23

      When there's that much brainrot going into an article it's easy to forget simple things like this 😂

    • @michawhite7613
      @michawhite7613 Рік тому +48

      Better yet, what if we had a max function, so it doesn't even need to be a grade? Any number will work. Hell, it doesn't even need to be a number. It just needs to implement the `Ord` trait.

    • @Hazanko83
      @Hazanko83 Рік тому +18

      Best way to put it lol... One of the best things a programmer can do for themselves is creating logic that is direct and as generalized/simple as possible without making compromises.
      The article literally starts off by saying ''Well we could rename the function to better indicate usage, or [we can create a complicated web of indirection and run-time bloat]''(in so many words)
      Rename the function ''GetBestGradeFromArray'' - and the entire codebase as well as everyone involved will be happier.

    • @lastmanstanding5423
      @lastmanstanding5423 Рік тому +14

      "An idiot admires complexity, a genius admires simplicity" Terry Davis (TempleOS)

    • @JacoJansenvanVuuren
      @JacoJansenvanVuuren Рік тому +4

      Easy. We can just create a Students functional class thingamajig that take in multiple Student functional classes and then have a “function” that iterates over all the _students to get the max and return the max of that.
      Simple. Efficient.

  • @LoveLearnShareGrow
    @LoveLearnShareGrow Рік тому +9

    It's clear from the last paragraph that he's not recommending that code style. It's designed that way to DEMONSTRATE what message passing is. He should have brought it back to idiomatic JS and pointed out where the message passing happens.

  • @richardgeddes630
    @richardgeddes630 Рік тому +21

    I think the author of the article missed the chapter on prototypes, prototype chains, and prototypal inheritance in JavaScript. Oddly enough, that's one of the main things that differentiates JavaScript from other languages.

    • @quatricise
      @quatricise Рік тому +4

      I actually think this is great, it's so flexible that you can just override all properties inherited by the prototype, it defeats the coupling problem of inheritance.
      Also, if you're mad enough, you can implement abstract classes and interfaces by adding methods that throw an exception that tells you to replace the method with a new one. Don't recommend it but i did that on one older project that I started in JS and couldn't be bothered to port it to typescript.

  • @ryangrogan6839
    @ryangrogan6839 Рік тому +11

    Just found your channel recently and I didn't know just how much I needed an angry developer to aggressively afirm me

  • @redlancer7263
    @redlancer7263 Рік тому +74

    I got out of bed at 5am to keep programming cause I couldn't sleep and this is going to be good entertainment

  • @fletchcanny717
    @fletchcanny717 Рік тому +6

    This whole article was edging me. I was excited for them to say "look! This is just partial application! And it's a really powerful model when combined with immutability, and a syntax to support it!". Then there was the conclusion and now I'm blue balled.

  • @marcusrehn6915
    @marcusrehn6915 Рік тому +146

    The argument for FP has never been speed. Fans of FP tend to believe that their programs tend to be more correct. Hard to measure, so who really knows. I do think that there are lessons to be learned from that world, that will improve your programs, regardless of language or paradigm.
    Also, Rust is the only language that I know of that takes correctness seriously without going full FP.
    EDIT: The example in the article has nothing to do with anything that the hard core FP people are talking about though. Creating class-like functions with internal state is literally just a less readable way to write OOP.

    • @_orangutan
      @_orangutan Рік тому +38

      I program in Haskell because I like feeling superior to OOP plebs.

    • @jearsh
      @jearsh Рік тому +6

      yeah this article makes me sad. but "functional oo" is a real thing. if you initialize a class with immutable state, and have n number of functions produce values based on the initial state, and pass in any other dependencies you need...aka a decorator that doesn't mutate anything. also called a value object, if nothing is mutated.

    • @jakubrogacz6829
      @jakubrogacz6829 Рік тому

      @@jearsh memory cost. If you could dealloc in 1 instruction - yes

    • @bransonS
      @bransonS Рік тому +3

      Yes, that is my understanding as well.
      If I understand correctly, there is a solid case that OOP was designed to optimize for resources (eg memory/storage/processor), that today are cheap and fast so it makes more sense to optimize for code that is more maintainable (obviously there is a balance here that is different for each scenario).
      For example, in most projects I have been on, hardware limitations have not really been significant issues. But mutable state in the domain logic, and over-abstraction have been.
      It's a similar point for Event type storage vs just overwriting data in the DB. Basically, that there are some trade offs like eventual consistency and more storage costs, but all the stuff you're storing is worth it.

    • @ArgoIo
      @ArgoIo Рік тому +9

      Functional programs do not tend to be "more correct", but their correctness is usually easier to prove. Rust does offer a useful middle ground, though, as smaller blocks are usually easy to reason with using Hoare logic.

  • @omega_sine
    @omega_sine Рік тому +17

    Prime is too optimistic. I knew this wasn’t going to end well when we started returning different functions based on a switch statement.

  • @bahaelaila
    @bahaelaila Рік тому +2

    The article should've been titled: "How to fuck up the Actor model side-ways. Getting all the cons without any pros"

  • @PetrSzturc
    @PetrSzturc 6 місяців тому +1

    I love how one of the first paragraphs is "we need to understand what is message" and then doesn't explain it. 😂

  • @ravenecho2410
    @ravenecho2410 Рік тому +4

    its an exploratory analysis into oop and functional representation of classes, its not meant to be viewed as actual code just oooo. i wonder if 🤔

  • @Ch0rr1s
    @Ch0rr1s 10 місяців тому +1

    This is brilliant!
    If i ever get pissed off with my employer i'll push this through - refactor all the code to match that pattern and then just quit.

  • @jyrikgauldurson8169
    @jyrikgauldurson8169 5 місяців тому +1

    bro literally took the class functions and made them being called with a magic string . OMFG

  • @KnThSelf2ThSelfBTrue
    @KnThSelf2ThSelfBTrue Рік тому +8

    I feel like this is way more complicated than just using classes to encapsulate functionality while keeping all methods pure, and implementing message broker as core component to please Alan Kay.

  • @TankorSmash
    @TankorSmash Рік тому +30

    I think the idea is that you don't need to have OOP built in to use inheritance and all that. It's not about how it's nicer to read or anything, just that classic Message Passing can be done at all.
    To reiterate, I'm big into FP (Elm, Haskell etc), and I don't think the article was saying 'write JS like this', but more 'if you were curious about how it originally worked, it would work like this'.
    The author didn't talk about immutability or referential transparency at all, which is a huge part of why writing frontends in Elm is so nice.

    • @Hazanko83
      @Hazanko83 Рік тому +3

      The absolute best example to show someone would be an example of code from a functional language, and explain what's going on.
      For someone that knows javascript, it could be teaching bad lessons. For someone like me that doesn't know any javascript, the choice to use it as an example provides no actual benefit.

    • @TankorSmash
      @TankorSmash Рік тому +3

      @@Hazanko83 I think it's a numbers game. In 2023, more programmers know JS than not, I think.
      I get your point though, it doesn't show things off as well as it could in another language that plays to its benefits.

  • @wforbes87
    @wforbes87 Рік тому +1

    Yup I remember stumbling into this specific article once... hated it. I feel so vindicated right now, thank you for this confidence boost sir

  • @darylphuah
    @darylphuah Рік тому +3

    The road to hell is paved with good intentions. The road to bad code is paved with misunderstood paradigms.

  • @matthewr8502
    @matthewr8502 Рік тому +10

    He basically said in order to achieve the double dispatch that makes OO message passing work, I am not going to use the features of the language and runtime that already provide this but I am going to write them myself every time I write a class.
    This insanity was particularly depressing as someone who learnt his OO as an undergraduate via Smalltalk and for whom Alan Kay was, and remains, an early hero.

  • @gatodetaco
    @gatodetaco Рік тому +2

    Great primer on code obfuscation and on how to get the mythical "Changes Requested - Merging is blocked"

  • @voidwalker7774
    @voidwalker7774 Рік тому +19

    After now 20 years of software engineering. I never needed multi inheritance, not once. Actually, all problems could be solved without inheritance at all. Interface where nice sometimes, but thats it. OOP and Polymorphism is the bain of software engineering. It leads to slow and hard to debug code. Add Pointers into the mix and the disaster is inevitable.

    • @jakubrogacz6829
      @jakubrogacz6829 Рік тому +2

      Better support for abstract algebra is all is needed.

    • @KyleSmithNH
      @KyleSmithNH Рік тому +1

      All cases for inheritance can be solved with composition if your language supports something like interfaces. Sometimes inheritance is less code, but meh.

    • @voidwalker7774
      @voidwalker7774 Рік тому

      @@KyleSmithNH Ok, give me one real life example. :)

    • @CottidaeSEA
      @CottidaeSEA Рік тому +3

      @@voidwalker7774 A real life example where composition can replace inheritance or where inheritance is less code? Or what?
      OOP is not inherently bad by the way, people simply overcomplicate things, and not being able to have functions as first class citizens is probably the biggest issue, because that means you create classes just to access a function, which is unnecessary overhead for no good reason.

    • @freesoftwareextremist8119
      @freesoftwareextremist8119 Рік тому

      The only "problem" with multiple inheritance is the diamond problem. Which is only a problem in C++ because C++ sucks.

  • @ScibbieGames
    @ScibbieGames Рік тому +1

    What's so great about this article is that the basic implementation for finding the best grade doesn't change at all. There's just useless lines of OOP philosophy surrounding it.
    It still uses the 'not very semantic sounding' array and returns it in the end lol

  • @helleye311
    @helleye311 Рік тому +10

    So you're telling me... They would rather manually type obj('string-message') that is not autocompleted in ANY way, than just do a obj.functionName, that depending on how things are set up will likely be autocompleted, or at least suggested by intellisense sometimes?
    I don't like classes, but doing this just to avoid using the keyword is pretty crazy. I'd rather go back to writing ConcreteAbstractFactoryBeans in java than implement function-classes.

    • @michaelthompson7217
      @michaelthompson7217 Рік тому +1

      if you do this in any language, immediately you are having to create a mental mapping between objects and their string translation. huge headache

  • @equivocator7727
    @equivocator7727 Рік тому +18

    This is like an exercise one might do to try and understand OOP better and then immediately throw it away, not something one should write an article about on the internet saying it's what you should do

    • @michaelthompson7217
      @michaelthompson7217 Рік тому +6

      it’s also the wrong language to do this sort of thing which makes the argument 100x worse. if he is going to style up a lisp-y looking object, he should do it in lisp. this code would make more sense in lisp than in abused-javascript.
      the ultimate implementation of string passing as a method of memory access is one of the worst headache-inducing paradigms in programming IMO. it’s bad in python and it’s bad here.

    • @dalmationblack
      @dalmationblack 11 місяців тому

      @@michaelthompson7217 yeah a CS class I took in college spent a lecture showing how to write classes like this in scheme and it was useful at the time for understanding how OOP works but its really not much more than that

  • @slpwrm
    @slpwrm Рік тому +5

    all of this to avoid using "class" keyword and methods?

  • @danieltm2
    @danieltm2 Рік тому +2

    Prime was so upset he forgot his outro lmao

  • @broccoli7263
    @broccoli7263 Рік тому +1

    Renaming local variables to have a leading underscore to indicate privacy inside a closure where variables are going to be private by default is... interesting.

  • @freesoftwareextremist8119
    @freesoftwareextremist8119 Рік тому +8

    Pretty sure the authors point was not "Do it this way!" his point was to show how an OO system can be implemented using closures and higher order functions. The message passing here is of course very awkward in JavaScript, as you need to use strings to encode a message, which is not ideal. But the point is to show the concept, not to create something production ready.

    • @9SMTM6
      @9SMTM6 Рік тому +1

      The thing is that the author doesn't really make it clear what he's doing.
      He actually has a text in the beginning that says that he reimplement OOP with "FP" (if you can call it that), but that's just the picture description. Not part of the main article🤦.
      The intro is a meandering mess that's not at all connected to the rest of the article, unless you're looking VERY close and know a lot more than rhar article shows (LISP having closures AFAIK and apparently being the language where "object" was coined, presumably they did something similar).
      Also the author does all kinds of stuff that just doesn't make sense even with the aim you're suggesting. Perhaps I'm missing the purpose for some of them, but I've a really hard time finding it, so either don't do it or explain it.

  • @igrb
    @igrb Рік тому

    That bit about referencing a function x creating a new one was so instructive, thank you

  • @r4s3
    @r4s3 Рік тому +9

    Oh my godness, this blog post is going into my cringe folder. How did he manage to make such an easy to read function into such a mess? Impressive.

  • @Eloii_Xia
    @Eloii_Xia Рік тому +1

    The keywords 'get' and 'set' are more than enough. That's why we implemented them in JavaScript...

  • @FlaviusAspra
    @FlaviusAspra Рік тому +6

    When Alan Kay says message passing, he means calling methods: an object sends a message to another object by calling one of its methods. If the method has no parameters, it's just a signal. Otherwise the tuple of parameters is the message, thus message passing.
    Please understand the people and their historical context when trying to understand what they were saying.

    • @freesoftwareextremist8119
      @freesoftwareextremist8119 Рік тому

      Message passing is the idea, not the implementation. Early Smalltalk was actually implemented in terms of message passing, but was later changed to method invocation for performance reasons. For the programmer though, it looks like message passing. Similar story in Lisp, where early OO-Systems like Flavors were implemented using message passing, which didn't perform well and was also awkward to use (how do you pass such a call to "map"?) and so modern CLOS uses the method invocation approach. And although CLOS does not use message passing syntax either, it actually somewhat has a concept of a "message", messages being just generic functions. A concept which interestingly doesn't exist in JS, Java or C++.

  • @JimWitschey
    @JimWitschey Місяць тому +1

    What's the punchline Douglas. WHATS the PUNCHLINE, DOUGLAS

  • @tsalVlog
    @tsalVlog Рік тому +1

    watching this explanation was like going back in time to the late 90s / early 2000s through JavaScript de-evolution.

  • @michaelmueller9635
    @michaelmueller9635 Рік тому +5

    @ThePrimegen PLZ go for all and every coding exercise of the SCIP book (Structure and Interpretation of Computer Programs).
    You can make a whole series about it, high content quality guarantied. It will open a whole new world and view to programming.

  • @wadecodez
    @wadecodez Рік тому +6

    My program works because the syntax looks good. 1.6k claps

  • @salvadorroibon
    @salvadorroibon Рік тому +1

    I almost blackout with that space between the function and it's name. JSML sound so fun, lol.

  • @elia5562
    @elia5562 Рік тому +3

    The title should be "how to recreate the prototype chain"
    The returned closure is just the "getter"

    • @ThePrimeTimeagen
      @ThePrimeTimeagen  Рік тому +1

      How I Create The Prototype Chain in 3 simple steps!

    • @yjlom
      @yjlom Рік тому +1

      well yeah as far as I can guess it's just a demo of how classes work under the hood in scripting languages
      the same way I could write c++ with typedef struct Class {void *(*vtable)(void *); ...} Class;
      not useful in real code but makes for an interesting demo

  • @markasena
    @markasena Рік тому +1

    We all wasted 18mins of our lives! , I feel your pain going through the article.

  • @cherubin7th
    @cherubin7th Рік тому +3

    I don't think the article suggests to use this, and instead it is trying to teach the deeper meaning of OOP by showing it as functions. Like the Turing machine in Minecraft videos.

  • @lucasmontec
    @lucasmontec Рік тому +1

    Function creation in runtime can get way more expensive than just stackframes. They can be entire objects on various situations.

  • @BreytnerNascimento
    @BreytnerNascimento Рік тому +2

    What happened with the simple, readable, easy to maintain etc function from the beginning of the article? Why did they mangled it this way?

  • @RicardoValero95
    @RicardoValero95 Рік тому

    This was great, I love frustration sharing.

  • @MaxPicAxe
    @MaxPicAxe Рік тому +1

    The article actually looked promising originally until it rapidly spiraled into an absolute mess.

  • @BulbaWarrior
    @BulbaWarrior Рік тому +6

    The point of the article is not to show example if good code. The point was to show the connection between FP and OOP by implementing classes with functions and functions only. One of the implications is that if you have a cool feature in OOP you are guaranteed to be able to implement it in FP as well and vice versa.

    • @airkami
      @airkami Місяць тому

      They even mentioned in the conclusion it was humble. But they also mentioned multiple inheritance

  • @KaneSwartz
    @KaneSwartz 8 місяців тому

    This reminds me of that clip where the guy does the complicated milk carton technique and then it just spills everywhere

  • @jorios550
    @jorios550 Рік тому

    I love it, I'll use it everyday from now on

  • @JoeHacobian
    @JoeHacobian Рік тому

    I love watching Prime freaking out at the “dys-functional” FP crowd. Where have you been the last 9 years!!!?

  • @ovi1326
    @ovi1326 Рік тому +1

    I paused the video to learn more about Smalltalk, and yes, the author implements a basic ad-hoc Smalltalk runtime in Javascript. However - Smalltalk messages are just methods. There's no point in doing it this way since JS already has that feature. Also now that I understand Smalltalk's deal, C++ and Java do the same thing but using vtables instead of messages under the hood and that's great because it's usually faster to lookup an address of a function in a statically known precomputed set of vtables than to do a recursive dynamic lookup through said vtables. Meaningful usecases for messages as the dispatch mechanism are if you plan to break ABI between dynamic libraries and still want to keep legacy components (Objective-C does that) or in asynchronous multi-threaded environments (Elixir does that). It's just unnecesary to incorporate it to something like JS where there's no ABI, everything is single-threaded, and if you're doing RPC you'd probably like the tooling to implement message passing for you. I'm confused.

  • @pixtweaks393
    @pixtweaks393 Рік тому

    9:02 Literally that's me reviewing code "What the hell that means" and "Stop it".😆 Thanks for idea that "I would fistfight for..."

  • @marhoonothoja4144
    @marhoonothoja4144 9 місяців тому

    How to ensure a project is unmaintainable. This is the purest form of chaotic evil😂😂

  • @mage3690
    @mage3690 Рік тому +1

    I'm new to programming. I'll still be new to programming for the next 5 years, because the more I learn about OOP, the more I just don't get it. What's the point? What's a class? What's an object? What is the entire nuclear family doing with their generational wealth, and why does the oligarchy even exist in my CPU? WTF is polymorphism, and do they also attend swinger parties?
    I keep picking up tiny little bits via osmosis just by watching videos like this, and every time I do, I conclude that the only reasonable solution to any programming problem is return to monke (AKA procedural), apes together stronk, and maybe eat the rich to get the oligarchy out of my CPU. I don't get functional programming either, but when you say "functional programming was created as a reaction to how bad OOP is" I can definitely understand why I would subject myself to the mental gymnastics required to learn Haskell. And, the more I learn, the more I thank God that my deep contrarian streak caused me to reject OOP outright, _because_ it was popular.

  • @HiMyNameWaffy
    @HiMyNameWaffy Рік тому +7

    I'm going to assume the `let _grades = grades` is probably a habit he developed from other functions that would mutate the function parameter. Also he's never mutating _grades, why not const? 😕
    Edit: Could also be a habit from a different language? E.g. Declaring a private property with underscore?

    • @GamingMad101
      @GamingMad101 Рік тому +4

      The best part is that, if it's a type that will be copied by doing that, it's passed by value anyway.
      And any types (for example, an array of grades) passed in, will be passed to that variable by reference, so it literally does nothing.

  • @whywhatwherein
    @whywhatwherein Рік тому +2

    ahah Fully agree with the initial opinions about Medium. Imagine being a blogging company known for low quality posts!

  • @m4rt_
    @m4rt_ Рік тому +4

    1:00 Simula was the first language with OOP, not Smalltalk

    • @Tempus0
      @Tempus0 Рік тому

      Glad I'm not the only one who reacted to the article getting this part wrong. The only time I used Simula was in a class at the University. Not a bad language for it's intended purpose, writing simulations.

  • @Talk378
    @Talk378 Рік тому +4

    This is basically what Crockford recommends in JavaScript the good parts. The revealing module pattern, if I recall.

    • @alexk.7064
      @alexk.7064 Рік тому

      Didn't he explicitly say never to use class and that it's one of the worst newer additions to JS?

    • @Talk378
      @Talk378 Рік тому

      @@alexk.7064 more or less, yes.
      ua-cam.com/video/PSGEjv3Tqo0/v-deo.html#t=1395

  • @muxahuk1214
    @muxahuk1214 Рік тому +4

    Someone, quick, tell author of that article that there's a new feature in javascript - prototype's!!

    • @vukkulvar9769
      @vukkulvar9769 Рік тому

      Their mind will be blown!
      Imagine this, instead of
      carlos("get-best-grade")
      carlos("get-best-grade")()
      They can do
      () => carlos.getBestGrade()
      carlos.getBestGrade()

  • @pesterenan
    @pesterenan Рік тому +1

    I'm new to programming in JS, and the final implementation sounded confused as hell...
    It would be cool if Prime coded a better example about why that was bad right on stream, I would enjoy watching that!

  • @aziz0x00
    @aziz0x00 Рік тому

    This is most fun video eveeeer!!!!

  • @benjaminsanglitan7927
    @benjaminsanglitan7927 Рік тому +1

    It's similar to a reducer in the react ecosystem.
    The message can be a discriminated union to make it work with typescript which helps if we want to make exhaustive checking if we want to make sure all types of messages are handled. Also, with the discriminator, we can now infer the contents of the message correctly.
    But it doesn't mean that we can make it work then we should do it.

  • @ToBeardOrNotToBeard
    @ToBeardOrNotToBeard Рік тому +5

    Idk Erlang has been around for a long time now and does this properly. Why this is being done in JS is beyond me. Just do it in Erlang, or even elixir.

  • @alexandrep4913
    @alexandrep4913 Рік тому

    I've used inheritance with actual benefit when I made a radix tree that finds me a hierarchical answer and it allowed me to speed up the program. Yet it's a tree and not oop in the sense that we think of it as.

  • @guyindisguise
    @guyindisguise Рік тому +2

    I think the author of the article didn't want to show actual practical code, but rather just talk about the original idea of OOP which is message passing (this was somewhat hinted at in the first 2 paragraphs but could have been explained better) and for some reason (too much coconut-oil? not enough coconut-oil?) decided to demonstrate how one would implement that concept in a functional style (for real though, I guess the reason was to reinvent something familiar in an unfamiliar way to really show how it works).
    And I guess Prime was looking for something cool/practical so expectations were mismanaged.
    I might be totally wrong though, but I'm not afraid of being wrong on the internet anymore!

  • @mattstyles4283
    @mattstyles4283 Рік тому

    The suggestion of implementing multiple inheritance at the end surely shows it's a meme

  • @voidwalker7774
    @voidwalker7774 Рік тому +4

    Functional OOP? You mean when you only have 2 to 3 classes and the rest is functions and data?

    • @stsam63
      @stsam63 Рік тому +1

      this to me is the direction OOP should go, because sometimes it just really makes sense to have a class because having a complex object with certain functionality is great, but other times you end up making classes to just be able to put functions in them

  • @nickharbinger6839
    @nickharbinger6839 Рік тому

    Javascript and Typescript both already have Message based OOP built in.
    class Name extends EventHandler,
    The entire article is a Rube Goldberg implementation of an EventHandler.

  • @user-fp6dp1ux8s
    @user-fp6dp1ux8s Рік тому +1

    that's some nice ass editing right here

  • @l3p3
    @l3p3 Рік тому +1

    8:06 I also thought that for a long time. Actually, modern js engines do not recreate them but just compile them once and return an alias bound with the context. So there is no issue of "creating" millions of functions in a loop, it behaves just like creating millions of small structs.

    • @ChillAutos
      @ChillAutos Рік тому

      Thats what im confused about. I thought the function created and returned by a closure was only created once. Then that just uses the function reference to execute it. Can someone else chime in here and let me know what's actually happening?

  • @TechBuddy_
    @TechBuddy_ Рік тому +6

    Want Typescript to work with this mess, here's an example ( please please don't do this in real code PLEASE )
    type Messages = 'do' | 'not' | 'do' | 'this'
    function shit(msg: Message) : Message extends 'do' ? () => false : Message extends 'not' ? () => 'yes' : ...
    If you do this the TS language server dies of cringe basically

    • @CYXXYC
      @CYXXYC Рік тому +1

      sounds like a ts language server problem

    • @ThePrimeTimeagen
      @ThePrimeTimeagen  Рік тому +5

      i am a fan of cringe deaths

    • @TechBuddy_
      @TechBuddy_ Рік тому

      @@CYXXYC The TS language server is slow and unreliable as it is and if you start doing this it just blows up

    • @CYXXYC
      @CYXXYC Рік тому

      @@TechBuddy_ ah just like any other microsoft product (assuming ts is all microsoft)

    • @TechBuddy_
      @TechBuddy_ Рік тому

      @@CYXXYC exactly yess

  • @sanjeevmaharjan9795
    @sanjeevmaharjan9795 Рік тому

    the thumnbnail had me so dead 🤣🤣🤣

  • @igordemetriusalencar5861
    @igordemetriusalencar5861 Рік тому +20

    Definitely, Functional programming is my choice!!! Elixir has been around for 10 years on top of beam (erlang from 80) and it is one of the best languages with a 'message' passing concept!

    • @ThePrimeTimeagen
      @ThePrimeTimeagen  Рік тому +43

      agreed, but its a language designed around a concept, not a concept shoehorned into a language ;)

    • @sircalvin
      @sircalvin Рік тому

      @@ThePrimeTimeagen javascript unfortunately gets concepts shoehorned into it quite a bit, because its the only browser-side language. i hope wasm can eventually take over and solve this

    • @Qrzychu92
      @Qrzychu92 Рік тому

      if only Elixir wasn't dynamically typed...

  • @FourOf92000
    @FourOf92000 4 місяці тому +1

    I _think_ he was trying to explain how to use FP with closures to do OOP things, not using this in real production code
    ...I _think._
    ...I hope.

  • @lasoloz6972
    @lasoloz6972 Рік тому

    I absolutely love that the author managed to reference the hero image from a different webpage, but didn't reference anything about the Alan Kay's message sending idea. _Priorities_

  • @nightshade427
    @nightshade427 Рік тому +1

    ruby style message passing within js is what it looks like the author was going for, which is odd since there are better ways in js to do this like using Proxy

  • @ClaudioBrogliato
    @ClaudioBrogliato Рік тому

    @2:51 I think it's ideal when the system simply ignores unmapped messages, so that a 404 response is part of the protocol you decide to implement and not an imposed by the language. 6:37 not a surprise that a book titled: "Javascript, the good part" exists.12:01 wow, that looks like an actor on Erlang. What a nice combo: Erlang + Js.

  • @AndrewErwin73
    @AndrewErwin73 Рік тому +1

    Technically, Simula was the first OOP language (early 1960s), developed in Norway.

  • @robgrainger5314
    @robgrainger5314 10 місяців тому

    In Smalltalk, if an object receives a message it does not understand, it results in a "doesNotUnderstand" message being sent to the object, which has an implementation in class Object that can be the fallback if not overridden. Typically, this invokes the debugger (allowing the user to define a method to respond to the message)

  • @gaeel330
    @gaeel330 Рік тому

    I feel like this is someone who saw a neat little idea about how you can reimplement OOP concepts in a purely FP language, but didn't really understand the idea, and also doesn't use a purely FP language, but decided to write an article about it anyway.

  • @rianfuro4088
    @rianfuro4088 Рік тому

    What blog-post-author does not grasp is that a member function call is THE SAME THING as passing a message to that object (a synchronous one to be exact). What he did was basically just circumvent language-level concepts to achieve the same thing. Nice for getting a general feel about what it means to send a message, but that's about it...

  • @vencler
    @vencler Рік тому +1

    Prime, with all the hate of Javascript, what is your approved way of doing front-end webdev programming? Language/lib/framework?

  • @tokiomutex4148
    @tokiomutex4148 Рік тому +5

    I don't care what paradigm you use as long as you use me.

  • @IanRiley915
    @IanRiley915 Рік тому +1

    I'm really disappointed that the article didn't go into dispatch. I just don't understand why it ended where it ended with encapsulated state, dynamically created function objects, and mapping string literals to other dynamically created functions, when this is exactly what modern OOP languages already do, but better with classes and named methods. The article even started with notion that message passing can lead to decoupling and then went on to create the very coupled code that they were supposedly contrasting message passing to. There are lots of amazing ways in which OOP can be utilized and this is not one of them.

  • @nilox94
    @nilox94 Рік тому +6

    I'll be really concerned if this video gets shorter than 1.6K likes.

  • @nomoredarts8918
    @nomoredarts8918 Рік тому

    He is trying to reinvent the wheel, ending up with cube...

  • @sanjarcode
    @sanjarcode Рік тому

    I get that JSON screaming.

  • @kadensharpin2156
    @kadensharpin2156 Рік тому

    I spat my food out after seeing that switch block

  • @matiasbpg
    @matiasbpg Рік тому +1

    I feel the whole point of message passing was missed. The author must have had a very confused mind at that moment

  • @delicious_seabass
    @delicious_seabass Рік тому

    Article title should be "OOP is bad, here's something worse".

  • @MrAlanCristhian
    @MrAlanCristhian Рік тому +1

    There is two types of people, those that love OOP, and those that not program in python.

  • @rain_deer
    @rain_deer Рік тому +2

    You missed the point, I can't blame you though since the article doesn't even know what it's about.
    This is just explaining how you can encode objects with closures. The big take away should be a closure is equivalent to an object with 1 method.
    Doing this in a language with native support for objects just confuses the lesson though, should have done this in lisp or haskell.

  • @raianmr2843
    @raianmr2843 Рік тому +1

    I think the real issue here still remains unstated. I see this everywhere I go: 1) most people talking about functional JS don't understand functional programming, like at all. And 2) seeing this whole debate through the lens of a language like JS is a mistake to begin with; languages DO matter when it comes to programming paradigms. Most "functional JS" code is just OOP replication using closures. This is possible because JS (or even TS) doesn't really have immutable closures. Closures don't work anything like this in real functional languages i.e the ones that promote pureness. So, it makes zero sense to call code that looks like this functional. The JS world seems to be have taken a wrong turn at some point and ended up in a completely different corner of the programming landscape, where so many things bleed mutability that the simple act of using functions looks passable as FP. It's like how in the US you get to be right-wing af in every axis possible and still pass as a lefty. The React world is the biggest offender imo. Hooks are quite literally just a way to achieve what you would with objects for functions -- internal, mutable state. And yet, almost everyone seems to be convinced that rewriting code that uses class components into function components automagically makes their code functional.

  • @3_14pie
    @3_14pie 5 місяців тому

    Oop is the best paradigm for gamedev, functional needs a lot of workarounds

  • @xwtek3505
    @xwtek3505 7 місяців тому

    Anyone that claimed polymorphism is an OOP concept have never coded in Haskell, where typeclass (a trait-like construct) is very heavily used