The Ultimate Guide to Writing Functions

  Рет қаралды 176,535

ArjanCodes

ArjanCodes

Күн бұрын

Over the years, I’ve seen a lot of code by different people, and my conclusion is that writing great, well-designed functions is difficult. So, I made this guide, which includes the 7 most important things you should do when writing functions.
👉🏻 The code I worked on in this video is available here: github.com/ArjanCodes/2022-fu...
🚀 Next-Level Python Skillshare Class: skl.sh/3ZQkUEN
👷 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
🛒 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
👀 Code reviewers:
- Yoriz
- Ryan Laursen
- James Dooley
- Dale Hagglund
🎥 Video edited by Mark Bacskai: / bacskaimark
🔖 Chapters:
0:00 Intro
1:11 Tip 1: Do one thing and do it well
5:17 Tip 2: Separate Commands from queries
6:53 Tip 3: Only request information you actually need
9:27 Tip 4: Keep the number of parameters minimal
14:55 Tip 5: Don’t create and use an object in the same place
17:24 Tip 6: Don’t use flag arguments
19:59 Tip 7: Remember that functions are objects
22:56 BONUS: Tips for naming functions and parameters
#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!

Пікірлер: 309
@ArjanCodes
@ArjanCodes 7 ай бұрын
👷 Join the FREE Code Diagnosis Workshop to help you review code more effectively using my 3-Factor Diagnosis Framework: www.arjancodes.com/diagnosis
@marcioneto3016
@marcioneto3016 Жыл бұрын
After tulips and cheese, I really thought you were going for windmills, but nope 😂. Great video, as always!
@Ziggity
@Ziggity Жыл бұрын
If only I had this when I first started out. The amount of useful information you were able to so succinctly squeeze into a 25 minute video while keeping things clear and accessible is outstanding. Fantastic Job.
@Acuzzio
@Acuzzio Жыл бұрын
Agree
@BenKraal
@BenKraal 9 ай бұрын
Agree x2
@miyu545
@miyu545 6 ай бұрын
3*(agree)
@angelcaru
@angelcaru Жыл бұрын
Summary of this video: == TIPS == - Functions should do one thing, and one thing only - Side effects (commands) or computations (queries), not both - Request only what you need - Minimal parameters - Separate creation and usage - No flag parameters (split up functions instead) - Use higher-order functions == NAMING == - Split up functions with `and` in their name - Shorten - Names should be verbs, arguments should be nouns - Always use the same vocabulary - Use the languages preferred_naming_scheme and notTheWrongOne (so never touch C#) - No spelling or grammar mistakes (duh)
@Kev1305
@Kev1305 Жыл бұрын
You forgot one key bit - Python should be called Prostitute.
@myce-liam
@myce-liam Жыл бұрын
You've forgotten one of the most important take-aways: Arjan thinks Python should have been called Prostitute. "Prostitute 3.11 is up to 60% faster than Prostitute 3.10"😄
@kayakMike1000
@kayakMike1000 Жыл бұрын
And? The function should do one thing only...
@paultapping9510
@paultapping9510 9 ай бұрын
​@kayakMike1000 a redundant and somewhat idiomatic but nonetheless correct formulation.
@StavrosSachtouris
@StavrosSachtouris Жыл бұрын
Guido Van Rossum initially named his language "stroopwafel", but it didn't take off because the name is too long. While he was visiting a zoo and thinking ideas for a shorter name, a snake ate his stroopwafel. Guess what type of snake it was. (I cannot give you any hints, because stroopwafel didn't support type hints).
@PavelSTL
@PavelSTL Жыл бұрын
Umm Cobra?
@AnotherAvaibleName
@AnotherAvaibleName Жыл бұрын
was it a coralillo ?
@victor_silva6142
@victor_silva6142 Жыл бұрын
An Oroshimaru?
@moustachescarz
@moustachescarz Жыл бұрын
a pythong?
@ravimaithreyregulagedda2158
@ravimaithreyregulagedda2158 Жыл бұрын
this is a nice story but I hope you aren't implying that's how he named the language because python is named after Monty Python not the snake python
@mohammednasser2159
@mohammednasser2159 Жыл бұрын
You could've added the cc_validation function as a method for the Card class, and even turn it into property, or validate it upon instantiation in the init, will make even more sense. Great content, keep going ❤️
@_baco
@_baco Жыл бұрын
Really gooood video!!!! To @GrammarNazi, at work we happen to have a Django model named “Custom”. Because classes should be singular names in Python... and someone thought Customs was a plural 🤦‍♂. We still can not safely refactor that.
@qwerty11111122
@qwerty11111122 Жыл бұрын
Glad you mentioned there should be a verb in a function name. def verb(direct_object, indirect_object, ...): ... Or for methods, subject.verb(objects). Been trying my best to be consistent with using normal grammar to make my code make sense, like using plurals for collections to make loop variables easy to name.
@hovikkevork3069
@hovikkevork3069 Жыл бұрын
Crazy value in less than 30 mins! Not only you know what you're talking about, you also know how to deliver it in simple terms. Thanks.
@ArjanCodes
@ArjanCodes Жыл бұрын
I appreciate that!
@hcubill
@hcubill Жыл бұрын
I have followed you for a couple of years and this is my favourite video. You are getting so clear and concrete with your points. Functions did deserve a video like this!
@ArjanCodes
@ArjanCodes Жыл бұрын
Thanks so much Hector - glad you liked the video!
@hukl3945
@hukl3945 Жыл бұрын
Bonus Tip: Don't nest conditionals. While two simple, nested conditionals might be acceptable but I would already try and think of a better way. When you have three levels in your decision tree it might be time for a truth table. It may seem cumbersome to adhere to this rule but in my experience it always leads to better structure in the code.
@EAenergy
@EAenergy 5 ай бұрын
The Dutch guy said order salad instead of fries Holly crap haha. The first time I visited Holland my culture shock was how much fries is consumed. I did not connect the Irish historical famine with the current reality. Love your style and had a blast in Amsterdam. Keep up the good work and thank you for putting these together!
@shashankbang10
@shashankbang10 Жыл бұрын
Hello Arjan. I have been following your tips for a while now. It’s completely changed the way I write code and I have received accolades at my work for the significant improvement in code style. I want to thank you very much for it. Please make more videos like these.
@tugrulpinar16
@tugrulpinar16 Жыл бұрын
Same here, thank you Arjan!
@nitzan3984
@nitzan3984 Жыл бұрын
Same
@ARandomOWL
@ARandomOWL Жыл бұрын
Python should have been called Stroopwafel.
@lachlanstanding7386
@lachlanstanding7386 Жыл бұрын
That's a funny name, I'd've called 'em Shaswazzas!
@thunder____
@thunder____ Жыл бұрын
@@lachlanstanding7386 I see you've played "knifey spoony" before
@zyklos229
@zyklos229 Жыл бұрын
how in the hell, you have so much tasty food in netherlands :D
@Einimas
@Einimas Жыл бұрын
It's a windmill.
@leaoaugusto
@leaoaugusto Жыл бұрын
why?
@heitortremor
@heitortremor Жыл бұрын
I'm excited for this one! I've always wondered if I was going about functions in the most efficient/optimal way and I'm sure these tips will guide me to be better.
@ElNachoMacho
@ElNachoMacho Жыл бұрын
Great video as always. I always learn something new watching your content! Thank you for sharing
@danielkonstantinovsky108
@danielkonstantinovsky108 6 ай бұрын
It's very interesting for me to step into the mainstream Python developer world on KZbin. I'm a scientist and I write tons of "complicated" Python (and Cython and C++) code but the complexity is very different in scientific code - it's in the math and the algorithms rather than the stack of code that manages other code as seems to be common in mainstream codebases. We use abstractions like classes of course but our hierarchy of abstractions is much less branched than here, more like a stack than a web. We like our input files with dozens of parameters (🙂), which flows into some main, which calls some objects and functions, that kind of thing. This comment in itself is not a criticism of common design patterns - I don't feel qualified to criticize them, but I do note how difficult it is often to find the code that actually _does_ something in "professional" codebases. There is so much fluff that is supposed to manage the complexity that it becomes quite complex in itself. That has always frustrated me. Good abstractions are hard to come by, and mainstream code is full of bad abstractions for the sake of abstraction. Sometimes it's better just to _do_ the thing you want to do, rather than erect an entire class of middle managers, usually classes, with abstract-sounding names. If your core algorithm is ten lines or so (as is amazingly often the case by the way), there is no justification for writing 5000 lines across 14 source files to "manage the complexity", but that's often what you see. Bottom line is when you manage complexity you introduce complexity, and that has to be controlled if you're going to make the code friendlier to the developer and user. As you may have guessed, I'm a big fan of Brian Will's diatribe on OOP, not that I think classes are bad (he doesn't either) but that I think most abstractions are bad, and cementing them in with further bad abstraction is a bad idea. Just some thoughts from a scientific programmer - I live in a very different world from all of you, but maybe I have some useful insights because of that. I don't know. You decide.
@yahyakhan-rr9ei
@yahyakhan-rr9ei Жыл бұрын
One of the best channels, and for free. Feels amazing.
@EricT43
@EricT43 Жыл бұрын
Hi ArjanCodes, thanks for the video! I appreciate the way that you teach these coding concepts - you strike just the right balance, in my opinion, between conceptual and practical explanations.
@aashayamballi
@aashayamballi Жыл бұрын
Thanks for the great video again Arjan! It was really informative and helpful🙏
@JesusMRamosPerez
@JesusMRamosPerez 11 ай бұрын
Thanks a lot for these videos! Can't stop watching them!
@Personal-M.I.S.
@Personal-M.I.S. Жыл бұрын
Nice! You've taken some of the most fundamental clean code practices and distilled them down to a very coherent and concise 25 minutes with no hand waving or fluff. Uncle Bob would be proud =)
@ervankurniawan9267
@ervankurniawan9267 10 ай бұрын
The only thing I just want to say is, since I found your channel and has watched some videos, I never look Python is easy anymore. And every time I look at my current Python code, it's looks like a dumb code. 😂 Thanks for the content. 👏🏻
@Personal-M.I.S.
@Personal-M.I.S. Жыл бұрын
Just to say, I've only dabbled in Python and don't know much more than the fundamentals of the language, but I still get A LOT out of watching your videos. I really appreciate how your presentations are so chill and straight to the point. Even when I can't quite tell what's going on with the language, I can get the idea you're trying to teach. Good stuff!
@madao4024
@madao4024 Жыл бұрын
that was a good one at 5:50 🤣
@katja_und_mickey
@katja_und_mickey 6 ай бұрын
Another great watch! I am so glad there are so many great videos on your channel! Thank you so much for all the valuable information.
@ArjanCodes
@ArjanCodes 5 ай бұрын
I'm glad you're enjoying the content!
@gwho
@gwho 9 ай бұрын
Another tip: put your 17:00 Put PaymentHandler and StripPaymentHandler, related subclasses/polymorphisms next to each other. PRICES is particular constants (which are akin to arguments) as opposed to PaymenteHandler and StripePaymentHandler class definitions (which are akin to function definitions). So in sum, separate arguments from parameters, or templates from values.
@NoobomgWhy
@NoobomgWhy Жыл бұрын
My favourite Dutch things so far: Frikandeln, Vla and Pasta Choca. Now I can add Python. Thank you!
@uwegenosdude
@uwegenosdude 3 ай бұрын
Thanks for the great video.Especially I liked the trick to force keyword arguments. And the closed open principle.
@ArjanCodes
@ArjanCodes 3 ай бұрын
Glad you enjoyed it!
@weistrass
@weistrass 4 ай бұрын
Didn't know those partial functions!!! Sooooo gooooood
@ArjanCodes
@ArjanCodes 4 ай бұрын
I'm glad you learned something new!
@CodingIsFun
@CodingIsFun Жыл бұрын
*Very helpful, Arjan! Thank you!* 👍
@ArjanCodes
@ArjanCodes Жыл бұрын
Thanks so much, glad the content is helpful!
@gshan994
@gshan994 Жыл бұрын
Ur explanation is very clear n concise. I learned something new today. Thanks
@ArjanCodes
@ArjanCodes Жыл бұрын
Thanks so much GShan, glad the content is helpful!
@wizardfix
@wizardfix 8 ай бұрын
Nice. Very good advice about separation of concerns. Thank you.
@ArjanCodes
@ArjanCodes 8 ай бұрын
Glad it was helpful!
@JZ1917
@JZ1917 Жыл бұрын
The humor quality is increasing with each video. Not only did I learn, I chuckled a few times !
@ArjanCodes
@ArjanCodes Жыл бұрын
Glad you like them!
@drhilm
@drhilm Жыл бұрын
Love this kind of videos. Thanks. This is something to return to...
@ArjanCodes
@ArjanCodes Жыл бұрын
Thanks so much Dror, glad the content is helpful!
@abymathew575
@abymathew575 Жыл бұрын
wow I really like this video. What a clarity and clear explanation with real examples. Thanks for this wonderful video. 👏👏👏👏👏👏
@ArjanCodes
@ArjanCodes Жыл бұрын
Thanks so much Aby, glad the content is helpful!
@whkoh7619
@whkoh7619 Жыл бұрын
Amazing content as always. Thank you Arjan
@ArjanCodes
@ArjanCodes Жыл бұрын
Thanks so much, glad the content is helpful!
@vardantheunderdog
@vardantheunderdog Жыл бұрын
It's great to see Uncle Bob's Clean Code lessons apply still to this day! Thanks for the video :)
@JackQuarm
@JackQuarm Жыл бұрын
Your channel is brilliant, keep up the great vids!
@ArjanCodes
@ArjanCodes Жыл бұрын
Thanks a ton!
@ivannuzhyn4668
@ivannuzhyn4668 Жыл бұрын
Awsome video, a lot of very usefull info for me. Thanks a lot!
@ArjanCodes
@ArjanCodes Жыл бұрын
Thanks so much Ivan, glad the content is helpful!
@skellious
@skellious Жыл бұрын
I learnt so much from this one video
@Kamil-so1se
@Kamil-so1se Жыл бұрын
Great as always.
@mikelancaster8924
@mikelancaster8924 Жыл бұрын
These videos are very necessary, thanks!
@ArjanCodes
@ArjanCodes Жыл бұрын
Glad you like them!
@marcelgrolain2764
@marcelgrolain2764 Жыл бұрын
Thanks for the inspiration
@mohammadsharara3170
@mohammadsharara3170 4 ай бұрын
Very juicy video, and at the same time funny, especially the joke about PyQt 😂. Thanks!
@ArjanCodes
@ArjanCodes 4 ай бұрын
I'm happy you enjoyed the video!
@InvestLarge
@InvestLarge 10 ай бұрын
New to the channel since yesterday's KZbin recommended your video on Classes. Subscribed and liking the tutorials. I am learning and also seeing new things that I don't know what they are for. Decorators perhaps? protocol, hmm Going to look it all up and become better knowledged
@ArjanCodes
@ArjanCodes 10 ай бұрын
Thank you so much!
@Vijay-Yarramsetty
@Vijay-Yarramsetty Жыл бұрын
thanks a lot. great content
@mr.wheelers5504
@mr.wheelers5504 Жыл бұрын
Hi Arjan! Great video as always, I feel like I've learned more about python programming from you than I have during my astronomy studies. At 16:45 in the video you create a PaymentHandler baseclass using a Protocal. Howcome you don't use an AbstractBaseClass for this? Using a protocal like this seems to ignore the "better explicit than implicit" principle. Is there some advantage to using a protocal like this?
@georgH
@georgH 11 ай бұрын
Eiffel was used in some classes back in the day at my uni, it really helped me on understanding OO, it was so much nicer than Java (which didn't even have generics back then). Bertrand Meyer named an engineer's language on a great French engineer: Gustave Eiffel. By this rule, Python might have been called "Tideman" or "Lely"
@innstikk
@innstikk Жыл бұрын
Excellent video! There is one thing that I didn't understand. In order to not pass all the user information you made a CardInfo protocol and said that it then would only pass on the information in the protocol. I tested this, but I can still access name from the User dataclass in this way. So the protocol doesn't extract only the variables it contains, but I guess only checks that those needed are there? So in effect you send over as much data in this way as with simply passing the User without the protocol. The protocol approach is nicer than sending the User, but having a Card class is even better.
@paxdriver
@paxdriver Жыл бұрын
I just realized Arjan has 10% the subcribers I just assumed the channel had from watching for so long. I honestly believed for years this was a 1 million+ channel and only just now realized it wasn't. I need to comment and share more, this is my fault.
@ArjanCodes
@ArjanCodes Жыл бұрын
Thank you so much for your support Kristopher!
@danilkister1650
@danilkister1650 Жыл бұрын
This video is heavily underrated!
@mithunmanoharmithun
@mithunmanoharmithun Жыл бұрын
Awesome content. Keep going !
@ArjanCodes
@ArjanCodes Жыл бұрын
Thanks so much Mithun, glad the content is helpful!
@Mike-vj8do
@Mike-vj8do 10 ай бұрын
Enjoyed the video!
@ArjanCodes
@ArjanCodes 10 ай бұрын
Glad to hear it!
@gshan994
@gshan994 Жыл бұрын
Quicktip: you can select cc and then hit ctrl/cmd + d to select next occurance of cc. With this u can change selected same words.
@doctor6932
@doctor6932 Жыл бұрын
loved this
@ArjanCodes
@ArjanCodes Жыл бұрын
Thanks so much, glad you liked it!
@DS-tj2tu
@DS-tj2tu Жыл бұрын
Thank you!
@ArjanCodes
@ArjanCodes Жыл бұрын
Thanks so much, glad you liked it!
@CFox.7
@CFox.7 9 ай бұрын
The mind of the coder - they think they are creative but they are not they are just master organisers ! and no you dont need to be creative to be organised - its just a matter of finding the optimum for the goal ( within constraints of course ). Choose your focus.
@Krazness
@Krazness Жыл бұрын
Great video. Have you considered creating a video covering partial applications for functions?
@ArjanCodes
@ArjanCodes Жыл бұрын
Great suggestion Richard, thank you!
@kristianhig3283
@kristianhig3283 Жыл бұрын
thanks it worked
@ArjanCodes
@ArjanCodes Жыл бұрын
Thanks so much Kristian, glad the content is helpful!
@SuperDoc3000
@SuperDoc3000 Жыл бұрын
This man's content is a gift, thank you Arjan
@MagnusAnand
@MagnusAnand Жыл бұрын
Arjan, I have one question not related to this video: working with an ORM (like Django's), how do you use the SOLID principles? If you ever talk about this it would be so cool 😜
@irenaronen7497
@irenaronen7497 Жыл бұрын
Thank for the video! I also seek how to use functions within the dataframes, namely in Polars, and how to incorporate it in DuckDB (using SQL in Polars dataframes). Working with alot of data is a bit frustrating, and I seek ways to use real-case data analyses. Also wonder how to use the Python Class system in the above case... Don't want to overload the system with too many variables.
@ErikS-
@ErikS- Жыл бұрын
5:45 - 😂 Arjan is spot on here!
@AnotherAvaibleName
@AnotherAvaibleName Жыл бұрын
thanks Arjan, very nice and based
@ArjanCodes
@ArjanCodes Жыл бұрын
Thanks so much, glad the content is helpful!
@nickeldan
@nickeldan Жыл бұрын
The sound of your keyboard is so soothing.
@evgenyocean426
@evgenyocean426 Жыл бұрын
Serious question: How can you stick to the default vscode theme for so long? It doesn't not even highlight function arguments in the function body. Is it for video recording only or you do actually use it on a daily basis? BTW. Love your content. Thank you!
@tadastadux
@tadastadux Жыл бұрын
Thank you Arjan. I'm just wondering if you swapped ABC with Protocal libraries.
@confuso1
@confuso1 Жыл бұрын
Very good video, thanks a lot, instant abo
@ArjanCodes
@ArjanCodes Жыл бұрын
Glad you liked it!
@wiktormorela4907
@wiktormorela4907 9 ай бұрын
Hey Arjan / youtube community. every time i watch those videos, i have a feeling that applying this knowledge into my data engineering python tools would be an overkill. Can you recommend something like levels of complexity in python code, where one could judge design quality of code based on those levels? As an example, how long one should stay in single module project, what is the moment when design should consider dataclasses etc.
@tesszheng4586
@tesszheng4586 24 күн бұрын
at minute 5, for this piece of code: for digit in even_digits: checksum += sum(digits_of(str(digit * 2))) , I feel like we could write: checksum += sum(even_digits) * 2, thus we don't need to enumerate each even_digit, times 2 , convert to string ten convert back to an int list, then sum up.
@MrHarleking
@MrHarleking Жыл бұрын
Hi, i love your Videos, but please use a zoom on you screen when u show and work with Code. Thx a lot for your work!
@WarrenBey
@WarrenBey Жыл бұрын
Come on Arjan! Every python dev knows Guido loves Monty Python and that's where the language got it's name. There are ton's of Monty Python jokes in the source code and docs.
@walis85300
@walis85300 Жыл бұрын
Thanks for the video. One question: in the protocol class, is it required to mark as properties the class’ attributes or it can be declared as attributes?
@Shivnaren
@Shivnaren Жыл бұрын
Marking the attributes as properties is the only way to declare them as immutable (useful for NamedTuple instances, or just a `const` like declaration); but they can be declared as attributes too.
@Klej0aka0Klej
@Klej0aka0Klej Жыл бұрын
First video that made my laugh :) good jokes, you def not a junior YT anymore :)
@ArjanCodes
@ArjanCodes Жыл бұрын
Thank you, glad you liked the video!
@Nellak2011
@Nellak2011 Жыл бұрын
So on the first example, the luhn checksum one, it is ok to leave the functions all inline IF AND ONLY IF you know that the requirements wont change and you will just use it in that one place. Other than that it is a bad practice as it leads to less code coherence and more coupling, which makes thing hard to change. The few advantages to inline are efficiency and faster to write, but in a large software in prod, the drawbacks outweight the trivial advantages. In general, nearly always extract out to make your code more modular and easier to read, it is just common sense.
@mikeciul8599
@mikeciul8599 Жыл бұрын
In other videos, I recall you've advised against including types in variable names. Maybe it doesn't apply here because it's a type variable, but when you called the type HandlePaymentFn I wondered about the naming scheme. When I name function types, I usually put "er" at the end of the name. In this case the function type would have the same name as the class it replaced, "PaymentHandler." I probably would have called the param "handle_payment" rather than "payment_handler" though. e.g.: PaymentHandler = Callable[[int], None] def order_food(items: List[str], handle_payment: PaymentHandler) -> None: ... What are your thoughts? How does everyone here name their Callable type variables?
@philscosta
@philscosta Жыл бұрын
Great video as always! I also love partial functions in Python. One issue I have with them though, is that the type checker in Pycharm doesn't really know what to do with them. For e.g. def sum(a: int, b: int) -> int: .... sum_2 = partial(sum, b=2) The type checker shows and error when it checks whether sum_2 is of type Callable[[int], int]. Does anybody else have this issue? What do you all do about it?
@NostraDavid2
@NostraDavid2 Жыл бұрын
What error does it show?
@leniedor733
@leniedor733 Жыл бұрын
1. SRP from the S of SOLID + some good refactor examples
@MorselHoarder
@MorselHoarder Жыл бұрын
23:56 "I'm looking at you PyQt" 😂😂😂 fr tho
@tolstoievski4926
@tolstoievski4926 Жыл бұрын
Is the protocol class cardinfo still relevant after creating a separate data class for the card ?
@maortizm99
@maortizm99 Жыл бұрын
What's the advantage of using partials over lambdas? Is it just about readability?
@pitter6636
@pitter6636 Жыл бұрын
How would you proceed in creating functions for dataframes?
@mikefochtman7164
@mikefochtman7164 Жыл бұрын
One thought that popped up as I watched, couldn't we move the date checking into its own function? I know the date checking is pretty trivial, one line and all, but "do one thing, and do it well". So 'validate-card' would simply be " return validate_number and validate_date;" If later we wanted to do something more, such as 'validate-ccv' that too could be added in a similar manner. Having a separate date validation would help compartmentalize things such that some future changes to 'date checking' are localized to one function. For example, most CC here in the US are valid through the END of the month and don't expire on the first. Looks there like your CC is not valid on the first day of the exp_month?? How many places in all the code have to be searched to fix such a bug if you do date-checking in-line everywhere??
@aperturesignaturebandwidth
@aperturesignaturebandwidth 5 ай бұрын
@12:05 you seem to indicate we're running validate_card on the CardInfo type but you pass the Customer?
@nfredrik
@nfredrik Жыл бұрын
what is the diff btw 'def validate_card(card: CardInfo)' and writing 'def validate_card(card: Card)' Is it syntactic sugar? It do not to scope down number of props passed the validate_card() when executing, property 'valid' still there.
@Gukzilla
@Gukzilla Жыл бұрын
As a self taught, these design principles are really that one thing that I felt is missing to pull of brilliant code.
@ArjanCodes
@ArjanCodes Жыл бұрын
Thanks so much Gukzilla, glad the content is helpful!
@MagnusAnand
@MagnusAnand Жыл бұрын
One question not related to this video: How to solve the relational impedance mismatch? If I use the solid principles to design a payment system (like you did in a different video), an employee object, contrast object, commission object. You use interfaces, composition and inheritance. But how to reconcile this with the database??? I’m quite confused. Thanks.
@David-124
@David-124 Жыл бұрын
Great video! At 23:14 and 23:29 did you mean to say "Parameter" rather than "Argument"? 😱
@zknarc
@zknarc Жыл бұрын
For data related code, how do you deal with passing dataframes to functions? Should you select only the colums which are needed or pass the whole thing?
@NostraDavid2
@NostraDavid2 Жыл бұрын
I would pass the whole thing, as objects are passed by reference instead of pass by value. If you only pass the bits you need, you're likely to copy a bunch of data unnecessary.
@kovlabs
@kovlabs Жыл бұрын
Could you do a deep dive on building your own modules Please 🙏
@ArjanCodes
@ArjanCodes Жыл бұрын
Noted!
@gordonsross
@gordonsross Жыл бұрын
What is the benefit of creating the "digits_of" internal function within "luhn_checksum"? Why not just digits = [int(d) for d in card_number]?
@vladimirtchuiev2218
@vladimirtchuiev2218 9 ай бұрын
In my work I work on a codebase that someone else wrote with massive amount of typos, the typo point hits near and dear, it is infuriating to try to find functions with typo'ed names... Also, how you would approach making clean code with a dominant package that you need inherent a lot from its classes, like Pytorch and Pytorch Lightning for example?
@jasonhan3854
@jasonhan3854 Жыл бұрын
HI Arjan, first of all thanks for the informative video, this is the first video I've viewed from your channel and I really like it! But I'm a front-end developer and use JavaScript and I just wish that there's someone out there like you who creates contents around JS! Anyhow, keep up the great work!! P.S. I actually laughed when you said that Python should've been named prostitutes LOL
@ArjanCodes
@ArjanCodes Жыл бұрын
Thanks a lot! Glad you liked it :)
@hugoazevedo519
@hugoazevedo519 Жыл бұрын
Hi Arjan! How did you do (which shortcut) to format the code in the "validate_card" function call in 8:10?
@kevinrosa
@kevinrosa Жыл бұрын
It's likely a VS Code formatter plug-in. Maybe it's the "Python Indent" plug-in. He has Prettier installed but that doesn't support Python kzbin.info/www/bejne/a5a2kn19iKx_qZI
@NostraDavid2
@NostraDavid2 Жыл бұрын
Alt-shift-f formats the current document. Vscode will mention if you are missing a formatter (but some are available as extension)
@NostraDavid2
@NostraDavid2 Жыл бұрын
Arjan probably has "format on save" option enabled.
@luck3949
@luck3949 Жыл бұрын
Flags argument seen to be stretched: N flags represent 2^N functions. Flags might be written in configuration file, so using them in some form or another might be necessary. Splitting one function into many just to remove flag might lead to code repetition.
@mikeciul8599
@mikeciul8599 Жыл бұрын
What is the name of the code smell where an object is created and used in the same place?
@micmike
@micmike Жыл бұрын
I wanted to ask a question about holidays.py line 26 code. What does the 'f' do in: raise ValueError( f"you don't have enough holidays left......\ I'm struggling to understand that...
@Viertelhund
@Viertelhund Жыл бұрын
13:45 I wished you'd have moved the validate_card method into the Card class as validate method without a parameter.
@HenriqueErzinger
@HenriqueErzinger Жыл бұрын
In Brazil we have a programing language called Lua. We do, indeed, have a moon.
7 Python Code Smells: Olfactory Offenses To Avoid At All Costs
22:10
The Ultimate Guide to Writing Classes in Python
25:39
ArjanCodes
Рет қаралды 104 М.
¡Puaj! No comas piruleta sucia, usa un gadget 😱 #herramienta
00:30
JOON Spanish
Рет қаралды 22 МЛН
О, сосисочки! (Или корейская уличная еда?)
00:32
Кушать Хочу
Рет қаралды 8 МЛН
WHY IS A CAR MORE EXPENSIVE THAN A GIRL?
00:37
Levsob
Рет қаралды 6 МЛН
The purest coding style, where bugs are near impossible
10:25
Coderized
Рет қаралды 859 М.
Python Decorators: The Complete Guide
27:59
ArjanCodes
Рет қаралды 144 М.
What the Heck Are Monads?!
21:08
ArjanCodes
Рет қаралды 67 М.
5 Reasons Why You Should Use Type Hints In Python
13:54
ArjanCodes
Рет қаралды 103 М.
5 Tips For Object-Oriented Programming Done Well - In Python
16:08
What is Span in C# and why you should be using it
15:15
Nick Chapsas
Рет қаралды 247 М.
Uncle Bob’s SOLID Principles Made Easy 🍀 - In Python!
19:09
ArjanCodes
Рет қаралды 282 М.
More Python Code Smells: Avoid These 7 Smelly Snags
20:29
ArjanCodes
Рет қаралды 85 М.
If You’re Not Using Python DATA CLASSES Yet, You Should 🚀
10:55
Naming Things in Code
7:25
CodeAesthetic
Рет қаралды 1,9 МЛН
¡Puaj! No comas piruleta sucia, usa un gadget 😱 #herramienta
00:30
JOON Spanish
Рет қаралды 22 МЛН