ArjanCodes
ArjanCodes
  • 380
  • 17 926 115
7 Functional Programming Techniques to Enhance Your Python Code
In this video, I'll walk you through 7 functional programming techniques and demonstrate how they work. Although Python is not a purely functional language, functional programming can significantly improve your Python skills.
🔥 GitHub Repository: git.arjan.codes/2024/func
💡 Get my FREE 7-step guide to help you consistently design great software: arjancodes.com/designguide.
📨 The Friday Loop by ArjanCodes Newsletter: thefridayloop.com
💻 ArjanCodes Blog: www.arjancodes.com/blog
✍🏻 Take a quiz on this topic: www.learntail.com/quiz/ezhdob
🎓 Courses:
The Software Designer Mindset: www.arjancodes.com/courses/tsdm
The Software Architect Mindset: www.arjancodes.com/courses/tsam
Next Level Python: Become a Python Expert: www.arjancodes.com/courses/nlp
The 30-Day Design Challenge: www.arjancodes.com/courses/30ddc
👍 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!
Social channels:
💬 Discord: discord.arjan.codes
🐦 X: x.com/arjancodes
🌍 LinkedIn: www.linkedin.com/company/arjancodes
🕵 Facebook: arjancodes
📱 Instagram: arjancodes
♪ Tiktok: www.tiktok.com/@arjancodes
👀 Code reviewers:
- Yoriz
- Ryan Laursen
- Dale Hagglund
- Kit Hygh
- Alexander Milden
- Bean
🎥 Video edited by Mark Bacskai: bacskaimark
🛒 GEAR & RECOMMENDED BOOKS: kit.co/arjancodes
🔖 Chapters:
0:00 Intro
0:32 #1. Recursion
4:45 #2. Structural Pattern Matching
6:17 #3. Immutability
8:49 #4. Pure Functions
11:11 #5. Higher-Order Functions
15:53 #6. Function Composition
18:42 #7. Lazy Evaluation
20:47 Outro
#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!
Переглядів: 17 459

Відео

Do These 5 Things if You Don’t Want to Write Crappy Code
Переглядів 16 тис.21 годину тому
In this video, I'll share 5 key things you should do to avoid writing crappy code. These tips, drawn from my own experience, will help you write clean code. 🔥 GitHub Repository: git.arjan.codes/2024/clean_code 👷 Join the FREE Code Diagnosis Workshop to help you review code more effectively using my 3-Factor Diagnosis Framework: www.arjancodes.com/diagnosis. 📨 The Friday Loop by ArjanCodes Newsl...
Every Developer Had This Feeling
Переглядів 11 тис.14 днів тому
In this video, I’m going to talk about imposter syndrome. What it is, why so many software developers have it, including me, and how I’ve learned to deal with it. ✅ Get the FREE Software Architecture Checklist, a guide for building robust, scalable software systems: arjan.codes/checklist. 📨 The Friday Loop by ArjanCodes Newsletter: thefridayloop.com 💻 ArjanCodes Blog: www.arjancodes.com/blog ✍🏻...
Build, Deploy, and Host a Backend From A to Z
Переглядів 15 тис.21 день тому
Check out Hostinger ➡️ hostinger.com/arjancodes ✔️ Hostinger code for 10% off: ARJANCODES In today's video, I'll show you how to build, deploy, and host a backend from start to finish. I’ll walk through the entire process, covering everything you need to know to get your application up and running. 🔥 GitHub Repository: git.arjan.codes/2024/build_deploy_host_backend/skypulse ✅ Get the FREE Softw...
Streamlit Explained: Python Tutorial for Data Scientists
Переглядів 28 тис.28 днів тому
In this Python tutorial, I’ll dive into Streamlit, a tool that simplifies the creation of web applications for your data science projects. Additionally, I’ll discuss the differences between Streamlit and other libraries like Dash and Taipy. 🔥 GitHub Repository: git.arjan.codes/2024/streamlit ✅ Get the FREE Software Architecture Checklist, a guide for building robust, scalable software systems: ...
Git Hooks: We’re Not Using Them Enough!
Переглядів 12 тис.Місяць тому
In this video, I’ll explore Git hooks and demonstrate how to create a custom Python script to enhance your development workflow. 💡 Get my FREE 7-step guide to help you consistently design great software: arjancodes.com/designguide. 📨 The Friday Loop by ArjanCodes Newsletter: thefridayloop.com 💻 ArjanCodes Blog: www.arjancodes.com/blog ✍🏻 Take a quiz on this topic: www.learntail.com/quiz/ziclcf ...
Keychron Q5 Max Developer Review
Переглядів 9 тис.Місяць тому
In this video, I’ll find out if the Keychron Q5 Max is the best keyboard for developers. I’ll talk about all its features, and how it differs from other keyboards. ⌨️ Check out the keyboard here: www.keychron.com/products/keychron-q5-max-qmk-via-wireless-custom-mechanical-keyboard ✅ Get the FREE Software Architecture Checklist, a guide for building robust, scalable software systems: arjan.codes...
Invariants: How Understanding Limits Enhances Your Code
Переглядів 8 тис.Місяць тому
In this video, I'll explore invariants in software development. As developers, we're usually focused on what the code does, but it's just as crucial to understand what the code doesn't do. Understanding invariants will not only deepen your grasp of your code but also enhance your ability to write more effective tests. 🔥 GitHub Repository: git.arjan.codes/2024/tuesday_tips/invariant 👷 Join the F...
The Unit of Work Design Pattern Explained
Переглядів 21 тис.Місяць тому
In today's video, I'll explain the Unit of Work design pattern, a crucial concept for anyone who regularly interacts with databases. This pattern plays a key role by accumulating all transactions and executing them collectively. But why is this necessary? Find out this video. 🔥 GitHub Repository: git.arjan.codes/2024/unit_of_work 👷 Join the FREE Code Diagnosis Workshop to help you review code m...
How To Do AI Prompt Templating
Переглядів 10 тис.Місяць тому
In this video, I'll show you how to use Jinja2 for AI prompt templates. While Jinja2 is commonly used for generating HTML pages, it's also incredibly effective for tools designed to interact with Large Language Models (LLMs). 🔥 GitHub Repository: git.arjan.codes/2024/tuesday_tips/jinja2 👷 Join the FREE Code Diagnosis Workshop to help you review code more effectively using my 3-Factor Diagnosis ...
AsyncIO and the Event Loop Explained
Переглядів 22 тис.Місяць тому
Over the years, I’ve produced several videos about AsyncIO. Today, however, I’m adopting a new approach where I explain the event loop in depth. I’ll delve deeper into asynchronous programming, focusing specifically on how the event loop operates behind the scenes. 🔥 GitHub Repository: git.arjan.codes/2024/asyncio_dive 💡 Get my FREE 7-step guide to help you consistently design great software: a...
How to Avoid Dependency Hell in Programming
Переглядів 8 тис.Місяць тому
In this video, I’ll talk about Semantic Versioning (SemVer). SemVer isn't just a practice; it's the backbone and foundation of stable and reliable software products. 👷 Join the FREE Code Diagnosis Workshop to help you review code more effectively using my 3-Factor Diagnosis Framework: www.arjancodes.com/diagnosis. 💻 ArjanCodes Blog: www.arjancodes.com/blog ✍🏻 Take a quiz on this topic: www.lear...
Which Programming Language is Better Rust or Python?
Переглядів 17 тис.Місяць тому
In this video, I’ll show you how Rust programming language handles errors and when to use which type of error handling, based on my own experience. 🔥 GitHub Repository: git.arjan.codes/2024/rust_error_handling 💡 Get my FREE 7-step guide to help you consistently design great software: arjancodes.com/designguide. 💻 ArjanCodes Blog: www.arjancodes.com/blog ✍🏻 Take a quiz on this topic: www.learnta...
Everything You Need to Know about Debugging in VSCode
Переглядів 25 тис.2 місяці тому
Everything You Need to Know about Debugging in VSCode
5 Tips for Building Powerful Data Dashboards in Python
Переглядів 28 тис.2 місяці тому
5 Tips for Building Powerful Data Dashboards in Python
This Is How You Do PROPER Exception Handling With FastAPI
Переглядів 15 тис.2 місяці тому
This Is How You Do PROPER Exception Handling With FastAPI
Rust’s Most Unique Feature
Переглядів 16 тис.2 місяці тому
Rust’s Most Unique Feature
The Basics You Need to Know about AWS, Azure, and Google Cloud
Переглядів 20 тис.2 місяці тому
The Basics You Need to Know about AWS, Azure, and Google Cloud
SQLAlchemy: The BEST SQL Database Library in Python
Переглядів 52 тис.2 місяці тому
SQLAlchemy: The BEST SQL Database Library in Python
Python 3.12 Generics in a Nutshell
Переглядів 47 тис.2 місяці тому
Python 3.12 Generics in a Nutshell
Protocols vs ABCs in Python - When to Use Which One?
Переглядів 32 тис.2 місяці тому
Protocols vs ABCs in Python - When to Use Which One?
Python Poetry in 8 Minutes
Переглядів 51 тис.2 місяці тому
Python Poetry in 8 Minutes
Top Keyboards for Software Developers on a Mac
Переглядів 11 тис.3 місяці тому
Top Keyboards for Software Developers on a Mac
How to Test Asynchronous Code in Python
Переглядів 19 тис.3 місяці тому
How to Test Asynchronous Code in Python
Should You Use Dependency Injection Frameworks?
Переглядів 41 тис.3 місяці тому
Should You Use Dependency Injection Frameworks?
Why You Need Custom Exception Classes
Переглядів 18 тис.3 місяці тому
Why You Need Custom Exception Classes
Why You Should Use Pydantic in 2024 | Tutorial
Переглядів 61 тис.3 місяці тому
Why You Should Use Pydantic in 2024 | Tutorial
3 Tips for Working With the OpenAI API
Переглядів 10 тис.3 місяці тому
3 Tips for Working With the OpenAI API
Combining Rust and Python: The Best of Both Worlds?
Переглядів 69 тис.3 місяці тому
Combining Rust and Python: The Best of Both Worlds?
Dependency Injection Explained in 7 Minutes
Переглядів 50 тис.3 місяці тому
Dependency Injection Explained in 7 Minutes

КОМЕНТАРІ

  • @ArjanCodes
    @ArjanCodes 13 хвилин тому

    💡 Get my FREE 7-step guide to help you consistently design great software: arjancodes.com/designguide.

  • @DominikJagoda
    @DominikJagoda 5 годин тому

    Thanks 👌

  • @user-jq5gr8gh3p
    @user-jq5gr8gh3p 11 годин тому

    I just shifted from Django to FastAPI, and the unavailability of an ORM was a shock, and then I came across SQLAlchemy, which came as another shock!

  • @Maik.iptoux
    @Maik.iptoux 13 годин тому

    What do you think about SQLModel? Its from the FastAPI creators and combines pydantic and SQLAlchemy, as i noticed you don't need to create extra classes for sql and pydantic

  • @BenjaminMorrison-pz2in
    @BenjaminMorrison-pz2in 14 годин тому

    in the bubble sort, the inner loop starts from the outer loop starts which means that there are a subset of elements in the beginning that are not sorted.

  • @Maik.iptoux
    @Maik.iptoux 17 годин тому

    Hey 👋 I host a project on my own server (under my couch) with Proxmox, running docker behind Opensense and Crowsec firewall, 1GB speed. I use Cloudflare for the DNS and IP proxy. It's possible, but you have to deal with attackers and hackers. So I Splitt up my Homelan into multiple VLan to exclude privat stuff from the container.

  • @JonitoFischer
    @JonitoFischer 23 години тому

    Thank you Arjan for the videos you upload, they're very helpful and have a great quality, both in teaching and technical quality, I have learned a lot from you.

  • @Impolite6263
    @Impolite6263 23 години тому

    thanks for this video man. i'm learning rust while writing pet project and result really bothered me until i found this video.

  • @djupstaten2328
    @djupstaten2328 День тому

    I find elimination of state to be mostly an obstacle in concurrent programming because atomic operations make threads inherently agnostic of what's going on and whether they should do a/b/c depending on updated conditions, and it also makes it difficult for them to broadcast their own state as it will require an intermediate who would ultimately end up doing exactly what that thread could be doing autonomously (and with less context). It's not impossible to safely allot partitions of a shared workload or state object by using range/slice-types for instance while retaining communicability.

  • @ApprendreSansNecessite
    @ApprendreSansNecessite День тому

    I'm not conviced by the tuple notation when adding a union of type bounds to a generic. Why a different syntax when you already have unions? It feels like types in Python are still an afterthought. I am also surprised by the comments which are against typing altogether. I hope the most important community packages support types

    • @ArjanCodes
      @ArjanCodes День тому

      A union in a type boundary works differently from what the tuple does. Let’s say you have a generic List class. If you set the type boundary to “int | float”, then you can only create lists that contain elements that are either ints or floats. If you set the type boundary to “(int, float)”, you can only create lists containing ints, or list containing floats.

    • @ApprendreSansNecessite
      @ApprendreSansNecessite 23 години тому

      Oh that's nice then!

  • @brunodepaula5293
    @brunodepaula5293 День тому

    How do i deal with real world implememtation in which i need a way to deal with the dependencies (external libs) that just my plugin will need to run ? Also, plugins will not be in the same path as of my application, specially when I install it as a onefile (using pyinstalller)..so how to deal with the imports? Please could you make a tutorial with a more "real example"?

  • @ravenecho2410
    @ravenecho2410 День тому

    Dude! This is crazy i wish i could share u our git repo, i watch all ur vids but havent seen this one! Decimal being slow and incorrect is halarious, we in our use case had to use fractional cents because of LLM cost per 1000 tokens was like 0.00025, we um settled on closest like 50 (rounded) was good enough, but i might make a PR to raise it to the token, just by going from 1e6, to 1e8 I guess it makes sense my code emulates urs as i watch a bit, still eerie tho

  • @tru2thastyle
    @tru2thastyle День тому

    I hate trendy paradigms. I find that’s writing better code is just simply about building an intuition for what is right to do. There is no silver bullet.

  • @manucheremeh5303
    @manucheremeh5303 День тому

    "Im looking at you pyqt !", love your joke. Thank you for this amazing channel

  • @markoobradovic9242
    @markoobradovic9242 День тому

    Arjan, you are soo good at what you‘re doing. Your voice is calm and relaxed. And you are able to transport your knowledge to your audience in the same manner, calm and relaxed. Learning new stuff suddenly becomes like a therapy. No more stress, no more struggle. Thank you very much. Please keep going.

  • @cjdaniels4
    @cjdaniels4 День тому

    This is a nice, concise overview of some core, simple, practical functional concepts. I just want to make one note about your section on function composition. Notice at 16:33, Copilot suggests an implementation of the compose function for exactly 2 functions, which applies the functions in the correct order (based upon the mathematical definition of function composition). Specifically, the composition of functions f and g, which would be called as compose(f, g), first applies g (the right hand function) to an input (x), and then applies f to the result (i.e., compose(f, g)(x) == f(g(x))). However, the compose function that you instead implemented, taking any number of functions of type Composable, applies the functions in order from left to right, not right to left, because reduce traverses the list of functions from left to right. Therefore, your resulting compose function is not truly composing functions in the mathematical sense, and is generally called by other names in other languages (e.g., foldl or pipe) or even in existing functional Python libraries. For your compose function to behave similarly to the original Copilot suggestion, you would need to traverse the list of functions from right to left. This is also evidenced by the fact that in your original code leading up to your introduction of function composition, you had the expression (at 15:10) sort_fn(add_10(multiply_by_2(data))), but then (at 18:22) had to reverse the order of the functions in compose(multiply_by_2, add_10, quick_sort) to get the same result because your compose function applies the function in the reverse ("wrong") order.

  • @y2ksw1
    @y2ksw1 День тому

    The usage of AI while programming can lead to terribly wrong code. I know, you like it because of the speed, but the moment you trust it blindly, you have lost the game.

  • @johnathanrhoades7751
    @johnathanrhoades7751 День тому

    I’ve been working through boot .dev (backend training course online) and using as many functional approaches as possible to get my brain moving that way. Question, doesn’t that quick sort double the length of a normal quick sort as it has to check every element twice (once for greater than once for less than) as opposed to the two normal implementations that check through the list just once. I may be wrong.

  • @FeverYonge
    @FeverYonge День тому

    I laugh at tutorial videos and people who watch them and think they are being productive wasting their time. When I was in a python network development internship, never ever found a video helping me, it was all going to documentation sites or asking people in forums. It doesn't matter cause like TechLead says, tech is almost dead nowadays, it just a skill for immigrants trying to immigrate in developed countries.

  • @kilianklaiber6367
    @kilianklaiber6367 День тому

    Sorry, but this is Just too fast for me, too many concepts in extremely quick succession. I don't tink that you used the Term idempotent correcty, If this means the Same AS the mathematical definition.

    • @kilianklaiber6367
      @kilianklaiber6367 День тому

      The idea that the output should always be the same, if the input is the same, is just part of the mathematical definition of a function. Idempotent means that applying a function to itself renders the same result: f(f(x)) = f(x)

  • @gpcureton
    @gpcureton День тому

    I've been doing a lot of the stuff in this video in Rust, it's nice to see a Python implementation of the same ideas which I can start to use in my day job.

  • @whistlenuts
    @whistlenuts 2 дні тому

    I like raw sql. I don't want to fight a framework to get something done.

  • @sabuein
    @sabuein 2 дні тому

    Thank you.

  • @victoradukwu2719
    @victoradukwu2719 2 дні тому

    As always, it's another masterpiece. Thanks, Arjan. I believe the input ‘data’ at 20:09 could still be a list, instead of an iterator; Only the return needs to be an iterator In addition, we can still achieve the lazy evaluation 20:24 by simply using the result of the map function, without casting into a list

  • @brudinie
    @brudinie 2 дні тому

    Best dating advice ever

  • @vitharana1996
    @vitharana1996 2 дні тому

    Thanks a lot ! you are awesome, I randomly came acoross your channel when I was working on my first industrial software project, my code was working but suddenly I wanted to integrate database to the system, then I watch your video regarding events and design patterns, but I watch your video around 7 times before I implemented the technique on my code ... really greatful for your expertise, I just want see your old videos now. All the best wishes from Sri Lanka ! 👏👏👏

  • @DrGreenGiant
    @DrGreenGiant 2 дні тому

    Worth noting that copy() only returns a shadow copy. So it's a new list but if the original elements were mutable (yours were ints at that's fine) then modifying them in the new list will also modify them in the old list. This can be a big gotcha in parallel code. Deepcopy from the copy module is _almost_ always what you need when you need an expensive copy.

  • @entitledOne
    @entitledOne 2 дні тому

    Your point 3 needs a asterisk with the solition. The copy methid creates a shallow copy. Ehich means that if your liat contains anything that's passed by reference, it will be the same in the new list. If those mutable elements are changed in the new list, they will also be changed in the old list. For true immutability, the deepcopy functionality should be used.

  • @andcarl85
    @andcarl85 2 дні тому

    What do you think of compose from the funcy-package? I've used it instead of writing my own compose-function.

  • @MichaelMossmanNZ
    @MichaelMossmanNZ 2 дні тому

    Thank you Arjan for your helpful insights. I am a Mac newbie, coming from Linux. I've been developing an Android app in Kotlin, and now want to make it Multiplatform, so I bought a second-hand iMac with some reasonable specs. Now to learn a little Xcode / Swift ... wish me luck =)

  • @TheedonCritic
    @TheedonCritic 2 дні тому

    I love the intro!

  • @detemegandy
    @detemegandy 2 дні тому

    Do you use Rye?

  • @thisoldproperty
    @thisoldproperty 2 дні тому

    Really enjoyed this video. The advanced concepts are appreciated.

  • @detemegandy
    @detemegandy 2 дні тому

    I made a composable in my project recently, but it did not have type hint! I had the apply be a lambda, which is ugly IMHO. Then you solved it... but then another lambda appeared! I would want the return to be `partial(reduce, apply, functions)`! I will incorporate the type definition though!

    • @ArjanCodes
      @ArjanCodes 2 дні тому

      Oohhh I like that!

    • @detemegandy
      @detemegandy 2 дні тому

      Corrected in edit. Glad you liked it😁

  • @ravenecho2410
    @ravenecho2410 2 дні тому

    Great vid as always, theres also *functools groupby*, which seems pretty powerful like... Sqlite3 backend, really doesnt matter, but i found like: ``` Select <record> from table where x, and y order by a,b ;``` Especially with um passing a method into the retrieval for how to create named tuples out of the list... you can get really ""complex"" behavior, with super performant code, thats also super readible. Ie used this in prompt generation for our tool, another thing im wondering about is separation vs interface vs api. For code that is being rapidly developped/iterated upon... (separation seems most important... i think.?)

  • @doc7115
    @doc7115 2 дні тому

    pure function is not necessarily idempotent, these are two totally irrelevant concepts, not sure why you said that. 9:02

  • @saitaro
    @saitaro 2 дні тому

    19:58 These both functions should take an Iterable as an argument, not an Iterator. Interpreter will automatically call for an iterator while using the for loop. Iterator protocol requires the __next__ method, which is not implemented for a list, for example. But the functions obviously can work with a list. We always should use the broadest types possible in for a function arguments and the most exact type for the result. This is known as the robustness principle, "Be liberal in what you accept, and conservative in what you return".

  • @GOTHICforLIFE1
    @GOTHICforLIFE1 2 дні тому

    i still struggle to see the value of a compose function over a wrapper function that simply calls a series of functions sequentially. To me at least it feels much more readable and equally flexible. And if you rely on having so many arguments that in no longer remains readable it feels nicer to simply use a class instead. I do understand that the premise of the video is to utilise purely functional principles, but i really can't see a good use case for something like partial functions unless there's some underlying performance benefits. Even in languages like Go i mostly see the sequential approach against a struct of data which is also more readable imo. But then again i'm no expert in either languages, so that could just be lack of experience / use cases where this would make sense to apply

  • @mmilerngruppe
    @mmilerngruppe 2 дні тому

    17:12 oh gods, they brought all that [T] cryptoshit from Java and C++ to my beloved Python. 😢

  • @TheUpriseConvention
    @TheUpriseConvention 2 дні тому

    Recently tried out Gleam was super fun! Python is my main language so really cool to see these ideas in Python, great timing Arjan!

  • @jamesarthurkimbell
    @jamesarthurkimbell 2 дні тому

    Is your Copilot suggesting lines you've already typed in a practice run before filming? Or does it not remember context in that way, and these are "fresh" suggestions?

  • @MLlRoon
    @MLlRoon 2 дні тому

    Monad is insulted not being mentioned here

  • @animeshsingh1307
    @animeshsingh1307 2 дні тому

    Nice video! The subtitles are a little bit out of sync though. Please fix that. Thanks.

    • @ArjanCodes
      @ArjanCodes 2 дні тому

      We’ll look into it, thanks!

  • @edgeeffect
    @edgeeffect 2 дні тому

    0:28 "As a side effect..." I saw what you did there. Nice recursion example... quicksort is so much more likely to be used than factorial.

    • @maleldil1
      @maleldil1 22 години тому

      The vast majority of programmers aren't going to write quicksort either. In imperative languages like Python, you should likely default to using iteration whenever possible and only use recursion for obviously recursive problems (e.g. graph traversal). Even then, one must be careful about blowing up the stack, so it's important that you also know how to convert a recursive function into one that uses an explicit stack.

  • @Soltaiyou
    @Soltaiyou 2 дні тому

    Love the mechanical keyboard 😂

  • @shalomdosseh5367
    @shalomdosseh5367 2 дні тому

    Always great and understandable videos. Thanks 🥲

  • @hriscuvalerica4814
    @hriscuvalerica4814 2 дні тому

    I rarely use recursion . Mostly to traverse a shallow tree like structure. Python has a recursion depth limit .

  • @benfung9571
    @benfung9571 2 дні тому

    This is really spot on I was struggling with function composition for awhile