While it makes the code look more elegant, it doesn't remove the obvious, procedural nature of python. By writing code like this you are making sure that a smaller number of people actually understand it, because for loops are more ubiquitous. Granted, it would take more lines of code but the flow would be easier to understand (even with yields) and also easier to debug. That being said, we should be enforcing pure functions wherever possible. Sometimes it's a bit less practical and can make for long argument lists particularly in web frameworks, but the reward is that things become very easy to unit test. So, what you've paid in longer argument lists, you're getting a return in unit tests.
I'll admit that it's not the greatest presentation. I think it is valuable for the student to understand how it works and work out a few contrived examples. In practice, things are way easier and the complicated scenarios aren't that common.
question: an iterator is an object that inherently has state! (same as a function that has a yield statement). So why is an iterator considered part of functional programming, which so frowns upon states??
@Noob Programmer That's not necessarily true. One could write a python interpreter or compiler which does optimize for tail calls. I'm not sure if it exists though, likely because functional style is not generally "pythonic".
@@alxjones Python doesn't know before hand that the recursive function call is the last statement in the function (tail recursion) since its interpreted. So, on every recursive function call, a new element containing the state of the latest function call is pushed onto the runtime stack (doesn't replace the previous element).
@@alxjones You're thinking about interpreters that have a huge compilation step beforehand like C#, Julia, etc. CPython has a compilation step but it's nothing like what those languages have. Recursions generally suck in Python and are not encouraged.
I want to know the person who has no existing knowledge on functional programming to watch this video and immediately starts converting his classes into functions. Seriously, have some overarching examples. You literally only just explained the Python docs in writing throughout the video.
It's kind of hard to teach even a meaningful portion of functional programming in 20 minutes. Maybe one day I'll do a bunch of videos on functional python.
I am glad I found your channel
While it makes the code look more elegant, it doesn't remove the obvious, procedural nature of python. By writing code like this you are making sure that a smaller number of people actually understand it, because for loops are more ubiquitous. Granted, it would take more lines of code but the flow would be easier to understand (even with yields) and also easier to debug.
That being said, we should be enforcing pure functions wherever possible. Sometimes it's a bit less practical and can make for long argument lists particularly in web frameworks, but the reward is that things become very easy to unit test. So, what you've paid in longer argument lists, you're getting a return in unit tests.
I'll admit that it's not the greatest presentation. I think it is valuable for the student to understand how it works and work out a few contrived examples. In practice, things are way easier and the complicated scenarios aren't that common.
Have a great day, you too. Thanks.
Much thanks for a video that returns clarity in pure way independent of global state :)
Chopin at the end; nice touch!
Thank you for this tutorial. It's really helpful
question: an iterator is an object that inherently has state! (same as a function that has a yield statement). So why is an iterator considered part of functional programming, which so frowns upon states??
So reduce is the python equivalent to fold in haskell? As in foldr and foldl?
I enjoy functional programming but it feels like it's an after thought in Python
Tail recursion doesn't work in python right? Ran into a problem with large stacks recently.
@Noob Programmer That's not necessarily true. One could write a python interpreter or compiler which does optimize for tail calls. I'm not sure if it exists though, likely because functional style is not generally "pythonic".
@@alxjones Python doesn't know before hand that the recursive function call is the last statement in the function (tail recursion) since its interpreted. So, on every recursive function call, a new element containing the state of the latest function call is pushed onto the runtime stack (doesn't replace the previous element).
@@alxjones You're thinking about interpreters that have a huge compilation step beforehand like C#, Julia, etc. CPython has a compilation step but it's nothing like what those languages have. Recursions generally suck in Python and are not encouraged.
I love this video
really helpful. many thanks.
Liked and Subcribed
I want to know the person who has no existing knowledge on functional programming to watch this video and immediately starts converting his classes into functions. Seriously, have some overarching examples. You literally only just explained the Python docs in writing throughout the video.
It's kind of hard to teach even a meaningful portion of functional programming in 20 minutes. Maybe one day I'll do a bunch of videos on functional python.
Terrible handwriting
Wait till you see mine
He's no calligrapher but it certainly isn't terrible.