3 Simple Ideas From Functional Programming To Improve Your Code

preview_player
Показать описание
Functional programming is a complex topic to dive into. However, there are 3 simple ideas from functional/declarative code that you can apply to your own code today - without becoming a Haskell expert! In this video, I dive into the details and show you a few examples in Python of how you can use these ideas in both object-oriented and functional/procedural code.

🎓 Courses:

👍 If you enjoyed this content, give this video a like. If you want to watch more of my upcoming videos, consider subscribing to my channel!

👀 Code reviewers:
- Yoriz
- Ryan Laursen
- James Dooley
- Dale Hagglund

🔖 Chapters:
0:00 Intro
0:53 Programming paradigms
2:30 Code example
3:48 #1: Group side effects and use pure functions
5:27 Code example
11:19 #2: Functions are first-class citizens
11:45 Code example
16:53 #3: Use immutability to your advantage
17:46 Code example

#arjancodes #softwaredesign #python

DISCLAIMER - The links in this description might be affiliate links. If you purchase a product or service through one of those links, I may receive a small commission. There is no additional charge to you. Thanks for supporting my channel so I can continue to provide you with free content each week!
Рекомендации по теме
Комментарии
Автор

I encourage you to come up with a full production series, which could be couple of dozen of videos but would be extremely useful. Considering a simple application deployment and put it in production with all software design consideration, such as how to put together all pieces of a software in production such as dockerization, traffic balance, and maintenance, CI/CD all on cloud of course, I offer my help if needed. Thank you!

MTT
Автор

You have one of the best YouTube channels for Python programming. You always provide clear explanations and show code examples of why you are changing anything. I am always happy to see new videos from your channel. Thank you for making videos!

kycklingmannen
Автор

The 3 ideas:
*#1*
4:54 : Group side effects and use pure functions.
8:46 : Functions or methods should have return values that only depend on the input parameters.
9:23 : Functions or methods should return consistent results for their respective input parameters. For example, for function F, input I and output O, i.e. if I = 3 and O = 5, every call to F(3) should produce the output of 5.
*#2*
11:18 : Functions are first-class citizens. What can you do with functions? You can compose them, deconstruct them, pass them to other functions (as parameters), and return them as "values" from other functions. Higher-order functions take input parameters as functions and return functions.
14:32 : Partial functional application. Create a new function from an original function with some of the input parameters already applied. Frequent use of this will make the code less readable.
*#3*
16:52 : Use immutability to your advantage.
In imperative languages (Python), variables can be accessed/changed anytime. Where as, in declarative languages (Excel), variables are generally bound to expressions and keep their value for the entire life of program execution. Immutability helps with resource sharing in use cases which employ concurrency and parallelization. Ref: Concurrency is not Parallelism by Rob Pike. Immutability eases unit testing.

asif.haswarey
Автор

The `greet_list` method/function can be improved using lazy evaluation, turning it into a generator function with the `names` argument as an Iterable. This is particularly useful if you need to read your names from a large file or database table.

JosephLeeHS
Автор

Just wanted to say that you really have inspired me to write much much better code now as a machine learning engineer and really elevated not just my capability but my passion in coding design. It is really so satisfying to produce lean and efficient code!!!

jindy
Автор

Yes! Great stuff. Keep the FP in Python content going, it's almost impossible to find (:

MrBachianas
Автор

I could have gone out with my friends, but seen you have uploaded so I had to stay and watch. I am so happy I stayed for the video, your content is just golden and your advice is solid. Truly a diamond, I am so happy I came across your channel, It means a lot for me. thank you!

hfbezus
Автор

Another amazing video. Thank you so much for this!

Celestialzzz
Автор

F2 allows you to rename all occurrences of a variable within a scope at once. Thus you don't need to rename the uses of the parameter when you rename it.

yeetdeets
Автор

You are a legend man. Very informative tips. Keep it going !!!

codewithray
Автор

this was such a great demonstration Arjan! Thanks so much! Loved it.

golammuhaimeen
Автор

Maybe it's just a detail, but when you said using the callable Greeting reader in the greet_list list comprehension, it will call the callable for each instance of the result list which will use different datetime instances.

esteenbrink
Автор

Thank you for the demo, ideas behind functional programming and scenarios when it is feasible to apply it.

I have noticed you example about shuffling cards and I still believe mutable approach can be better due to the fact that it is more intuitive for humans - we don't end up with another deck after shuffling. I, myself, try to carefully pick the right tool for the right task.

I guess, a good advice for new developers would be not to perceive every problem as nails, when they've discovered a hammer.

Great video!

protom
Автор

First video i watched of yours i had to quit because it was to advanced for me at the time. But still needed to refactor my code so i watched the Code Smells series and it changed the way i program python. After just 2 weeks time my code has had immense progress, in development, maintainability and reusability and that speeds up my overal production time. Huge thanks for all your material, now i am able to follow the more complicated videos as well.
I love that the material covered is Theory in Practice, because i've read about polymorphism and hashtables and all kind of datastructures and coding principles. But you just say what it is you are going to do, then show it and explain why with just the right amount of jargon involved for me to go read more about it if i want, but not get distracted or confused. Thank you so much!

molomono
Автор

Thanks @ArjanCodes, great content as usual.

tommybrecher
Автор

Top level stuff. Thanks Arjan! 👏🏽👏🏽👏🏽👏🏽👏🏽

brothercaleb
Автор

Great video! Just a suggestion — It’d have been nice if you could have run a profiler after every version of code change you made. Maybe in the future ones you can do a performance analysis also side by side.

esiarpze
Автор

This is a really cool video, thanks!!!

ethanholz
Автор

Thanks Arjan, your videos are very useful.

MTT
Автор

Thanks for this video. You are a fantastic teacher.

kopytko