Dear Functional Bros | Prime Reacts

Поділитися
Вставка
  • Опубліковано 6 лют 2025
  • Recorded live on twitch, GET IN
    / theprimeagen
    Reviewed video: • Dear Functional Bros |...
    By: / @codeaesthetic
    Become a backend engineer. Its my favorite site
    boot.dev/?prom...
    This is also the best way to support me is to support yourself becoming a better backend engineer.
    MY MAIN YT CHANNEL: Has well edited engineering videos
    / theprimeagen
    Discord
    / discord
    Have something for me to read or react to?: / theprimeagenreact
    Kinesis Advantage 360: bit.ly/Prime-K...
    Hey I am sponsored by Turso, an edge database. I think they are pretty neet. Give them a try for free and if you want you can get a decent amount off (the free tier is the best (better than planetscale or any other))
    turso.tech/dee...

КОМЕНТАРІ • 756

  • @asdqwe4427
    @asdqwe4427 Рік тому +515

    Yes, at the end of the day we all have shared global state. We call it “the database”

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

      @user-tx4wj7qk4t datomic is, most databases are not.

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

      Is this like an argument to something?
      I don’t see how this is relevant.

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

      functional databases I guess can work lol, always making copies

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

      @@fullfungo if you don't see how i/o (inherently having side effects) is not relevant, then you are a fucking idiot and dont belong on this thread

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

      @user-tx4wj7qk4t a simple ledger is an example, no mutation, just adding records

  • @TAP7a
    @TAP7a Рік тому +1047

    “There shall be no state”
    Didn’t know Marx wrote programming languages too, man that guy gets around

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

      isnt that anarchy tho? Marxism loves bug government

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

      😂😂😂

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

      Cant forget the classics like "The conquest of Functions"

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

      More like the subhuman Chomsky.

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

      It would not be Marx, more like an actual anarchist like Spooner.

  • @Telhias
    @Telhias Рік тому +747

    You see... Functional programmers hate transistors. The very idea that a component within your machine can change its state depending on external factors deeply frightens them.

    • @matt.loupe.
      @matt.loupe. Рік тому +55

      Transistors are functional though.

    • @michaelschmid2311
      @michaelschmid2311 Рік тому +68

      Well not after I set my cpu voltage to 2v

    • @0x41f13
      @0x41f13 11 місяців тому +23

      the transistor is a function the leads are inputs

    • @weakspirit_
      @weakspirit_ 11 місяців тому +12

      ​@@matt.loupe. deluded. like actually never understood how transistors are all different depending on manufacturing and environment.

    • @slipperyeel9206
      @slipperyeel9206 11 місяців тому +3

      There is only one solution. If there is ambiguity then that means you have not researched the problem correctly or completely.

  • @peteruelimaa4973
    @peteruelimaa4973 Рік тому +53

    *Pets LINQ*, "See they like you, they just don't know you!"

    • @ytnathandude
      @ytnathandude 8 місяців тому +3

      linq is poggers

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

      You know Erik Meijer distanced himself from functional programming including LINQ recently?

    • @peteruelimaa4973
      @peteruelimaa4973 8 місяців тому +2

      @portal_narlish3710 so what? Cat Stevens distanced himself from his old songs too, yet they're still amazing

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

      LINQ makes my .NET job significantly more enjoyable

    • @AdroSlice
      @AdroSlice 3 місяці тому +1

      The funny thing about LINQ is that the actual language is pointless, but the generic manipulation functions it provides for any enumerable are suuuuuuper useful.

  • @Satook
    @Satook Рік тому +116

    At 12 mins. It is currying and currying is not quite the same as partial application. Currying is where multi-argument functions are instead represented as a sequence of single argument functions that return a new single argument function until all arguments are provided, then the last one returns a value.
    So f(a,b): -> c would instead be
    f(a) -> (f(b) -> c).

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

      Yeah, I would say the use of .bind is partial application as it allows for passing multiple initial arguments and returns a new function which wants the remainder arguments.

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

      yep, thats why haskell type signatures look like:
      foo :: a -> b -> a
      and not something like
      foo :: a, b -> a

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

      ​@Satook why is this good though?

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

      @@Tigregalis Currying (one argument at a time) allows you to partially apply a function, which makes things a little bit easier (especially when the language supports them). For example, the function "userIdEquals" from the video, if curried, it'd be called as "userIdEquals(userId)(receipt)". This means we can then use this function partially applied as: "receipts.filter(userIdEquals(userId))", which saves as the trouble of creating an intermediate function: "receipts.filter((r)=>userIdEquals(userId,r))".
      In languages like JS, curried functions can be cumbersome, because each arguments has to be wrapped in parentheses. But languages like Haskell don't have this trouble: you can call the function with as many arguments as you want -- give them all and you'll get the result; provide the first few, and you'll get a partially applied function that's waiting for the rest.
      Hope this helps!

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

      @@DavidAguileraMoncusi that actually does help. first time in my life i've understood the benefit, specifically using it to avoid an intermediate function

  • @tepumasutasauno8671
    @tepumasutasauno8671 Рік тому +157

    Currying is not partial application) It is splitting function of multiple arguments into sequence of functions of 1 argument. This is currying, meaning we don't need functions with arity greater than 1
    Btw, we also don't need variables, because we can have functions with 0 arity returning constant value

    • @HrHaakon
      @HrHaakon Рік тому +40

      Which is incredibly helpful if you're in academia and need to prove things, because your proofs become easier since it's all just unary functions.

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

      @@anon_y_mousse
      Just memoize the results and you can reuse them! :p

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

      @@anon_y_mousse in the real world you must prove correctness too. But of course CRUD coders won't ever get anywhere close to applications that need this kind of rigour.

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

      @@anon_y_mousse and reducing the implementation to pure lambda (or, even better, combinatory logic) is one of the easiest ways to prove things. Luckily, nothing stops you from doing it with even a pretty heavily imperative code. But as an intermediate representation, a curried CPS is one of the most powerful and easy to reason about forms. Your source language does not really have to support currying, it's all down to intermediate representations.

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

      @@anon_y_mousse I mean, it becomes a stylistic choice at the end of the day. You give up varargs for seamless partial application. Otherwise the curried languages, Ocaml and Haskell being maybe the most famous, have both pretty decent performance and are pretty quick to develop in.

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

    For curiosity about tips (16:40), in Brazil it is common that restaurants auto calculate a 10% tip. You can either pay or not pay it, but basically nobody will tip a different value

  • @petrus4
    @petrus4 Рік тому +45

    This video was a classic bait and switch. The initial French kiss, followed by repeated kicks in the stomach.

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

      Better than repeated sack taps

  • @thomassynths
    @thomassynths Рік тому +107

    For clarification on "curring" vs "partial application". They are related but distinct. While curring _yields_ a new function that implicitly _supports_ partial application, the return value of `curry(f)` is not a partially applied function. No arguments were provided yet.

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

      @@samuraijosh1595 That's not true. It's possible to partially apply arguments to a function without currying the function prior.

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

      a shorthand for currying identification could be if you can do foo()()

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

      also currying is a stricter subset than partial application. as currying is typically understood for use w/LC or rather single arguments in general rather than splitting the input domain N times, which currying does for N arguments

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

      @@shampoablewell thass wild, i do that in JS all the time juss cause it’s more intuitive to write if returning a function is what i’m doing. neat.

  • @hoodiegal
    @hoodiegal 11 місяців тому +10

    I'm a hobbyist programmer and I've only got experience working with procedural and object oriented programming. This stuff is mindboggling to me. I can clearly see that it works, but I do not understand how the heck it does. It's like I've been building houses using nails and screws all my life, and then someone shows up and tells me about wood joining and shows me that you can build a whole house without any screws or nails. I can clearly see that you put a house together, but I have no idea why it's not falling apart.

  • @MeriaDuck
    @MeriaDuck Рік тому +98

    More languages than just haskell (and other 'pure' functional languages) should implement tail recursion optimization. That is a strategy that does not create a stack item for a function call when it is the last thing in the function, and is a recursive call to itself.
    Java for instance does not do that and the call stack for the recursion becomes too large after a few thousand. So implementing a loop the recursive way leads to trouble.

    • @silentobserver9095
      @silentobserver9095 Рік тому +25

      Tail call recursion optimization was one of the features that was promised in ES6 in JavaScript.
      But sadly only Safari implemented it... Which is surprising to say the least. Chrome, Firefox and others never really implemented it.

    • @awesomedavid2012
      @awesomedavid2012 Рік тому +28

      Kotlin has a tailrec keyword that enforces a function is tail recursive and performs this optimization

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

      @@awesomedavid2012 cool! Didn't know that. Maybe Java will get it in a dozen years too then 🤣

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

      Many compiled languages already do this optimisation, though it usually isn't 100% guaranteed (as with a lot of other optimsation techniques)

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

      F yes, tail call best call :)

  • @KevinPfeifer
    @KevinPfeifer Рік тому +32

    Its cool that functional programming is explained with the usecase of map, filter, sort and slice but looking at what is being done at 21:20 it feels to me like all of this should have been done on a database level in the first place. map => join | filter => where | sort => order by | slice => limit
    Then you don't need to fiddle around in JS and waste a bunch of time and memory doing stuff in JS which should have been done in SQL (or an appropriately designed API)

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

      Yep! Database queries are one of my favourite examples of functional programming. I'd argue you need to be a bit careful, as they can be hard to test/verify and SQL is honestly not that great and has pretty poor IDE support, but you can get a lot done before you ever send the data out over the network.

  • @thomassynths
    @thomassynths Рік тому +251

    The sad thing is all these coding youtubers only understand surface level stuff about FP. It's not actually all about pure functions and such. It's all about explicitly modelling computation.

    • @ericb7937
      @ericb7937 Рік тому +233

      I look forward to your youtube video expanding on these concepts

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

      @@ericb7937 I've honestly been toying with the idea of making some tech videos on youtube. Perhaps sooner than later.

    • @sfulibarri
      @sfulibarri Рік тому +89

      Cool story functional bro

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

      You just gotta learn Clojure to get it

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

      ​@llIlllIIlIIlllIlllIlIt has been my observation that almost all coding youtubers (who are not overtly obsessed with FP) think they understand FP after only learning: Pure functions, no side effects, const variables, recursion. I mean those are all features of FP for sure, but that is not the pull of FP. In fact many imperative languages have these features. In fact us functional programmers go out of our way to explicitly put state into our code! FP is NOT about avoiding state. The magic of FP is that a good FP language (such as Haskell) allows you to explicitly model both data and computation flow in concise and well-defined ways. I won't go into the details here, but I have heard the phrase "monads are a programmable semicolon". IMO this is rather accurate. Imagine you were writing a function in your favorite C-syntax language and you could program implicit code specific for that given function to be ran in between every expression. It's rather powerful stuff.

  • @janerikjakstein
    @janerikjakstein Місяць тому +5

    YOU GIVE YOUR CREDIT CARD TO THE RESTAURANT AMERICANS? WTF?

  • @CTimmerman
    @CTimmerman Рік тому +61

    Recursion is a dangerous form of iteration that can overflow the stack if it's not being tail call optimised.

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

      And the worst part in case of errors the call stack is completely useless without first (which started the whole chain and holds initial value) and the last (the reason for the error) calls.

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

      And a loop can run out if memory if there is no garbage collection.
      How is this any different?

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

      @@fullfungo Just clean up when needed, which is easier to handle than a recursive control flow.

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

      ​​@@fullfungo it's infinitely easier to debug and you can easily Tell when you run out of memory in a loop. because you get a Seg Fault or malloc can't get any new memory instead of Stack Overflow with the stack trace pointing to one function. Using the program stack like this is just not a good idea.

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

      @@fullfungo And this is one reason why I love RAII, though, as the_mandrill suggested, it should probably just be called Scope-Bound Resource Management (SBRM)

  • @lethicanthus
    @lethicanthus Рік тому +76

    There is state, it's just explicitly passed around instead of hidden by class variables and global mutables.
    I wrote this on the original, but the issue with using functional techniques in a language like JavaScript is that
    A) The language doesn't have tail-call optimization and therefore recursion blows up the call stack
    B) Sometimes, functional languages are able to support loop fusion where, in the pipeline example, all the steps happen in a single loop instead of iterating multiple times.

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

      I always wondering how this kind of approach (the currying, multi-step-loop functions) would affect performance. Thanks for addressing this concern.

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

      fwiw re: B) - you can easily build transducers in JS (or use a library), which allows you to write declarative transformations but avoid a bunch of additional loops/instances.
      To me one of thing I hate about FP with JS is that there isn't currying by default (again, you can supplement with libs), which makes the whole thing feel super un-ergonomic. It makes composition harder and less intuitive, which makes small, pure functions feel less valuable. FP techniques synergize in a really satisfying way, so when you have to do all this extra leg work to enact them, of course it feels like going all in on FP is a pain.

    • @gunt-her
      @gunt-her Рік тому +1

      The other issue is when you work in embedded and you have to modify state in place because of cpu and memory constraints.

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

      JS(ES6) does have TCO its just that V8/Firefox doesn't support it.

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

      @@mixed_nuts then it doesn't. A standard without an implementation is like saying I have a PhD from MIT because I can see their outline of their PhD program online.

  • @TazG2000
    @TazG2000 10 місяців тому +4

    21:00 The standard javascript library is the problem here. These functions SHOULD accept and return iterators (where you can dump it back into an array at the end if you need to). Still, you don't really need to break up the code to debug this though. You could start by stepping through the "map", then remove that breakpoint if you are satisfied there are no bugs there, skip ahead to "filter" and so on, until you find a bug.

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

    Learning Haskell as basically my first language (C++ was my actual first, but I quickly grew disinterested in the language). Has caused quite an interesting learning journey.

  • @catchychazz
    @catchychazz Рік тому +31

    IMHO, nothing beats Scott Wlaschin's conference lectures on "Domain Modeling Made Functional" and "Functional Design Patterns" for introducing functional programming in a really intuitive way.

    • @giorgos-4515
      @giorgos-4515 Рік тому

      came here to say this, glad someone is also on board

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

      Yes! Are you also one of the 5 F# programmers?

    • @giorgos-4515
      @giorgos-4515 Рік тому

      @@mciejgda88 not yet unfortunately, but i have almost read all of the articles from Scott's blog. I want to do as an experiment the domain modelling with F# thing in a real context with domain experts

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

      I also got owned by reverse last week. Totally forgot it mutates arrays

  • @dv_thai
    @dv_thai Рік тому +84

    I agree that functional programmers are bad marketers because, somehow, they make this guy think about FP as “There Shall Be No State”. This is hilarious 😂

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

      Seems to me like it's more about reducing the use of state and trying to make sure its impacts are known when it does get used. I'm just starting to look into it but those are the benefits I'm seeing right out of the gate.

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

      Yes of course there is state..it is just immutable. So once you alter it, you just get a new copy. The copy is smart though, nothing like Rust's "Clone"

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

      @user-tx4wj7qk4tAnd they are a whole lot easier to test

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

      @@ragnarok7976 sort of, but to be clear there isn't any "more" or "less" state in FP. The fundamental state of a program or app has to exist regardless of how it's represented. It's more about where that state lives and is consumed.
      I think the bit on state was confused and misconstrued with reducing (but not "removing" which was the implication) side effects which are entirely different concepts, not the last of which is totally misrepresented in this video, but is similar in that FP intends to manage how side effects occur in a different way than other paradigms.
      I agree with the other commenter - THIS is the bad marketing, people who don't fully understand FP's goals explaining why it "sucks".
      Real FP bros market FP not as this "hurr durr warm the room do nothing useful" thing, but to the contrary as a paradigm to side effects. Eric Normand (someone Prime has trashed in other videos) describes FP simply has organizing programs into two buckets: easy stuff - calculations and tranformation logic that can be represented as pure functions, and effectful logic - the "hard" unwieldy parts of a program. FP simply aims to separate those buckets much more than other paradigms, and thus is inherently side effect friendly than other paradigms.

    • @volbla
      @volbla 2 місяці тому

      I recently watched Tsoding write a json parser in "111 lines of haskell", and i honestly don't think it had any explicit state. It was just a bunch of definitions of types and functions, and making sure those functions followed certain rules.
      I guess a json parser isn't very complex, but i think it's the only practical demonstration i've seen of haskell, so you could fool me that FP is all about eschewing state 🤷‍♂️

  • @BudgiePanic
    @BudgiePanic Рік тому +88

    Everybody gangsta till the recursive "iteration" blows up the stack and ravages the heap

    • @ultru3525
      @ultru3525 10 місяців тому +25

      that's what tail call optimisation is for

    • @mitchhudson3972
      @mitchhudson3972 9 місяців тому +4

      ​@@ultru3525 that's a lot of bs to simply use a branch instruction

    • @ultru3525
      @ultru3525 9 місяців тому +3

      @@mitchhudson3972 yes every single assembly-level instruction is simple by itself, but once you start combining them to actually do something noteworthy, there is a point where the simple instructions start becoming exponentially more difficult to understand than the bs, or abstractions as they're more commonly called.

    • @mitchhudson3972
      @mitchhudson3972 9 місяців тому +12

      @ultru3525 in no universe will a for loop be more complex or difficult to understand than a bunch of recursion. With performance at best it just ends up being the same thing and at worst blows up your stack

    • @ultru3525
      @ultru3525 9 місяців тому +1

      @@mitchhudson3972 Sure, if you ignore the entire history of formal mathematics. Why do you think ancient mathematicians defined the Fibonacci sequence using recursion instead of a for-loop? Because recursion is the mathematical approach which is modelled by human reasoning. For-loops OTOH only came into existence when we needed to translate our reasoning into something a smarter-than-average rock can work with.

  • @dberweger
    @dberweger Рік тому +15

    🎯 Key Takeaways for quick navigation:
    00:00 🎉 *The video starts with a discussion about functional programming and the term "functional bros."*
    02:10 💡 *Functional programming emphasizes pure functions without side effects, making it elegant and predictable.*
    03:44 🧐 *Functional programming eliminates mutable state and relies on functions to compose and manipulate data.*
    06:04 🔄 *Recursion is discussed as a key technique in functional programming for tasks like looping.*
    09:30 🤔 *The video explores currying and partial application as functional programming techniques.*
    11:35 🧩 *Lambda functions are introduced as a way to create functions that carry extra data for specific conditions.*
    14:58 🤓 *Functional programming methods like `filter`, `map`, and `take` are used to process data in a declarative and concise way.*
    18:10 🔄 *The video demonstrates how to apply functional programming techniques to solve a problem involving restaurant receipts.*
    20:18 📺 *Focus on being actively engaged when watching videos, especially if not live.*
    21:26 💡 *Functional programming allows for elegant data pipelines, which are common in many programming tasks.*
    23:10 🧠 *The best parts of functional programming have been incorporated into popular languages.*
    24:05 🛡️ *Reducing state and using data pipelines can bring significant benefits without excessive restrictiveness.*
    24:44 🚀 *Exploring multi-threading and parallelism in Rust can lead to improvements in performance.*

  • @womiro
    @womiro Рік тому +27

    I am doing a lot of DSP and data processing, and I found myself drawn to the style of creating some kind of "pipeline" since it makes it really easy to understand on a high level what kind of steps a given analysis is going through (much more so than, say, a nested loop with all the interesting stuff going on in the innermost loop).
    Since in Rust / C++, I find myself falling back to good old procedural idioms quite often out of habit, I started to use some F# for smaller scripts and recently Advent of Code, forcing myself to embrace the functional style.
    On the one hand, the code turns out to be quite readable, composing functions feels good, and I have less issues bikeshedding how to organize code compared to an object oriented approach, where there are always multiple ways to split up functionality into different classes, and usually the first choice turns out to be flawed some time down the road.
    On the other hand, I find that the FP style has more "surface area" to learn (knowing as many algorithms / operations available for a given type of container is critical), I find it hard to reason about the performance of certain steps (compared to a procedural style where working with contiguous memory and avoiding copies already gets you quite far, and it's usually obvious when copies happen), and, most critically, the debugger seems really useless.
    So I'm torn. It seems a bit like sugar, some FP style in some places (mainly high-level "business logic"?) is awesome, but in the more involved interna of a codebase, I find that keeping things procedural may actually be better to stay on top of what's going on, at least based on the debugging experience I had so far.
    Ofc it might just be a skill issue at this point.

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

    Functional bros don't even program... they just function.

  • @alberthadonlyone
    @alberthadonlyone Рік тому +29

    Haskell has a special place in my heart because it got me interested in programming

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

      Damn, I can't imagine raw dogging Haskell as a first programing language. Did you major in math?

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

      @@azmah1999 Yes and it wasn't technically my first language. That was Java but I could barely write hello world at that point.

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

      It was my 2nd but it was also the one that got me really into programming

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

      Had Phil Wadler as a professor in first year Soft. Eng. and that was hands down the best, most interesting and fun course. Though everybody else seemed to hate it xD

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

    I like my for loops and you can never take them away

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

    I think he's mixing up Functional Programming and Pure Functional Programming.
    There is a difference.

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

      No he doesn't. 22:50

    • @abuDA-bt6ei
      @abuDA-bt6ei 7 місяців тому

      Does Pure Functional Programming inherit from Functional Programming or the other way around? I think OOP is for your kind.

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

      @@abuDA-bt6ei the other way around

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

    Lol, I commented - as one of the first comments - under the original 'Dear Functional Bros': "This one is going to hit ThePrimeagen hard xD"

  • @JamesJones-zt2yx
    @JamesJones-zt2yx Рік тому +9

    Haskell Curry realized that all you need is functions with one argument, as long as you can return a function. (Moses Schoenfinkel realized it first, but you and the guy with the video would REALLY complain if you had to talk about schoenfinkeling a function.) Haskell notation is designed to make it easy to schoen...uh, curry.

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

      On the other hand, the programming language Moses probably would be way more popular. To their chagrin!

  • @larjasoul
    @larjasoul 7 місяців тому +1

    The beauty of FP is, it basically takes tons of boiler plate and turns it into many shorthands.
    map (+5) xs
    feels so readable.
    this is of course an incredibly basic example.
    Instead of having to learn/debug your coworker's boilerplate shorthand, you can just learn FP boilerplate shorthand upfront.
    Maybe that FP boilerplate shorthand isn't as readable as plain English. But it reduces your coworkers' boilerplate shorthand by an order of magnitude, which is almost always a win.

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

    This video has convinced me to never consider pure functional programming.
    Thanks saving-my-life-agen

  • @handomize
    @handomize Рік тому +40

    Prime: never gives attention to UA-cam comments doesn't put anywhere that he's doing that
    Also prime: i wonder why I don't have traction on UA-cam.

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

      Well, there is "LIVE AND READ CHAT ONLY ON TWITCH" in the description of his live streams.

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

      @Drazzz27 oh my bad didn't see that

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

      To be fair, I see him respond to UA-cam comments all the time (including myself.) Just not while live lol

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

      Could it also be the content he throws at UA-cam nowadays?
      Reaction video after reaction video, zero original content, just him hitting space on UA-cam videos every second. Like idk, dude’s free to do whatever he wants and he obviously prefers Twitch but it feels pointless to sub to him now. Such a stark contrast to the channel he’s reacting to…

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

      The peak of Prime's UA-cam content was when he was on paternity leave. Dude is a Netflix Engineer™️ and has a few children iirc. He's just busy

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

    "No state" but you use a secret parameter that will influence the result of your nested function.. in other words : State with extra steps.

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

      No. Pure functional programming languages like "clean programming language" for example model the whole universe with no state changes (including the computer memory) - then how you run interactive programs is that both your functional program can create a new universe - then the user as a function also can create a new universe from that - then functions run over it again.
      You need no state this is just recursion with a completely new universe being born all the times haha.
      Then haskell has the other approach with monads - but I find the "Clean" approach to be theoretically cleaner indeed. Fun-fact: Clean and Haskell are nearly fully compatibly even to the syntax level and you could not tell which code is from which - despite the therory and inner workings being so different...

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

      ​@@u9vata
      What you are describing is the theoretical underpinnings of FP, the real implementations dont abide by that.

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

      @@arkeynserhayn8370 What I describe is the SEMANTICS of said languages so real implementations DO totally abide that in both circumstances. Just of course - as every sensible compiler - they optimize whatever they can and whenever possible given the given circumstances when the compiler is good.
      Still this is the programming model that you see when you are coding. There are "not purely" functional languages, where the semantics enable more, but in case of Clean and Haskell the semantics are purely functional.

  • @ThrowAway-t3m
    @ThrowAway-t3m Рік тому +14

    Currying is taking a function that has an arity greater than 1 (n) into a group of single arity functions whose members total n.
    Currying will result in high order functions (but not all HOFs will require you to curry, a function with a callback for instance, can be a high order function but it is not a curry) since high order functions take a function as an argument or return a function

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

      Arity being the number of arguments a function takes for my Dysfunctional bros.

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

      And here I thought he just misspelled parity... I think at the end of the day most people would rather just learn a programming language than relearn English to learn a programming style then learn a programming language to implement it in. That's probably why this stuff hasn't gained more traction.

    • @ThrowAway-t3m
      @ThrowAway-t3m Рік тому

      @@D4ngeresque I can appreciate hyperbole but I think comparing learning a couple new words (which are long standing English words) to relearning English is a bit too hyperbolic for me.
      I thought the same thing when I first saw "arity" but I took two seconds to google it and I now I can understand any text that uses the term. 2 seconds of investment; lifetime of value.
      I'd also add that you will need new language for all new things you learn so this really isn't an inherent issue to FP.
      I'm not saying you need to learn it either just don't avoid it for arbitrary reasons like being novel to you.

  • @Wyklepheph
    @Wyklepheph 11 місяців тому +13

    Saying functional programming “has no state” is like saying math has no numbers. There’s obvious state, you just get rid of as much mutation of state as you can. If there was no state you would have no program 😂. Like, I understand the word isn’t being used to mean EXACTLY that, but still.

    • @watsonwrote
      @watsonwrote 28 днів тому +1

      Lambda calculus doesn't have numbers, which is what a lot of this is built from. But for practicality, yes, we normally want states to solve certain problems

  • @nescafezos4265
    @nescafezos4265 4 місяці тому

    this is not the only way (breaking statements saing stuff into variables) to debug such code (20:40 when it has pipeline of map().filter().sort().slice()), can make a function that takes an array and returns it back (while also sending the array to console.log), and just temporary wrap the portion of pipeline with that function

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

    Rust iterators are such a big win over the JS way map|filter|reduce or implemented

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

      JS has a proposal to add those and many more to iterators.

  • @sealer1675
    @sealer1675 3 місяці тому +1

    23:35 I was forced to use list comprehensions at my previous job and I grew to despise them xD . Sometimes being concise is not better

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

    6:15 the nature of javascript: you don't get error on out of index, you get error on accessing field on null.

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

    If you want to be a true functional programmer, you need to be born this way, because you cannot change by design.

  • @joshuakb2
    @joshuakb2 Рік тому +80

    You don't step through the functional code with the debugger, you test the functional code with different inputs to see where it doesn't do what you wanted it to. Then you break it apart into its smaller parts to understand where you've gone wrong

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

      QuickCheck for Haskell is amazing for this, but there aren’t as many good analogs in other language ecosystems…

    • @ryanleemartin7758
      @ryanleemartin7758 Рік тому +24

      unless it's javascript or some other mutation first language cosplaying as a functional language. Then good luck with that!

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

      @@tuchapoltr you can just use the repl. It's pretty easy to use in both haskell and JS

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

      Indeed! Step-by-step debugging doesn't make sense anywhere except in code executed step-by-step. For simple, pure functions you only want to see what various parts of the call tree evaluate to. More complex types would maybe warrant specialized debuggers tho.

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

      @@ryanleemartin7758 I do this in JS all the time lol

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

    The reviewed video link causes a recursion.

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

    FYI the "reviewed video" link in the description links to THIS video, not the CodeAesthetic video

  • @valcron-1000
    @valcron-1000 Рік тому +9

    I suggest reading "The Curse of the Excluded Middle" to understand why this "using the bests parts of FP" approach eventually falls apart in practice.

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

    @ 2:25 😂❤ "the concepts of a function is so pure... You have this elegant thing that takes in an input and gives you an output..."
    A woman! 😂❤

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

    18:10 You can both call array.sort() to just sort it, but you can also use it in a dot-chain of functions. I call that a win. At least as long as it doesn't actually clone the thing.

  • @sealer1675
    @sealer1675 3 місяці тому

    Whenever I look at the example at 7 min I keep thinking that if there should be no state, we either have to keep copying variables, wasting a ton of clock cycles, or we do actually have the state somewhere (maybe hidden) - cause we need a reference to the array. In any case I keep thinking there must be an easier way to do the same thing.

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

    The great thing about functional programming is that I spend less time debugging multiple issues because I have to spend more time debugging each individual issue.

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

    11:46 Yeah, it is currying, basically if you have a function that does the sum between 2 numbers, gets a number as input, that's the function that does the sum of x + 5 (assuming you passed 5 as first argument) and you specialize the function x + y with y = 5. If you pass both of them in this way (x)(y), you are actually changing both of the x and y. TECHNICALLY what he did it's called closure in python world, but it's the same principle of currying

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

    03:56
    I wonder is "Code oriented: state is code" possible
    no ifs, no loops, but instruction to replace instruction (branchless self modifying code)

  • @BroudbrunMusicMerge
    @BroudbrunMusicMerge 7 місяців тому +2

    Functional programming is like Sigmund Freud's work -- a handful of great ideas that are widely applicable; but if you start digging too deep, it plummets into insanity.

  • @musicaeclectica
    @musicaeclectica 3 місяці тому

    Single or, at most, double loop comprehensions are great! Any deeper and they are an interesting challenge to create but shouldn't be used in production

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

    21:34 he claims breaking the pipeline apart is "the worse" because you can't debug one item at a time. He is strongly assuming the first item in in the iterated version would tell him what was wrong, often you have to look at the entire output to see the issue.

  • @Lord_zeel
    @Lord_zeel 5 місяців тому +2

    Functional programming seems pretty legit until you start intentionally creating new arrays at every step of your recursion. Did we forget about size complexity? You're basically always making it O(n^2) to do things that should be O(n) just to avoid mutation. It's insane.

    • @toucansam7796
      @toucansam7796 4 місяці тому

      Can you give me an example?

    • @voskresenie-
      @voskresenie- 4 місяці тому

      ​@@toucansam7796 90% of the video is one.

  • @TRex-fu7bt
    @TRex-fu7bt Рік тому +2

    currying is turning f(a, b, c) into g(a)(b)(c). partial application is where you create a new function with some argument values pre-set (partially applied).

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

      Do you really need to know the names of them in order to use them though? I think the video was mostly about scaring new people off.

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

      @@georgehelyar Using is second to *reasoning* about the concepts. Without the language and definitions of concepts, how do you convey the meaning and semantics?

    • @TRex-fu7bt
      @TRex-fu7bt Рік тому +1

      @@georgehelyar it’s a programming pattern and it’s good to have a consistent name for the pattern 🤷‍♀️

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

      People use these things all the time without knowing what they are called though. It's just that the names are scary to people who have not heard them before, and that makes people think FP isn't for them.

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

    i really like constexpr functions. like, you reduce state by having something where the output depends only on all inputs (even for constexpr classes, since `this` is a hidden parameter) and you don't have to deal with any of the bullshit with "pure" functional programming such as not being able to mutate local variables leading to things being overly complex and leading programmers to iterate and exhaust stack space.

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

    Funny thing, if you have account with European bank, you are not allowed to let the card out of your sight of you or authorized person when paying with CC/debit (one of those things people don't read when they sign papers) so things like this is less likely to happen.

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

    I’ve just started a programming course and I’m currently making my first JavaScript project. I was worried that I didn’t have any kind of “loop” in my code. I just have functions that call each other when certain criteria is met. The first 7 mins of this video made me feel a LOT better.. am I becoming functional bro?? 😂

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

      f(str)
      return str + " " + f(str)
      f("One of us.")

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

      @@NeilHaskins yeah I wish I knew what that meant 😂❤️

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

      No you are not writing useful code yet.

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

      @@nnnik3595 oh I’m very aware that I am still at the base of mount stupid 😂

    • @dsdy1205
      @dsdy1205 11 місяців тому +2

      Bro discovered callback hell

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

    Typical all-paradigms-are-good take. Software is remarkable among fields of engineering (civil, mechanical, electrical, etc.) in that nothing ever gets taken out. Legacy code and recalcitrance keep every approach in-play along with their defenders, the good and the bad.

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

    The reviewed video is not properly linked in the description.

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

      It never is, which I hate. I always have to google source videos and articles... :

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

      The video link is gay tho?

  • @BJ-sq1si
    @BJ-sq1si Рік тому

    In Haskell, It’s not just because it’s pretty or because it’s elegant or because it’s easier to reason about once you understand it, it’s useful for making increasingly complex programs require less code to write (even under the hood) through the use of generalizations of functions on types and type classes. It’s the low cost or cost free abstractions that allow you to have automatic optimizations that the compiler can now prove using the type system that it wouldn’t be able to make without it. In some cases this even allows optimizations you wouldn’t be able to get writing well written C unless you used inline assembly.
    It literally lets you write more performant programs using less total code asymptotically as you scale. And imo it’s more pleasant to write. And for the record, I love C and assembly. Calling C and assembly in Haskell when generalizations don’t yet exist to get you comparable performance for that specific function is practically standard practice for a Haskell dev when performance matters.

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

    Full agree on the debugging part, exactly that, remove the return at the beginning, make multiple variables and then return it is also how I debug those things.

  • @Remiwi-bp6nw
    @Remiwi-bp6nw Рік тому

    Ironically exactly when he says youtube can be a part of this video this one time, my UA-cam app crashes lol

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

    I watched this video a few weeks ago and just was baffled. This guy clearly doesn't understand FP at all, and that's disconcerting.

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

    Learning F# right while getting a deeper learning of concurrency in .Net. Brain melting.

  • @ryano1267
    @ryano1267 8 місяців тому +2

    All this shit to prevent writing a simple for loop? I don't understand it. It's nice and all, but is it needed? Why can't you have a for loop in a pure function? The state is inside the function so the same input gives the same output? What's the problem here exactly. I just wanna make code that works and is readable and suddenly I'm writing 4 functions, recursion, predicates. Like come on man

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

    Changing state is how you get things done. Heard it here first.

  • @rahuljindal-ik4zv
    @rahuljindal-ik4zv Рік тому

    This is much cleaner and readable until promise are not put into the equation, where things will start to look messy fairly quickly.

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

    You can hear functional programmers break when they see a break.

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

      switch is probably the most inherently functional aspect of most programming languages (aside from functions) and that uses break.

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

      @@valseedianyeah considering it’s pretty close to pattern matching (see Java switch expressions)

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

      @@valseedian I mean, they can't break in the same way normal for loops work in a forEach function, only continue by doing return.

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

    I fucking hate that js is used in the example. The time and space complexity of the code is fucking bad. It's so much worse than just doing it with a for loop.

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

      I think it's a problem with taking functional programming too far /currying. Not the language used

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

      ​@@Jabberwockybirdat 21:00 there are 3 new arrays created. The same code in rust with iterators or c# with IEnumerables would only need to create one.

  • @theboydaily
    @theboydaily 11 місяців тому +1

    I love high order functions. And I love to use them in Go.

  • @hosspatrick
    @hosspatrick Рік тому +12

    F bros don't market the paradigm poorly in 2024. That is just a narrative anti FP people keep trying to push. There are definitely purists out there, but by and large the modern FP community has been fully aware of the intimidation factor associated with many of the patterns in the paradigm, and actively seeks to make the paradigm more accessible by attempting to avoid weird terminology. It can just be difficult to teach around, because those things mean real things, with very specific definitions (we're talking about math after all).
    But with that said, there are undertones of elitism and gatekeeping - you may be picking some up while reading this comment. But I think this is partially due to Anti FP propaganda and miseducation. Most Anti FPers consistently have never actually tried real FP. They've seen stuff like this video where there is repeated misunderstanding of the concepts by the presenters, as they actively downplay the value of said concepts. They've maybe dabbled with concepts in multi-paradigm languages, but have never experienced a true FP environment. Has @CodeAesthetic developed anything from start to finish in a purely FP language? Perhaps, but I wonder.
    Do I agree that you can get value out of FP concepts in multiparadigm languages without going all in? Yes but at best it dilutes that value of the concepts because the guarentees provided by FP are only as strong as the adherence to it's principles, and at worst it forces others working on the code, who aren't motivated by the princibles or concepts, to deal with them, potentially reinforcing the negative stereotypes presented here.
    I'll just say, if anyone is tempted to have a take on FP or F bros, and you haven't ACTUALLY used a functional language, go checkout something simple like Elm to get a real taste of pure functional coding. You may not like it in the end, but I belive you will at least see how using these patterns within a dedicated environment is so much different, and so much more beneficial, and at worst I truly believe you'll come out a better JS (or whatever) programmer.

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

      The take that the FP community "actively seeks to make the paradigm more accessible" is pretty wild. Isn't Haskell's motto "avoid success at all costs"? The problem is that the whole field has married itself to some overgeneral, overabstracted category theory mumbo jumbo that the vast majority of people don't understand -- just look at the wealth of monad tutorials written by people who obviously don't understand monads. And monads are far from being the most complicated idea from category theory in FP!
      If the FP community were truly interested in making things accessible, they'd 1. focus on making Haskell's error messages actually useful 2. improve naming all around (what on earth is supposed to be? ?) and 3. take seriously the concerns brought up by people who aren't onboard with the paradigm instead of dismissing them as "you never did _real_ FP" or some permutation thereof.

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

      @@isodoubIet if you consider that one language to be the end all be all of the entire paradigm, then your point is well taken - but that wouldn't be very fair would it? Check out Elm! It's basically simplified Haskell. No Monads. No needless cat theory in the docs. And literally the best compiler errors I've ever seen.
      I don't mean to dismiss the concerns of people who are taken aback by the syntax and approaches of FP. But at a certain point if folks don't make a concerted effort to to understand - yes, their critiques will eventually be dismissed.
      When ES6 came out, the team I was on had about half of people interested in investing in the new syntaxes, and half feeling really really weary of the unfamiliarity. If you've never used the spread operator before, sure it's hard to understand. All syntax is weird until you learn it!
      I'll just say if you're interested in more pragmatic resources around FP, check out: Elm
      Richard Feldman
      Kyle Simpson's Functional Light FP
      Professor Frisby's Mostly Adequate Guide to Function Programming

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

      @@hosspatrick Haskell may not be the "only" FP language out there, but it's surely the most important one. There are languages that are more "purely FP" than it, but they're largely academic with no adoption, and there are languages with more adoption than it, but they're much more lax and multi-paradigm. Love it or hate it, Haskell is the prototypical example of a pure functional language. You're protesting that people aren't pure functional enough (you also mentioned that _other_ people are purists, which is a tad ironic but I'll let it slide), so surely we should stick to _at least_ Haskell. Elm is clearly not pure functional, right? Monads are kind of required if you want to stick to a pure functional style and still have effects.
      (I also don't do web so Elm is not even solving the right kind of problem for me)
      "yes, their critiques will eventually be dismissed."
      That is a fundamental misunderstanding of the dynamic at play. Functional programming is a niche activity; probably less than 1% of all programmers regularly use a functional language, even an impure/multi-paradigm version. The top functional lang in the TIOBE index is F#, in 26th place with a rating of 0.67%, behind even prolog! So, make no mistake, if fbois want people to check out pure functional programming, it's fbois who have to make pure functional programming attractive to the rest of us. When a decision is made to name a function something abstruse like "LiftM2", or to write a key piece of functionality as a made-up infix operator like or >>=, you're losing people. When your abstractions are so overabstracted that you can't even come up with good names anymore, you're losing people. Ultimately you only win me over when you prove that you can solve my problems better than my current tools can. Dismissing my concerns is not the way to go there.

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

      @@isodoubIet First off to be clear, I'm not advocating against FP in muti-paradigm functional programming languages.. I'm not saying Purely Functional is the only way. I'm saying doing FP in a functional first language is much different than something like JS which merely enables the possibility of a somewhat functional style. FP and as an extension, pure FP, is still a spectrum. There are simply guiding lights.
      Like I said before, there are languages like Elm (btw, we are talking about the overhead of adopting the design patterns, so arguing "that's not my domain, thus FP is still not easily learned" is a stretch), Roc as well as impure stuff that removes much of the barrier to entry like Gleam, OCaml, Elixir, F#, etc. In addition to the languages out there which are motivated to remove much of the academic cruft you complain about, there are plentify learning resources and educators attempting to do the same.
      So yeah, if you continue to respond "but Haskellll" you will be dismissed. This is what I'm talking about. You're just using Haskell as a strawman to argue that FP is an overabstracted mess, when there is plenty of evidence out there to back up what I said about that being a dated argument.

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

      @@hosspatrick "btw, we are talking about the overhead of adopting the design patterns, so arguing "that's not my domain, thus FP is still not easily learned" is a stretch"
      That's not what I'm saying. What I'm saying is that that particular language doesn't fit my needs, so even if it's easily learned, it's not useful for me. My biggest concern, however, is not that it's difficult to learn FP (the general-purpose one, with the monads and all the shebangs). The problem is that it's impossible to teach.
      As for your last paragraph, I already addressed the extant misunderstandings of the dynamic at play here and don't feel a need to reiterate.

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

    11:30 - :O He said the forbidden word.
    How can it have the state bound to it if there is no state?

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

    I remember getting owned by reverse so hard that I memory holed what it was that I did wrong, ensuring I will eventually get owned by it again in the exact same way at some point

  • @_MB_93
    @_MB_93 Рік тому +15

    FP might one day be better than procedural / OOP if colleges start teaching its concept, so the next junior seeing my (beautifully :) written functional code doesn't curse me behind my back

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

      FP has it's uses, but trying do everything in FP is like a carpenter discovering a framing hammer and using it to drive a bolt into concrete.

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

      Hey, at Cornell they teach OCaml in a pretty fundamental course so we're a bunch of closet functional nerds wondering what to do with ourselves!

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

    Currying and partial application are related, but not equal.
    All partial application is currying, but not all currying is partial application.

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

      "All partial application is currying" is false by definition. Also currying is never partial application. The only thing you wrote that is correct is saying that they are related.

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

      @@thomassynths
      Currying is a function that returns a function.
      Partial application is a function that returns a function with some of the arguments fixed.
      I stand by what i wrote.

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

      @@khatdubell Currying is a function that takes in a function with tuple arguments and turns a new function that takes unary arguments and returns successive functions. Partial application merely returns a new function with some argument values already provided. These are different things. `curry(f)` returns a function that has nothing partially applied it it. Currying is one mechanism to facilitate partial application, but it is not the only one.
      Mathematically, currying `(a, b)->c` is `a->(b->c)`. Notice that no partial application has yet been performed, yet the currying operation is completed once the `a->(b->c)` value is returned.
      Mathematically, partially applying `a` to `(a,b)->c` yields `b->c`. Notice that `patial_apply(f,a)` takes more than just the function as an input, unlike `curry`

    • @fdg-rt2rk
      @fdg-rt2rk Рік тому

      ​​@user-tx4wj7qk4the and other soydevs always love sh*tting on functional programming and when asked why? They don't know sh*t on how to elaborate on functional programming

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

    @ThePrimeTime, whenever you summed up a list of numbers you did a catamorphic operation, you probably did it during the last few weeks.

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

      This is the point though. Hearing "catamorphic operation" scares people off, and you don't really need to know the name of it in order to use it.

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

      The problem with category theory is that it's so abstract and general that there's some construct in category theory that will describe what you're doing.
      Except, naming things for the sake of naming them gives you nothing useful.

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

      @@isodoubIet Knowing the basics of CT can lead you to seeing your programming problems differently. I recently wanted an embedded DSL for Logic Programming (with cut!) in Python, and I implemented it in Python with a triple-barrelled continuation monad. I'm very pleased with the simplicity of the code. I ported it to C# in one evening without much prior knowledge in that language. The structure of the code made it also very easy to add tail call elimination via thunks and a trampoline.

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

      @@pillmuncher67 yeah parsing is one of those things for which functional patterns in general are very well suited

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

    12:04 Currying is not partial application. I know people have sort of answered this, but I'll try to provide a more complete answer in relation to bind.
    Say we have a function with multiple parameters: f is (number, number, number) -> string
    bind performs partial application. You're absolutely correct.
    f.bind(null, 1) returns (number, number) -> string
    Currying, on the other hand, is the transformation of f into f2 :: number -> (number -> (number -> string))
    i.e. We end up with a "curried" function, that makes us pass parameters to it 1 at a time.
    For partial application, instead of
    bar = f.bind(null, 1)
    we now just go:
    bar = f2(1)
    Currying can happen at runtime: Haskell literally has a "curry" function. But in this video, he is currying the function manually at dev-time.
    Here's how partial application looks on userIdEquals before and after currying:
    userIdEquals(userId, receipt)
    userIdEqualsCurried(userId)
    Partial application (these give the same result):
    userIdEquals.bind(null, 1)
    userIdEqualsCurried(1)
    12:52 You mention that he's using a closure, whereas bind isn't, but if you think about how to implement bind, it almost certainly returns a closure.

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

      correct bind is using a closure, but its as close to "partial" application as i can get in javascript

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

      @@ThePrimeTimeagen It IS partial application! :) (I go into more detail above)

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

    The confusion behind currying is probably with the nomenclature, currying is the process of turning this type signature:
    f :: (Int, Int) -> Int
    Into this type signature:
    f :: Int -> Int -> Int

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

    Technically all functions modify state because you're modifying registers

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

    for good introductions to fp i can recommend scott wlaschin's articles and videos

  • @juggy2006
    @juggy2006 4 місяці тому

    Currying is the transformation of a function to another which is exactly what he did.

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

    It is false that recursion is a fancier form of iteration, because there are some functions that are only recursive and can’t be turned into an iterative. Look up the Ackermann function to see one that can only be recursive.

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

      Recursion isn’t a fancier form of iteration but can be expressed with iteration and a stack.

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

    This is proof that you can meme on a shoddy "code-tuber" like the one Prime's reacting to and still learn something valuable!

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

      I’m really sad because Code Aesthetics has some good takes and amazing animations… but sometimes, they just miss the mark.

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

      @user-tx4wj7qk4t Holy shit dude calm down.

  • @EdmondDantèsDE
    @EdmondDantèsDE Рік тому +1

    Dogmatists are so annoying. No single tool can be the best for everything. Functional programming has its place, for example stream processing. But you can't shoehorn it into everything.

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

    18:57 - No, you're not a real frontend developer if you haven't spent a day debugging why an (mistakenly) n-colored element is not showing up on the background of the same color.

  • @Lancefh_ENV
    @Lancefh_ENV 2 місяці тому +1

    I am a non functional coder. Because both my code and I don't function correctly

  • @CarlosEstebanLopezJaramillo

    It is currying, its also a factory pattern, and it seems a higher order function as well? damn how many patterns do we have to learn??

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

    I really dislike recursions. Why not just have loops? Or have a normal object oriented language and have something like (C#) function bool IsPrime (int value) { }? The rule is that these may not access static fields, properties and methods, and are therefore stateless. Unless some randomizing is used, the same input should return the same output. This way the caller can know it's an actual function.

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

    Let me know when we are able to break; inside map.

  • @mayatrash
    @mayatrash 11 місяців тому +1

    Since using Julia I will never go back to any non functional language. No side effects is a god given right. (I’m a theoretical physicist so probably it comes naturally to me)

  • @simple-stack-by-ed
    @simple-stack-by-ed 6 місяців тому +1

    The entire world from a human eyes is chaos...but maybe...from a god's angle...functional..
    We will never know perhaps

  • @radovanobal3842
    @radovanobal3842 3 місяці тому

    The times someone effed their heap with a recursion...

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

    "Don't hide footguns (such as changing global variables as a side effect) deep inyour function" is good advice, but functional programming is hardly the heal-all-solution: You'll still have to change state eventually and the mere fact that it's isolated from your regular code by some IO monad condom doesn't mean you can't fuck up inside the monad (which is even more likely if you barely understand the abstract realm you're moving in)

  • @skyleonidas9270
    @skyleonidas9270 6 місяців тому

    I find that if you code without prejudice sometimes you find yourself passing functions into other functions calling functions from inside themselves, creating pure functions and so on, theres a right situation for these things and many wrong ones

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

    everytime I saw your yt pfp, I always thought it looks like a communist leader paintings

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

    recovering functional bro here.

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

    IMHO opinion, not having state is reasonable. But carrying that over to, you cant have for loops because the iteration counter is a variable that is written to and is therefore state, is stupid.
    Having no state, IMHO, means that the same input will result in the same output, every time. That is it. There can be internal "states" as long as the same input will result in the same output.

    • @狐赤い-f5b
      @狐赤い-f5b Рік тому +1

      I would also recommend ignoring that explanation. Local mutations and state are possible in functional languages, but you don't need them for a for loop. e.g. a local Ref can be used to achieve this in Scala, OCaml, and even Haskell
      Using map, filter, flatmap are preferred as you do not need to write the looping implementation where mistakes could be made, it's easier to reason about (likewise using recursion), and can take advantage of any optimisations
      Last time I looked map in Scala was just a classic loop in Java under the hood 😅
      Trust me, 90% of the stuff I read about FP (like in JS) is not really FP. It's procedural code using FP concepts -- and there's nothing wrong with that at all

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

      There are pretty much purely functional programming languages (like Flix) that allow local mutation as long as it doesn't escape the scope.

  • @BesideTheVoid
    @BesideTheVoid 2 місяці тому

    If functional has to generate functions, isnt that just a way to pretend that statefulness (like method of object with attributes or subclasses that affect outcome) isnt useful, while producing a state? I may be saying that because I "haven't done it" but I am genuinely curious.

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

    "Reviewed video: Dear Functional Bros | Prime Reacts" - is this error in description intentional? Recursion for a video involving recursion.