Write AWESOME Code With These 3 Functional Programming Concepts

แชร์
ฝัง
  • เผยแพร่เมื่อ 26 ธ.ค. 2024

ความคิดเห็น • 160

  • @ArjanCodes
    @ArjanCodes  ปีที่แล้ว +2

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

  • @MTT818
    @MTT818 2 ปีที่แล้ว +153

    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!

    • @aflous
      @aflous 2 ปีที่แล้ว +5

      That would indeed be amazing. Happy to help too if needed

    • @ArjanCodes
      @ArjanCodes  2 ปีที่แล้ว +83

      In principle, that’s a good idea. Unfortunately, it’s really not suitable for TH-cam as the algorithm favors videos that stand on their own (even the 2 or 3 part miniseries I post from time to time do less well than my standalone videos). I am thinking of offering something like this as an online program though.

    • @ndiegow1
      @ndiegow1 2 ปีที่แล้ว +13

      @@ArjanCodes I would love to buy a complete course.

    • @digiryde
      @digiryde 2 ปีที่แล้ว +5

      @@ArjanCodes In the Python World, Using Django, it would be possible to build several stand alone apps that could be tied together. Though, that might still be too niche.
      Whatever you do or not, you are doing a great job. Thank you.

    • @muhammadiqbalbazmi9275
      @muhammadiqbalbazmi9275 2 ปีที่แล้ว

      @@ArjanCodes yeah this would be a better option to have a complete course end to end.

  • @kycklingmannen931
    @kycklingmannen931 2 ปีที่แล้ว +54

    You have one of the best TH-cam 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!

    • @ArjanCodes
      @ArjanCodes  2 ปีที่แล้ว +1

      Thanks so much Nathan, glad it was helpful!

    • @ddctechinstitute6861
      @ddctechinstitute6861 ปีที่แล้ว

      Not just for python programming but software engineering as a whole. You can apply this principles to any language all you need do is learn with an open heart not a syntax or language oriented.

  • @asif.haswarey
    @asif.haswarey ปีที่แล้ว +7

    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.

  • @jindy94
    @jindy94 2 ปีที่แล้ว +9

    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!!!

  • @JosephLeeHS
    @JosephLeeHS 2 ปีที่แล้ว +9

    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.

  • @molomono9481
    @molomono9481 ปีที่แล้ว +1

    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!

    • @ArjanCodes
      @ArjanCodes  ปีที่แล้ว

      Thank you so much for sharing this! I'm glad that my videos are helpful :)

  • @MrBachianas
    @MrBachianas 2 ปีที่แล้ว +17

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

    • @ArjanCodes
      @ArjanCodes  2 ปีที่แล้ว +2

      Thank you MrBachianas, will do!

  • @memsb1
    @memsb1 2 ปีที่แล้ว +2

    Don't let your view count determine your worth. These videos are really valuable to all that watch

    • @ArjanCodes
      @ArjanCodes  2 ปีที่แล้ว

      Thanks Marty, happy you’re enjoying the content!

  • @williamduvall3167
    @williamduvall3167 ปีที่แล้ว

    I am a lone python programmer/environmental engineer with all types of python tools I use day to day. These videos have been the sweet spot to make these tools better. I just became a member, thanks!

    • @ArjanCodes
      @ArjanCodes  ปีที่แล้ว

      Glad you like the content and thanks for becoming a member!

  • @omarcrosby
    @omarcrosby 5 วันที่ผ่านมา

    You are the best Arjan, keep providing great content!

  • @esteenbrink
    @esteenbrink 2 ปีที่แล้ว +4

    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.

  • @Mutual_Information
    @Mutual_Information 2 ปีที่แล้ว +7

    Love the topic! If anyone needs evidence that functional programming is a powerful paradigm, consider JAX.
    JAX is Google’s most recent bet on a neural network framework. It’s their contended with PyTorch and, beyond that, it’s designed to major shortcoming of frameworks in general: speed and reproducibility. And JAX (written in Python) is a effectively all functional programming tool. Everything is a function.

  • @rcc420
    @rcc420 ปีที่แล้ว

    Hey dude. Thank you very much for the knowledge you drop in this channel. I work as a DevOps engineer and I find your channel super useful in my quest to improve my python skills. You're the best !! Thanks. Keep up the good work and spread the knowledge, so we can all become better engineers. Cheers!

    • @ArjanCodes
      @ArjanCodes  ปีที่แล้ว

      Thank you so much!

  • @pro100tom
    @pro100tom 2 ปีที่แล้ว +2

    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!

    • @v0id_d3m0n
      @v0id_d3m0n 2 ปีที่แล้ว

      Good quote haha

  • @esiarpze7908
    @esiarpze7908 ปีที่แล้ว +2

    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.

  • @asdrubalivan18
    @asdrubalivan18 2 ปีที่แล้ว +1

    I'm currently learning Haskell as a way to learn functional programming to apply it to Python and Typescript! This is very useful!

    • @scotttang6229
      @scotttang6229 2 ปีที่แล้ว +1

      You can use Ramda for JS or Lodash/FP. Those are very good to use with functional pattern with JS/TS. It's a bit more work using those libraries with TS though. But it's very doable.

    • @ArjanCodes
      @ArjanCodes  2 ปีที่แล้ว +1

      Thanks so much, glad it was helpful!

  • @ymarinho
    @ymarinho 2 ปีที่แล้ว

    Arjan I really like your videos for their teaching skills and competence. Congratulations.

    • @ArjanCodes
      @ArjanCodes  2 ปีที่แล้ว

      Thanks so much Yves, glad it was helpful!

  • @yeetdeets
    @yeetdeets 2 ปีที่แล้ว +8

    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.

  • @הודגמרסני-ת5ל
    @הודגמרסני-ת5ל 2 ปีที่แล้ว

    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!

  • @hcubill
    @hcubill 5 หลายเดือนก่อน

    Excellent Arjan! Do you test main functions as well?

  • @marcosdiez7263
    @marcosdiez7263 2 ปีที่แล้ว +3

    Nice explanation. I'm new to Phyton yet experienced in other languages and paradigms (in 35 years or experience I took pride of studying paradigms and trying to combine them). I believe the word you wanted to describe the lack of side effect as a feature is "deterministic", which implies that a function produce the same outcome when given the same parameters.
    This is used in many declarative and functional languages behind the scene to cache responses and eventually choose between the cost of calling a function again with the same parameters and the cost of storing the response to return it again instead. For instance, Most SQL servers attempt (but may fail) to tell appart deterministic from non deterministic functions to do this and cache functions responses, and in some scenaries involving grouping data and aggregate functions this may lead to unexpected outcomes and to solve them, anti intuitively you need to pass as parameters the colums making an unike key to each row even if the function doesn't use them internally to "couple" your function determinism to the rows for which you expect it to be executed and cached.
    In the other hand, I believe someone surely implemented the idea of caching function responses in Phyton for high cost algorithms like telling when a number is prime or calculating large factorials, and if not, it'd be a great programming excercise for an application of deferring a function with Callable or another better mean that I suspect may exist and I am still unaware of.

    • @clementdato6328
      @clementdato6328 2 ปีที่แล้ว

      I think side effect also includes cases of mutating states outside of its inputs and outputs and local variables. For example, Python list append always returns None except exceptions. It is “deterministic”, but it is not side-effect-free.

    • @zl4518
      @zl4518 2 ปีที่แล้ว

      I believe there's a cache decorator under the functools module

  • @brothercaleb
    @brothercaleb 2 ปีที่แล้ว

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

    • @ArjanCodes
      @ArjanCodes  2 ปีที่แล้ว

      Thanks so much, Caleb glad the content is helpful!

  • @chuxmyk
    @chuxmyk 2 ปีที่แล้ว +2

    It’s the Vim extension for me. I love VSCode and Vim and extension gives you the best of both worlds 🔥🔥

    • @ArjanCodes
      @ArjanCodes  2 ปีที่แล้ว +1

      Thanks Chuks, happy you’re enjoying the content!

  • @paulbird2772
    @paulbird2772 2 ปีที่แล้ว +6

    The partial function is interesting, would be great to show how using would make some existing code easier to read and or more concise. (probably needs a more complicated example). I can understand what it is doing from your clear explanation, but can't really see why I would need it.

    • @ian4175
      @ian4175 2 ปีที่แล้ว +3

      I don’t know if this is exactly the same, but I’ve found that partial functions is nice for having a single source of truth (or functionality in this case I guess). I’m my case it was in JS and went something like this:
      // NOTE: simplified for example (also copying into an IDE will make it easier to read)
      // most general form of fetching data
      function runFetch(baseUrl, endpoint, method, params, data) {
      // makes request to api using inputs
      }
      // Used specifically for user data
      function runUserFetch(endpoint, method, params, data) {
      return runFetch('userDataApi.com', endpoint , method, params, data)
      }
      // Specifically for GETting user data
      function getUser(endpoint, params) {
      return runUserFetch(endpoint, 'GET', params, {})
      }
      // Specifically for GETting a users friends
      function getUserFriends(params) {
      return getUser('/friends', params)
      }
      // Specifically for POSTing user data
      function postUser(endpoint, params, data) {
      return runUserFetch(endpoint, 'POST', params, data)
      }
      // Specifically for POSTing a users login time
      function postUserLoginTime(endpoint, params) {
      return postUser(endpoint, params, { loginTime: Date.now() })
      }
      As you can see with each new, more specific, function we make we reuse the more general form and set some input to a static value.
      This to me has one major upside, and that is EVERY time we fetch data we end up calling the same function (runFetch) and so now if we want to add something, (like maybe a cache or something), all we have to do is modify that single function to add that new feature. Or if we wanted to debug an issue with data fetching we only have to print out data in one place.
      TLDR: Starting with a general function, with lots of input options, we create more and more specific functions by calling the general form with some function specific input options. This allows us to have a single source of functionality so that if we ever want to modify that we only have to change one function.
      PS: This is just what Ive picked up along the way, not saying this is best practice or anything.

  • @2010edward1978
    @2010edward1978 2 ปีที่แล้ว +6

    Thank you, it was very interesting! Another related topic could be about balancing OOP and FP in Python.

    • @ArjanCodes
      @ArjanCodes  2 ปีที่แล้ว

      Thank you Eduard, and great suggestion ;).

  • @golammuhaimeen2825
    @golammuhaimeen2825 2 ปีที่แล้ว

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

    • @ArjanCodes
      @ArjanCodes  2 ปีที่แล้ว

      Thank you Golam, glad you liked the video!

  • @ianbdb7686
    @ianbdb7686 2 ปีที่แล้ว

    Question: So if i was making a commercial software where i use the IO package should i override the class and make the output native to the prospective client machine.

  • @jessexing3456
    @jessexing3456 9 หลายเดือนก่อน

    thank you, always learning a lot here

    • @ArjanCodes
      @ArjanCodes  9 หลายเดือนก่อน +1

      Glad to hear! I'm always happy to be part of people's learning journeys.

  • @codewithray
    @codewithray 2 ปีที่แล้ว

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

  • @MMarcuzzo
    @MMarcuzzo 2 ปีที่แล้ว +2

    What keyboard shortcuts do you use when typing and editing code?

    • @NostraDavid2
      @NostraDavid2 2 ปีที่แล้ว +1

      I remember he said that he used the vim extension, but vim is fucking wild compared to most standardized editors (probably because the origins of vim is from before ctrl-c ctrl-v were a thing - in 1969 the Ed editor was created, which spawned Ex, which spawned vi, which spawned vim, which spawned Neovim and the vscode extension)

    • @NostraDavid2
      @NostraDavid2 2 ปีที่แล้ว +1

      I like using ctrl + left/right arrow to jump over words, which I can combine with shift to make selections. End and Home are nice too.

    • @MMarcuzzo
      @MMarcuzzo 2 ปีที่แล้ว

      @@NostraDavid2 I do that a lot. But I want to powerup even more my editing, if possible. If I notice that's not possible on conventional editors, I'll try different ones

  • @fa11en1ce
    @fa11en1ce 2 ปีที่แล้ว

    Thanks for the great content Arjan. I am kind of appalled at the lack of manners some of the commenters have here. Don't worry about them, and keep up the good work!

  • @Han-ve8uh
    @Han-ve8uh 2 ปีที่แล้ว

    9:24, "functions/methods should return same if parameter values are same".
    For class methods, what does it mean for self to be the same? Self is something automatically created when we instantiate a class so how to control it repeatably during tests?
    If i remember right, self causes problems during functools lru_cache too since the user may not be aware self (being part of the cached tuple key) is changing.

  • @presstv
    @presstv 2 ปีที่แล้ว

    this functional programming video is so informative. thanks Arjan

    • @ArjanCodes
      @ArjanCodes  2 ปีที่แล้ว

      Thanks so much, glad it was helpful!

  • @markhathaway9456
    @markhathaway9456 ปีที่แล้ว

    Excellent example(s). I'd like to see it in Scala too.

  • @cetilly
    @cetilly 2 ปีที่แล้ว

    This video is SO so so good!!! Thanks Arjan

    • @ArjanCodes
      @ArjanCodes  2 ปีที่แล้ว

      Thanks so much Chuck!

  • @georgytoporkov2041
    @georgytoporkov2041 ปีที่แล้ว

    Great video! I wander whether there's also function composition in Python :D

  • @pieter5466
    @pieter5466 ปีที่แล้ว

    What's going on in line 12 `greetings: list[str] = []`, not sure I've seen that before?

  • @kopytko998
    @kopytko998 2 ปีที่แล้ว

    Thanks for this video. You are a fantastic teacher.

    • @ArjanCodes
      @ArjanCodes  2 ปีที่แล้ว

      Thanks Andrzej, happy you’re enjoying the content!

  • @Celestialzzz
    @Celestialzzz 2 ปีที่แล้ว

    Another amazing video. Thank you so much for this!

  • @tommybrecher7742
    @tommybrecher7742 2 ปีที่แล้ว

    Thanks @ArjanCodes, great content as usual.

    • @ArjanCodes
      @ArjanCodes  2 ปีที่แล้ว +1

      Thanks Tommy, happy you’re enjoying the content!

  • @UNgineering
    @UNgineering 2 ปีที่แล้ว +3

    Functional programming is not given appropriate attention in schools these days. It is huge for code test-ability. Excellent video as always.

  • @miniappletheapple
    @miniappletheapple 2 ปีที่แล้ว +1

    Great vid, it would be nice if most of OOP programmers know

  • @MTT818
    @MTT818 2 ปีที่แล้ว

    Thanks Arjan, your videos are very useful.

    • @ArjanCodes
      @ArjanCodes  2 ปีที่แล้ว

      Thank you - glad you find the videos useful!

  • @mikec64
    @mikec64 2 ปีที่แล้ว +2

    I really appreciate your videos but I lost the thread here on the value of higher order functions. For me, your example made the syntax clear but the example code became harder to read without any clear advantage. I'm going to watch this a few more times because it feels like an important step for me to learn, but I hope you'll give more time to use cases in the future.

  • @abdelghafourfid8216
    @abdelghafourfid8216 2 ปีที่แล้ว +4

    while I do agree that doing immutable operation might simplify the code desing and testing. But in some contexts it may impact the performance, for instance in pandas usually the immutable operations take more time as they require making copies of the dataframe each time. So one sould keep this also in mind.

    • @МаксимГорюнов-м7и
      @МаксимГорюнов-м7и 2 ปีที่แล้ว

      It is not our problem to solve. Languages should be optimised for these scenarios.

    • @karserasl
      @karserasl 2 ปีที่แล้ว +1

      Thats pandas problem. In functional programming, these data structures were rewritten to be efficient, they just keep a copy of things that modified, not the whole structure.

    • @МаксимГорюнов-м7и
      @МаксимГорюнов-м7и 2 ปีที่แล้ว

      @@karserasl object-oriented languages were initially designed for people who coded in C with all of its beatiful features. OO languages came, but the thinking remained imperative.

  • @ethanholz3733
    @ethanholz3733 2 ปีที่แล้ว

    This is a really cool video, thanks!!!

  • @albertjose9654
    @albertjose9654 2 ปีที่แล้ว

    Thanks man Great stuff, will you make a video on microservice architechure in python

    • @ArjanCodes
      @ArjanCodes  2 ปีที่แล้ว +1

      Thank you Albert, will do!

  • @AnthonySherritt
    @AnthonySherritt 2 ปีที่แล้ว

    Love this!

    • @ArjanCodes
      @ArjanCodes  2 ปีที่แล้ว

      Thanks Anthony, happy you’re enjoying the content!

  • @mauisam1
    @mauisam1 2 ปีที่แล้ว

    Sorry, I got lost with the Callable decoration and how it works. I looked in you YT for a video on this didn't see one.

  • @joansparky4439
    @joansparky4439 2 ปีที่แล้ว

    Been programming functional in Python since I started with it in 2008.
    I preface my variables with their expected types, so I know what I'm dealing with..
    str_ , int_ , lst_, los_ (list of strings), lol_ (list of lists), dct_ (dict), FLG_, CNT_, dto_ (datetime object), dts_ (datetime string)
    The class stuff that comes with python most often is useful. But I myself seem somewhat incapable to create/use it for what I do.. which pretty much boils down to run csv like data conversion/modification and displaying.
    Nice content.

    • @ArjanCodes
      @ArjanCodes  2 ปีที่แล้ว

      Thanks so much, glad you liked it!

    • @raphaels2103
      @raphaels2103 2 ปีที่แล้ว +1

      Do you continue to do that with type hints?

    • @joansparky4439
      @joansparky4439 2 ปีที่แล้ว

      @@raphaels2103 you mean do I stick with the practice? Yes. It's helpful to me.. so I keep doing it.

  • @CayoBuay
    @CayoBuay 7 หลายเดือนก่อน

    Good content, thanks.

    • @ArjanCodes
      @ArjanCodes  7 หลายเดือนก่อน

      Glad you liked it!

  • @againstthegrain5914
    @againstthegrain5914 2 ปีที่แล้ว

    I like this way of coding better.. do you mentor folks?

  • @deepakpune1
    @deepakpune1 2 ปีที่แล้ว

    is this similar to separation of concern ?

  • @Jedimaster36091
    @Jedimaster36091 ปีที่แล้ว

    Somehow, I don't see what the purpose of the Greetings class is, after the changes. It doesn't really do anything useful, just returns the provided greeting_intro. As far as I understand, the whole value of the program was to greet the name based on the time of day.

  • @victorcui4014
    @victorcui4014 5 หลายเดือนก่อน

    why is reading from a file considered a side effect? If the function just reads from the file without writing to the file, the original file is unchanged so where is the side effect?

    • @ArjanCodes
      @ArjanCodes  5 หลายเดือนก่อน

      Reading from a file is considered a side effect because this task depends on the external state of the file system. The content of the file might change between different reads, which means that the function performing the read operation doesn’t always produce the same output for the same input (the file name or path). It also involves interacting with an external system (the file system). This can have side effects such as I/O operations that affect performance or potentially lead to I/O errors, which the function then needs to handle.

  • @NicholasShanks
    @NicholasShanks 2 ปีที่แล้ว +1

    I learnt more about Python than FP from this video. However, I suggest you re-upload this with two edits: only move the current timestamp out of the class; leave the greeting string in there. By moving the greeting string to main() you pollute what should be the 'dirty' function with otherwise pure code. Keep the string code in the lower level functions where they can be easily tested too!
    Secondly, put your data argument last. You had a function to which you passed a list of names and a greeting or greet_fn - swap the argument order. By having data last, you follow the standard function layout of other languages and codebases which don't have variable argument order.

  • @DrGreenGiant
    @DrGreenGiant 2 ปีที่แล้ว +1

    I feel like you didn't give a fair argument in favour of mutable, only against.
    Mutable uses much less memory and is much more cache efficient (so faster) than immutable.
    Which one you choose is of course down to the application constraints. But it's very much worth understanding the disadvantages of immutability. Especially with micropython now being a thing on low memory bare metal processors

    • @ArjanCodes
      @ArjanCodes  2 ปีที่แล้ว

      Good point, Simon!

  • @dietermenne
    @dietermenne ปีที่แล้ว

    Great content - and I could concentrate much better if there was no background music. So I have to "listen" to the subtitles

  • @dmytrokorbanytskyi1586
    @dmytrokorbanytskyi1586 2 ปีที่แล้ว

    I really like it, thanks!

    • @ArjanCodes
      @ArjanCodes  2 ปีที่แล้ว

      Thanks so much, glad you liked it!

  • @Terroid
    @Terroid 2 ปีที่แล้ว

    What linter/language server plugin do you use In VSC? It seems to be really strict, I use the Python plugin and pylance, and those 2 aren't so strict like yours
    What other tools do you use??
    Thanks in advance :D

    • @chinin97
      @chinin97 2 ปีที่แล้ว +1

      Pylance as you but has it on strict mode. He has a video about vs code extensions

    • @NostraDavid2
      @NostraDavid2 2 ปีที่แล้ว +1

      Can confirm there's a strict mode. Use ctrl-, to open setting and search for "pylance strict" and it should pop up.

  • @davidsyengo1893
    @davidsyengo1893 2 ปีที่แล้ว

    True python guru!

  • @szeredaiakos
    @szeredaiakos ปีที่แล้ว

    And what are the downsides of working with immutable data?

  • @rianderous8761
    @rianderous8761 2 ปีที่แล้ว +1

    But now, when you put the if elif else statement to define the correct greeting in your main or somewhere else outside the class, essential logic that was inside the class is now spread across the application. I can imagine that this is also something to consider? Would a class method be a good option here? Then you know the code belongs to the greeting class

  • @ewerybody
    @ewerybody 2 ปีที่แล้ว

    Hej Arjan! I generally really like your style and enjoy your videos. But the greeting code example seemed rather artificial. I could see that it all works but the benefits were not clear. I mean it seemed it makes everything much more complicated but for what reason? 😐

    • @ewerybody
      @ewerybody 2 ปีที่แล้ว

      Sure testability is most obvious: Maybe show a tiny unittest to make clear that its cumbersome to test for expected output.

  • @weihu-ai
    @weihu-ai 2 ปีที่แล้ว

    Another takeaway I get from this video is that use meaningful aliases for types in type hints to make the codes more readable.

    • @weihu-ai
      @weihu-ai 2 ปีที่แล้ว

      that actually depends. in examples in this video, the argument names already contain information as suggested by the type alias. It might be better to just have the real type in the hint to provide the real signature

  • @slhcn8609
    @slhcn8609 2 ปีที่แล้ว

    Is that a kind of complaint? Who said "Bugger off" to you :) thanks for your efforts!

  • @v0id_d3m0n
    @v0id_d3m0n 2 ปีที่แล้ว

    Greet doesn't feel like a word anymore. Greet groot.

  • @edgeeffect
    @edgeeffect 2 ปีที่แล้ว

    I have to be VERY careful not to commit code with strings like "Bugger off!" in them... every time I push my branch there's a little tingle of fear that I might have "said" something I shouldn't.

  • @kishorecharandhuli9137
    @kishorecharandhuli9137 ปีที่แล้ว

    Excellent….!!!!!!

    • @ArjanCodes
      @ArjanCodes  ปีที่แล้ว

      Thank you! Cheers!

  • @gmarcosoldo
    @gmarcosoldo 2 ปีที่แล้ว

    Great video, but the functions names (greeting_reader, greet, etc) got a bit confusing at time tbh

  • @oreychandan9229
    @oreychandan9229 2 ปีที่แล้ว

    Yo you did it!

  • @JohnJohnson-dl8oq
    @JohnJohnson-dl8oq 7 หลายเดือนก่อน

    I understand the benefits of FP, but in the first example the knowledge of how to greet went from nicely encapsulated in the class, to spread out between the class and main. There is little need for the class anymore.
    Perhaps this example was just intended to be a segue to the rest of the video.

  • @johncarlo4028
    @johncarlo4028 2 ปีที่แล้ว +3

    Is it just me or is it true to everyone else that you look like hopper from Stranger Things.

  • @edgeeffect
    @edgeeffect 2 ปีที่แล้ว +3

    I wouldn't go so far as to say functional is declarative... I'd say it was "closer to" declarative but still imperative.

  • @mr.RAND5584
    @mr.RAND5584 3 วันที่ผ่านมา

    lambda?

  • @cthutu
    @cthutu 2 หลายเดือนก่อน

    I wouldn't say functional is declarative. I would say declarative is a different paradigm to functional programming.

  • @epgui
    @epgui 8 หลายเดือนก่อน +1

    The best thing you can do to improve your python code is to throw it away and try a language that is actually elegant, something like Clojure or Haskell. Yes, there is such a thing as a better language.

    • @fsharplove
      @fsharplove 7 หลายเดือนก่อน

      or F#.

  • @basedmuslimbooks
    @basedmuslimbooks 2 ปีที่แล้ว +1

    @ArjanCodes, do you have a twin who knows rust? 🤭

    • @avidrucker
      @avidrucker 2 ปีที่แล้ว +1

      I'm also interested to know about this "twin" 😂

  • @halfsourlizard9319
    @halfsourlizard9319 ปีที่แล้ว +1

    FP is a way of thinking, not some 'neat tricks'. You can't just add random ideas from FP to imperative code -- that's like adding vegetables to a meat stew and pretending that you're doing anything like cooking vegetarian food.

  • @sparrowhawkguitarboy
    @sparrowhawkguitarboy ปีที่แล้ว

    I can’t see the video for the most part 😔

  • @tir0__
    @tir0__ 2 ปีที่แล้ว

    ❤️👌🏻👌🏻👌🏻

    • @ArjanCodes
      @ArjanCodes  2 ปีที่แล้ว

      Thanks Priye, happy you’re enjoying the content!

  • @deemon710
    @deemon710 2 ปีที่แล้ว +1

    I tried but I definitely wasn't following along by two thirds of the video.

    • @ArjanCodes
      @ArjanCodes  2 ปีที่แล้ว +1

      Until what part were you able to follow the video? When did things start to get fuzzy? Please let me know as this is very useful feedback for me and I can incorporate that in future videos.

  • @raj.svc.google911
    @raj.svc.google911 6 หลายเดือนก่อน

    Python is, unfortunately , a bad choice for teaching functional programming, primarily because it is statement-based, and not expression-based .

  • @seventeeen29
    @seventeeen29 2 ปีที่แล้ว

    Why are you telling people to move complex functionality out of classes? The motivations behind why you're doing this are completely sound but the place where you handle that complex state is a class. That way any dependencies of this functionality can test their own implementations independently to how the shared logic is implemented by replacing the dependency at runtime

  • @muhammadyusoffjamaluddin
    @muhammadyusoffjamaluddin 2 ปีที่แล้ว +2

    2:18 Seriously you use Wikipedia?? Sir? Hello?

    • @ArjanCodes
      @ArjanCodes  2 ปีที่แล้ว +20

      Normally the knowledge is injected into my brain via a neural link, but unfortunately the data was corrupt, so I had to use another resource.

    • @nowyouknow2249
      @nowyouknow2249 2 ปีที่แล้ว

      @@ArjanCodes 😆 🤣

    • @RatafakRatafak
      @RatafakRatafak 2 ปีที่แล้ว +3

      Whats wrong with wikipedia?

    • @nachorodriguez6380
      @nachorodriguez6380 3 หลายเดือนก่อน

      ​@@RatafakRatafak Literally nothing at all

  • @МаксимГорюнов-м7и
    @МаксимГорюнов-м7и 2 ปีที่แล้ว +1

    After he said "OOP is a subset of imperative programming" I stopped watching immediately. This dude does not even understand what he is talking about. If you can't write declarative OO code it doesn't mean that it is not declarative. What a nonsense.

  • @stevenhe3462
    @stevenhe3462 2 ปีที่แล้ว +1

    This feels like squeezing in functional programming to Python's object oriented environment… The benefits are obvious. But, it feels unnatural.
    Also, the effort does not produce as elegant code as you get in more functional languages.
    I'm not saying that this is not good. It is. It is Python itself that is very limiting in this regard.
    Try to add monads and you'll see…

  • @Jebusankel
    @Jebusankel 2 ปีที่แล้ว +1

    Yet another video that creates a straw man of bad code and calls it OOP and then calls the fixed version functional.

  • @MTT818
    @MTT818 2 ปีที่แล้ว

    It would be good to stop using print and start using log since we don't use print almost never in production and I guess everyone needs to learn what is used in real world than just practising things they would never/shouldn't use. Please avoid distributing bad practices.

    • @ArjanCodes
      @ArjanCodes  2 ปีที่แล้ว +8

      I have experimented with using logging instead of print and it was confusing to the audience since extra boilerplate is needed to setup logging.
      I get that using printing as a logging solution is bad practice. But I’d argue that the way I use print is not logging: it’s what the example application actually does.

    • @avidrucker
      @avidrucker 2 ปีที่แล้ว +3

      How about a video just on logging best practices? 👍😁

  • @Klej0aka0Klej
    @Klej0aka0Klej 2 ปีที่แล้ว

    Great video, terrible shirt :)

    • @ArjanCodes
      @ArjanCodes  2 ปีที่แล้ว +11

      In the Star Trek mirror universe, I run a successful fashion channel but I write terrible code.

    • @cetilly
      @cetilly 2 ปีที่แล้ว +2

      The shirt is good 👍🏻