Functions vs Classes: When to Use Which and Why?

2024 ж. 13 Мам.
135 410 Рет қаралды

Functions vs. Classes?! Are you trying to decide which one to use in your code? In this video, I’ll explore how and when to use each of them, so you can make sure your code is as efficient and effective as possible.
Git Repo ➡️ git.arjan.codes/2023/funclass
✍🏻 Take a quiz on this topic: www.learntail.com/quiz/chlkzb
👷 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
🎓 Courses:
The Software Designer Mindset: www.arjancodes.com/mindset
The Software Designer Mindset Team Packages: www.arjancodes.com/sas
The Software Architect Mindset: Pre-register now! www.arjancodes.com/architect
Next Level Python: Become a Python Expert: www.arjancodes.com/next-level...
The 30-Day Design Challenge: www.arjancodes.com/30ddc
🛒 GEAR & RECOMMENDED BOOKS: kit.co/arjancodes.
👍 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!
💬 Discord: discord.arjan.codes
🐦Twitter: / arjancodes
🌍LinkedIn: / arjancodes
🕵Facebook: / arjancodes
📱Instagram: / arjancodes
♪ Tiktok: / arjancodes
👀 Code reviewers:
- Yoriz
- Ryan Laursen
- Dale Hagglund
🎥 Video edited by Mark Bacskai: / bacskaimark
💻 Code example by Henrique Branco: / henriqueajnb
🔖 Chapters:
0:00 Intro
1:11 Overview
2:29 Functions
6:02 Classes
9:00 Recap
9:48 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!

Пікірлер
  • 👷 Join the FREE Code Diagnosis Workshop to help you review code more effectively using my 3-Factor Diagnosis Framework: www.arjancodes.com/diagnosis

    @ArjanCodes@ArjanCodes7 ай бұрын
  • Arjan just wanted to let you know that in the past year your channel played a huge role in helping me get significantly better at programming during my final year of college, and now working as a software developer. You're doing great work!

    @jordanmungo917@jordanmungo917 Жыл бұрын
    • Thank you for sharing this!

      @ArjanCodes@ArjanCodes Жыл бұрын
    • Brother so happy to read this. The same thing happened to me as well four years ago and I'm so glad to see that the same thing happens to other people. Coding is the most empowering thing we can do

      @mooza.shorts@mooza.shorts Жыл бұрын
  • Last year I made a web scrapper that checked prices of products and used Object Oriented approach "just to keep the code organized". I did not have the need to spawn multiple instances of the scrapper and I was not storing anything in my scrapper instance, so I felt that I was using the wrong tool for the job, because there was no need to use any of the properties of an object, I was just calling its methods. Now it is much clearer to me why to pick one versus the another and I am very thankful that you made this video.

    @poneis88@poneis88 Жыл бұрын
  • This has been my question for YEARS! Thanks for making it simple, love your videos.

    @mariacardona8644@mariacardona8644 Жыл бұрын
  • It is one the most simple and useful explanations of the difference between function/class usage cases Lots of thanks!

    @andriistefanenko6270@andriistefanenko62704 ай бұрын
  • Arjan is a one-man university.

    @manomancan@manomancan Жыл бұрын
    • Someone didn't go to university

      @Generic_text871@Generic_text871 Жыл бұрын
    • Not enough committees to be accredited though.

      @RickWeberEcon@RickWeberEcon Жыл бұрын
    • I would say also for a dev he’s extremely proficient at marketing.

      @dansplain2393@dansplain23937 ай бұрын
    • Word!

      @kyrgyzsanjar@kyrgyzsanjar6 ай бұрын
    • LMAO

      @fabio.1@fabio.14 ай бұрын
  • Thanks for this, it makes a lot of sense. I wish I had seen this in my earlier days learning to code. I definitely have written code as classes when they should have been functions and written code as functions when they should have been classes.

    @bearson4075@bearson4075 Жыл бұрын
  • I don't even need to see the rest of the video but the intro, because you are so clear as allways. I will see it out pure fun and entertainment. Thanks 👍🙏

    @jorgerios5330@jorgerios5330 Жыл бұрын
  • Well described. I spent months coming to this conclusion, I wish I had your video when I started. One big reason I like to use functions with separate data structures, is that it can help to keep Inter Process Communication simple. I use a shared memory approach for performance and I think the OOP model (which tends to include exposing data) would be awkward in an IPC Python system.

    @calum.macleod@calum.macleod Жыл бұрын
  • I can't to be good like you Arjan. Thanks for the effort. Keep up the good work!

    @kwabenakesseh1282@kwabenakesseh1282 Жыл бұрын
  • I also find myself mixing the approaches quite often. In a web backend with routers, for example, I want both states (classes) and pure actions. Pure actions would be a crud module with action-focused SQL statements (or ORM code), while states would be a schema module with classes that hold the state of the request and response. Additionally, the ease of testing argument can not be said enough. The amount of mocking and pre-test setups you have to do varies significantly by the amount of state in your code. All in all, really great video, I agree with all points made.

    @veni_vidi_victorian@veni_vidi_victorian Жыл бұрын
  • I love your humor. You are literally a meme guy. Thank you so much for your hard work and contribution to the Python community

    @YaroslavOliinyk2023@YaroslavOliinyk2023 Жыл бұрын
    • You're welcome - glad you find it helpful! Now... I have to go back to creating memes ;).

      @ArjanCodes@ArjanCodes Жыл бұрын
  • I just can not believe how every line of code in your videos is useful and worth to even dive deeper in the logic you create! Best of the best!

    @ledempire9066@ledempire906610 ай бұрын
    • Thank you so much!

      @ArjanCodes@ArjanCodes10 ай бұрын
  • I recently discovered your channel and I can honestly say; the more I watch you and type out the codes you wrote... The better programmer I have become. THANK YOU!!

    @divine-favouranigbogu413@divine-favouranigbogu41311 ай бұрын
    • Wow, thank you!

      @ArjanCodes@ArjanCodes10 ай бұрын
  • Thanks for sharing. It really helps

    @moinulislam7935@moinulislam7935 Жыл бұрын
  • I also find classes to be useful ways to hold data and define data structures (in this case, dataclasses), which can be passed in as arguments to functions and instances of classes. Thanks for another fantastic video Arjan.

    @rossursino8175@rossursino8175 Жыл бұрын
    • Totally agree & you’re welcome, Ross!

      @ArjanCodes@ArjanCodes Жыл бұрын
    • I wouldn't count dataclasses as classes. Dataclasses are necessary in Python because there's no obvious way to define pure data: your choices in the standard library are dataclasses, named tuples and dicts, and dataclasses have the best ergonomics. They're much closer to pure structs.

      @maleldil1@maleldil1 Жыл бұрын
  • Listening to you is like listening to the best senior developer that never existed in my company.

    @joxa6119@joxa611910 ай бұрын
  • Amazing cosmically music, good light. I almost fly away to the andromeda. Thanks

    @KonstantinPrydnikov1@KonstantinPrydnikov1 Жыл бұрын
  • Exact tutorial i was looking ❤. Thanks

    @mugudev@mugudev Жыл бұрын
    • Enjoy the video!

      @ArjanCodes@ArjanCodes Жыл бұрын
  • Classes are used to model nouns (objects): employees, products, customers, etc. This matches well with relational databases which are also designed around nouns. A product table with a unique ID for each product and a customer table with a unique ID for each customer.The state of the nouns are critical in the database. It is natural to use OOP to represent the entities stored in the database.

    @marksegall9766@marksegall9766 Жыл бұрын
    • Is there any Subject in programming ?

      @gemorp8506@gemorp85067 ай бұрын
    • I agree, it sounds to me that objects are like tables in a database, actual structured data being manipulated on the fly, in the computer's working memory instead of non-volatile storage

      @aocastro@aocastro5 ай бұрын
  • Valuable insights as always!

    @user-tz3lf3oh7c@user-tz3lf3oh7c Жыл бұрын
    • Thank you Scott!

      @ArjanCodes@ArjanCodes Жыл бұрын
  • I have watched hour long lectures/presentations and read more articles than i care to count, on the pros and cons of OOP and using classes, and this is the first time I've seen someone sum it up so well. Honestly I could never figure out why anyone would ever use classes because they just seem to add a lot of complexity compared to the functionality they provide, so they always looked inferior to just using functions. This makes it so much easier to figure out where to use classes.

    @Curatiokyte@Curatiokyte Жыл бұрын
    • Thank you!

      @ArjanCodes@ArjanCodes Жыл бұрын
  • Perfectly explained, I loved this

    @Dubs3@Dubs3 Жыл бұрын
    • Thank you, Kyle!

      @ArjanCodes@ArjanCodes Жыл бұрын
  • Well done, thx!!

    @arthurdent8086@arthurdent8086 Жыл бұрын
  • Thx for this video. I am doing something like the first example you provided. I did a function oriented programme but decided to move to a object oriented one to look more professional. I feel what you said : it’s highly complex (but maybe I architectured it wrongly) and not as easy to read as functional based. I think I am going to roll back part of the code 🤔

    @Lekkerman@Lekkerman11 ай бұрын
  • Awesome content! As a self-taught programmer who first learnt functional programming, I often struggled to see the benefit of OOP. This is a super helpful framework for thinking about the differences between the two.

    @morgankerle5566@morgankerle556611 ай бұрын
    • Thank you, Morgan!

      @ArjanCodes@ArjanCodes11 ай бұрын
  • Thank you, ArjanCodes!

    @doop9134@doop91343 ай бұрын
    • Glad you enjoyed the content!

      @ArjanCodes@ArjanCodes3 ай бұрын
  • Hi Arjan, thanks, for this video, i realize i don't have to use classes for everything if i want to programm, following "best practise", i think functions are easier to use and classes are more complicated. so if not needed i will stay with the functions.

    @RonaldPostelmans@RonaldPostelmans Жыл бұрын
  • The intro is perfect :D love your content and your humble attitude.

    @redkvicka@redkvicka11 ай бұрын
    • Thank you so much! :)

      @ArjanCodes@ArjanCodes11 ай бұрын
  • from now on I will think about classes and functions in terms of bank accounts and file i/o. Thanks dude

    @nonaligned293@nonaligned293 Жыл бұрын
  • thanks for the overview.

    @joansparky4439@joansparky44392 ай бұрын
    • Glad you enjoyed the video!

      @ArjanCodes@ArjanCodes2 ай бұрын
  • Great advice, thanks for sharing!

    @JohnCoughlan_JAC@JohnCoughlan_JAC4 ай бұрын
    • Glad you enjoyed it, John!

      @ArjanCodes@ArjanCodes4 ай бұрын
  • My rule is: If it makes sense to encapsulate something in your own class (so interacting becomes easier and more intuitive), use classes, otherwise stick to functions.

    @dokick2746@dokick2746 Жыл бұрын
    • I also have turned to this philosophy. Often times I would find myself writing 3-4 closely connected functions that require much of the same data and are unlikely to be used elsewhere throughout the program. While a function is theoretically a more robust construct to perform this task, the code becomes way more readable if I wrap it in a class and use the __call__ method to initiate the process.

      @lukekurlandski7653@lukekurlandski7653 Жыл бұрын
  • This channel is a gold mine. I'm a DBA and I use Python for simple automations, but I like to know the language more in depth and this channel seems perfect for it. Thanks for explaining the more high level concepts very clearly and with examples that I wouldnt easily find and I didnt get to study at uni not in this detail at least (I mainly did iteration algs in C and statistics with R no OOP)

    @outofahat9363@outofahat936311 ай бұрын
    • Glad you enjoy it!

      @ArjanCodes@ArjanCodes11 ай бұрын
  • Thanks. 12y ago I started programming Python and a big piece of administrative software for my business... Back then I really tried to use classes, because "that's how it's supposed to be". But found it was simpler if there was mostly plain functions. I did it that way, and it's still working everyday today. Now thanks to you I know I'm actually doing it right 👍🎉🎉🎉

    @Gaspar.Albertengo@Gaspar.Albertengo Жыл бұрын
    • Awesome! Thank so for sharing this!

      @ArjanCodes@ArjanCodes Жыл бұрын
  • I feel you can sometimes use classes to making functional programming cleaner. I was developing an automated report for work. The program would calculate some data, then either send a daily report or an invoice at the end of the month. Completely stateless, so a functional approach made sense. Different clients received their own version of the daily or monthly emails so we would need to write the same types of functions for each client. At the end of the day, it was simpler to create an interface which bundled all of these email-sending actions together. For each client, we used a different implementation of this interface. Technically it was an abstract class rather than an interface since Python doesn't have interfaces.

    @ilangated@ilangated Жыл бұрын
    • hi, python has protocol that can be used as interfaces, Arjan has a video about abstract classes vs protocols

      @HelmutIsaacPadillaChavarria@HelmutIsaacPadillaChavarria Жыл бұрын
  • Goeie video Arjan!

    @Djellowman@Djellowman Жыл бұрын
  • Great video thank you

    @kosmonautofficial296@kosmonautofficial296 Жыл бұрын
  • The duration of state is also an important factor. The rule can be formulated as follows: if you have state that needs to be retained for longer than one procedure call (and that state can be meaningfully encapsulated), then use a class. If the state is only needed for one procedure call, use a procedure .

    @MisterKorihor@MisterKorihor Жыл бұрын
    • agreed, with the bank account example one could easily handle the state in a file or database, and have all the operations be functional

      @Flackon@Flackon11 ай бұрын
    • This is a pretty sound generalization.

      @kicknotes@kicknotes9 ай бұрын
    • very helpful

      @DevinDTV@DevinDTV9 ай бұрын
    • The bank account example is ambiguous - irl want to use a transactional model with some backend data store. Unless you are the bank, the data isn’t mutated at your end, you send requests which are applied and the results are returned, ie; you don’t hold the object at your end.

      @jamesgrant3343@jamesgrant33435 ай бұрын
  • I love this framework! One more: if your program is process-focused, that’s when you use an imperative style

    @bjh4970@bjh4970 Жыл бұрын
  • Thank you for making this video.

    @djbroake9810@djbroake9810 Жыл бұрын
    • Glad you liked it!

      @ArjanCodes@ArjanCodes Жыл бұрын
  • Very nice explanation....

    @rahulkmail@rahulkmail4 ай бұрын
  • Thank you.

    @Louviewtube@Louviewtube5 ай бұрын
  • Very helpful, thanks

    @7scientist@7scientist19 күн бұрын
    • Glad it was helpful!

      @ArjanCodes@ArjanCodes19 күн бұрын
  • Perfect explanation.

    @Michael201078@Michael201078 Жыл бұрын
    • Thank you, Michael, glad you liked it!

      @ArjanCodes@ArjanCodes Жыл бұрын
  • @2:35 I love it when Arjan always says: "I have a very simple sample application here" Me: Eyes squinting: I have no clue what this does

    @alphenit@alphenit Жыл бұрын
  • Thank you for the content! Just subscribed because i really need this knowledge in video. Hopefully I can gain more after subscribing !

    @damienong1462@damienong1462 Жыл бұрын
    • Glad to hear you like the content, and welcome on board! ;)

      @ArjanCodes@ArjanCodes Жыл бұрын
  • thank you

    @PaulBrema@PaulBrema10 күн бұрын
  • Arjan, you inspired me to dive deeper into python and made me want to get better at it! Good stuff. Kudos!!!!

    @vaishnavisonawane8559@vaishnavisonawane8559 Жыл бұрын
    • Thank you!

      @ArjanCodes@ArjanCodes Жыл бұрын
  • Finding out about classes is almost the same “omg” revelation moment as when you first find out about Python 😅 dope vid

    @JFloridaTech@JFloridaTech11 ай бұрын
  • As a Go developer I face the same challenge. Generally I start with functions, and find that I "step up" to data classes as needed. But truthfully, using both functions and data classes together is the answer. Personally I find data classes easier to test since they can implement interfaces, which allow for the easy creation of mock/fake implementations. Functions, on the other hand, can be harder to test, especially when they're coupled to other parts of the system. Also, in Go, a type introduces a new namespace/scope for its methods, which is valuable when the package you're working in is already heavily populated with functions. With no overloading of methods or functions, managing the namespace is critical.

    @simonarcher1510@simonarcher1510 Жыл бұрын
  • The Babylon 5 reference is Awesome! Really takes me back.

    @DouglasHirsh@DouglasHirsh Жыл бұрын
  • What an outstanding video. It even make sense when you're questioning if it makes sense.

    @dj196301@dj1963015 ай бұрын
    • I'm glad you enjoyed the video!

      @ArjanCodes@ArjanCodes5 ай бұрын
  • I have a question about basic programming structures. I have a series of functions that access different databases. I’m not using APIs or json requests, but direct connections, think of them as simple spreadsheets. Function 1 hits database 1 and for those records that meet the criteria, I return values from columns A, C, D, and G. What is the pythonic or professional way to return? I’ve got multiple rows that meet the criteria. I’ve tried tuples of lists, dictionaries of tuples, e.g. return [row1 : (A, C, D, G)] … and returned a dict of subdicts [row1 : [A:value], [C:value]…] They all work but retrieving values by index or keys:subdict key seems convoluted. Thanks!

    @harrycrab8725@harrycrab87258 ай бұрын
  • One more notch in the programming Swiss Army Knife. Thanks.

    @johncrunk8038@johncrunk8038 Жыл бұрын
  • God bless!, thank you for you knowleadge

    @MultiJpva@MultiJpva Жыл бұрын
    • You’re welcome - glad you find it helpful!

      @ArjanCodes@ArjanCodes Жыл бұрын
  • As a self-taught coding person (though far from expert), I have often asked myself this question. Thanks for a great perspective on it.

    @cerealport2726@cerealport2726 Жыл бұрын
  • functools.partial, which you have already covered in a few videos, is a great example of using functions to cover that "grey area" where you want to leverage some lightweight state but don't want the belt-and-braces approach of classes.

    @djl3009@djl3009 Жыл бұрын
  • Great video! comming from pure object-oriented languages to Python I've always struggled to know when to choose just functions over classes, I still have a question though. What about classes that act as a container for multiple related actions? for example, having a class responsible for file utilities, getting a file's absolute path, basename, extension, .... you name it. Would it be better to have file utils as a file containing those functions or have them inside a FileUtils class and mark those methods @staticmethod?

    @mghalix@mghalix6 ай бұрын
  • I prefer this kind of content, over videos of his studio or equipment.

    @Forseti2@Forseti2 Жыл бұрын
  • Coding sensei, thank you for explaining the difference between class and functions. To confirm, if I wanted a code that monitored the stability of proteins over time, that would be state-focused, vs if I wanted to model the kinetics of protein binding, would that be more action-focused. please let me know if I am understanding.

    @TheWrighteousOne@TheWrighteousOne5 ай бұрын
  • Great intro!

    @neilmurphy7064@neilmurphy7064 Жыл бұрын
  • Liked for the B5 reboot reference!!!

    @jatodd3746@jatodd37467 ай бұрын
  • Thanks, Arjan. A question: Say I take a class, make all its instance methods return "self", and then just take them out of the class and convert them into functions. After this, the class is left with only attributes that represent state, and no behavior. What are some good arguments against doing this? I can think of one, which is it can make it harder to quickly read which functions "go together with" which data, loosely speaking. But I'm curious to know if people have other reasons.

    @adrianzuur5589@adrianzuur5589 Жыл бұрын
  • Are you spying on me. Seriously you come up with topics which I recently search😊❤

    @amitaniket5472@amitaniket5472 Жыл бұрын
    • Same for me - Been moving onwards to functional programming recently and found myself struggling with certain aspects feeling more complicated than if i used classes. So this hybrid solution is what works the best for my imo.

      @GOTHICforLIFE1@GOTHICforLIFE1 Жыл бұрын
  • is the diagnosis page not working ? unable to sign up

    @Khan-At-Large@Khan-At-Large7 ай бұрын
  • what’s your lighting budget? love the hues in your videos.

    @kevon217@kevon217 Жыл бұрын
    • He made a whole video about his set-up, you should probably start there.

      @dyanosis@dyanosis Жыл бұрын
  • Arjan is extra witty today. 😜

    @ekaterinakorolkoviene5824@ekaterinakorolkoviene5824 Жыл бұрын
  • The stakes couldn’t be higher. B5 is a great show

    @user-cq3fc3fn5o@user-cq3fc3fn5o9 күн бұрын
  • Hopefully this video is relevant for more than a few more years. Eventually the correct decision will be whatever GPT-5 decides.

    @js46644@js46644 Жыл бұрын
  • Arjan has a new logo... But what about the cushion that his wife made (with the old logo)?! And maybe Arjan can explain the idea behind the new logo? I.e. what does it stand for? Maybe it is a bit inspired by the "NPO" logo of the dutch public TV😉 The NPO also has two squares on top (in green for NPO3).

    @ErikS-@ErikS- Жыл бұрын
  • Hey ChatGPT, can you summarize the following video and focus on the code examples it used? """ Sure, in the video, the speaker provides two examples to illustrate when to use functions versus classes. In the first example, the speaker demonstrates a simple program that analyzes data from a CSV file. The program has a few functions that take input arguments, do something with the data, and then return a result. These functions are then called in a specific order to carry out the analysis. In this case, the program is action-focused, and functions are the most suitable choice for organizing the code. In the second example, the speaker demonstrates a program that simulates a simple game of blackjack. In this case, the program needs to maintain state information such as the player's hand, the dealer's hand, and the deck of cards. The program also needs to have methods that modify this state such as dealing cards and checking for a win. In this case, the program is state-focused, and classes are a better choice for organizing the code. Overall, the examples demonstrate that functions are best suited for action-focused programs, while classes are better for state-focused programs. However, it's important to note that there is no hard and fast rule, and the choice between functions and classes ultimately depends on the specific requirements of the program. """

    @AhmedBesbes@AhmedBesbes Жыл бұрын
  • yay, another B5 fan

    @spaceidiot200@spaceidiot2008 ай бұрын
  • perfection

    @pointer333@pointer3335 ай бұрын
    • Thank you!

      @ArjanCodes@ArjanCodes5 ай бұрын
  • 09:09 line 49 what tuple[a, b, c] means?

    @m3hdim3hdi@m3hdim3hdi Жыл бұрын
  • can you make a video about OpenSource code ? how to contribut, and maybe launch a new wave ? i'm sure you community can do big things. who knows, maybe the full safe driving is in our hands ... ;)

    @sylvainprive1754@sylvainprive1754 Жыл бұрын
  • What I don't get, is how classes are supposed to "store" these states/data/transactions. I assume you'de have to pass every transaction to a database, for example MS SQL?

    @kristoffertjemsland8087@kristoffertjemsland8087 Жыл бұрын
  • What about mixing functional with oop?

    @catface875@catface875Ай бұрын
  • State-focused programming is ill advised, especially for bigger more complex code. My suggestion: avoid mutable state like the plague. Classes are still very useful though, even if their attributes don't get mutated: classes model data, encapsulate properties (read-only) and encapsulate functionality bound to this data (like closures). I think of classes as (1) immutable structs that can have calculated fields or (2) parameterized modules. Functions can tempt you to call global objects or global configuration, which are then difficult to factor out when you need to switch those objects. Classes can tempt you to mutate the object state, which after a few hundred lines looks a lot like mutating globals. So basically, avoid side effects.

    @oscarengland6122@oscarengland61228 ай бұрын
    • Software is all about side effects. There is not much benefit for a software which does not mutate state. At the end of a workflow, you still need to persist the mutated state in a database, file, etc.

      @Jedimaster36091@Jedimaster360916 ай бұрын
  • Have been looking for an answer for this question for long time and just wanted to ask you one hour ago…. Also another question: how can we organize and/or import multiple functions and classes better in py file(s)?

    @nathansun1654@nathansun1654 Жыл бұрын
    • Comments. Use them. If your editor/language allows region comments, use those.

      @dyanosis@dyanosis Жыл бұрын
  • it sounds to me objects are more suitable when we have to store and manipulate data during the program/system execution, i am right @arjancodes ?

    @aocastro@aocastro5 ай бұрын
  • I like to group tasks, if they are complex, and data into classes.

    @TN-cx4qi@TN-cx4qi7 ай бұрын
  • For me I prefer the more data oriented approach where data is first class citizen, for more back end application. I personally believe this approach give clear definitions between the layers and void a lot of mocking and stubbing if it more data centric. Though I do like using my own types h i.e data class etc. For python libs I go more OO seems reasonable to when creating a lib.

    @user-ur9xv7bl7g@user-ur9xv7bl7g11 ай бұрын
  • The intro is quite triggering. I couldn't continue with lesson at once, rewinding the example with Haskell around 6-7 times and trying to calm down. Realizing that the intro idea was nice and witty, explaining just the idea of code over complication consequences with irony. The video footage just hit me showing the ukrainian defence weapons surrounded with words "start WW3", reminding the ruzz prop. ("Neptun" system which allowed to sink the ruzzian "Moskva" destroyer, preventing ruzzian occupation of Odessa, saving big part of Ukraine from ruzzian bombers which have previously used "Moskva" "umbrella".) No blames, just sharing my impressions. I got to watch the lesson "Functions vs Classes" - it is just great. The critical info missing in many courses and tutorials. Thank you for sharing the lesson, I really appreciate it.

    @vitalyromas6752@vitalyromas6752 Жыл бұрын
  • If we begin writing a program, initially we think is state focused, but end up with lots of static methods...would this be a signal that in fact our program is action focused and should switch to pure functions?

    @DiegoMartinez-sr9rm@DiegoMartinez-sr9rm6 ай бұрын
    • I'm going to provoke you : What's the reason you begin writing program, and not begin drawing diagrams before that?

      @Geza_Molnar_@Geza_Molnar_5 ай бұрын
    • @@Geza_Molnar_ well... I've doing uml diagrams since then really hahaha never face this question anymore, however, if is not the case and I haven't done any diagrams, lots of static methods should be a signal to migrate the module to functions

      @DiegoMartinez-sr9rm@DiegoMartinez-sr9rm5 ай бұрын
  • Babalon 5!!!! :)

    @edgeeffect@edgeeffect6 ай бұрын
  • I'm learning Python just to get Babylon 5 reboot. I don't know how that'll happen, but I have faith in arjan lol

    @paxdriver@paxdriver Жыл бұрын
  • 8:15 (in python) couldn't you just use a list of dicts? that's only 1 variable and basically does the job of a class (and of course in reality you'd just be using a db)

    @DevinDTV@DevinDTV9 ай бұрын
  • Classes makes it easy to collect belonging functions. What’s good strategy there when using functions to not end up with everything together?

    @spaderkungskuk@spaderkungskuk11 ай бұрын
  • I have a different definition: use objects for side effects (network, file, database, UI...) and functions for everything else

    @MarkusBurrer@MarkusBurrer7 ай бұрын
  • I'm really confused. How come your code has those arrows ( -> ) in it? How come python doesn't error with those? I've never seen those arrows before in the videos I've watched.

    @lv99redchocobo37@lv99redchocobo379 күн бұрын
  • +1 for Babylon5 reboot

    @ruslanoid@ruslanoid Жыл бұрын
  • You know I really like this explanation. Too often I find videos where OOP is decried as demonic and you can get away with using functions for most OOP uses.

    @joelmanning249@joelmanning2496 ай бұрын
  • And what about "batch"... They are actions to change the state... so, classes or functions ?

    @axel584@axel584 Жыл бұрын
  • I've been writing code for about... oh... when playing in the dirt was good clean fun. The classes stuff is not sinking in. In the backing app; the class only lives for a given time as the single account updates are complete? In the example, the init set the value of the balance to zero. In real life, something would have to feed the current balance to the init part. Calling program open transaction file. Sets the starting balance for this account. How would the class get and keep the balance for this account? Then a loop to process all the updates for this account Call class Save the updated balance get next account So, we basically have two programs, the driver and the class. I'm still not getting the need for a class, when a function can do the same thing and be contained in one program. Not trying to be critical, trying to understand as my attempt to use classes seem to fail and I have to revert it back to a function. I know and have uses a program that call other programs, but that/those called programs do very little and always need some program to drive the process. Please help.

    @wk0djs-TheBigD@wk0djs-TheBigD Жыл бұрын
    • Classes and functions are not programs but are components that you can use in making programs. Class defines the object, its properties(data), and methods(what you can do with said data). Functions typically describes "actions" in programs. When making a program you can use just functions but you will have to track all the data yourself(doable, think games made in C). However, if you are dealing with large amount of related data that are structured, using classes makes development mentally easier.

      @marktiempo466@marktiempo466 Жыл бұрын
  • so often i was asked if i do object oriented or what style i code in and i never knew what i did.... apparently i write funtion oriented code. my code just does things

    @Florian1509_@Florian1509_3 ай бұрын
  • 1:30 Not only Haskell :) ``` def say_something(): print("something") def func_handler(func_par): func_par() func_handler(say_something) ```

    @ipadista@ipadista Жыл бұрын
  • Classes are great for Polymorphism which helps write code that follow solid principles like open closed and others.

    @dovids.greenberger435@dovids.greenberger435 Жыл бұрын
  • "And then we'll never get that reboot of Babylon 5." I suddenly have a new reason to never fuck up ever again.

    @shadeofsound23@shadeofsound236 ай бұрын
  • Interesting! Classes are then used as a last result so functions should be the standard 🤔

    @jazzyniko@jazzyniko Жыл бұрын
KZhead