Тёмный
ArjanCodes
ArjanCodes
ArjanCodes
Подписаться
On this channel, I post videos about programming and software design to help you take your coding skills to the next level. I'm an entrepreneur and a university lecturer in computer science, with more than 20 years of experience in software development and design. If you're a software developer and you want to improve your development skills, and learn more about programming in general, make sure to subscribe for helpful videos.

I post a video here every Friday. If you have any suggestion for a topic you'd like me to cover, just leave a comment on any of my videos and I'll take it under consideration.

Thanks for watching!
Avoid These BAD Practices in Python OOP
24:42
14 дней назад
My FAVORITE Error Handling Technique
16:01
21 день назад
6 Easy Tips to Design an AWESOME REST API
23:32
2 месяца назад
Build AWESOME CLIs With Click in Python
25:12
2 месяца назад
Every Developer Should Know This
15:38
2 месяца назад
5 Tips for Writing Clean Python Code
25:59
3 месяца назад
Build, Deploy, and Host a Backend From A to Z
14:07
3 месяца назад
Git Hooks: We’re Not Using Them Enough!
4:06
4 месяца назад
The Unit of Work Design Pattern Explained
12:37
4 месяца назад
How To Do AI Prompt Templating
7:00
4 месяца назад
AsyncIO and the Event Loop Explained
13:34
4 месяца назад
How to Avoid Dependency Hell in Programming
5:20
4 месяца назад
Rust Handles Errors Way Better Than Python
17:48
4 месяца назад
Rust’s Most Unique Feature
13:38
5 месяцев назад
Комментарии
@TheEvertw
@TheEvertw 8 часов назад
There are a lot of people who think JavaScript (of all languages) is better than Python because it is faster. That is such a load of cr@p. As the UNIX gurus knew, "Programmer time is expensive. Computer time is cheap." So I will consider a language that makes me more productive as a programmer far superior compared to a language that runs my code a bit faster. Note that this maxim is from the seventies. Compared to back then, computer time has become many orders of magnitude cheaper, and programmer time quite a bit more expensive. And while Python is from a later age and not quite a scripting language, scripting languages were invented by the UNIX people for exactly this reason.
@TheEvertw
@TheEvertw 9 часов назад
When handling default arguments, I often use the following line to set them at runtime: `timestamp = timestamp or time.time()` This works if the default value is `None`, because `None` is a "False" value and a valid timestamp is a `True` value. It also uses the fact that Python passes on the actual value of the first `True` element in an `or` operation, and does not evaluate the second value if the first one is already `True`. If the first value is `False`, it yields the second value regardless of whether it is `True` or `False`.
@AISWARYAR-et6rp
@AISWARYAR-et6rp 12 часов назад
How should get that toml file
@yishan9598
@yishan9598 14 часов назад
I have a question about dataclass VS normal class. When I use dataclass define one kind of data, at the beginning it is perfect. However, then more and more methods were added based on the attributes of the dataclass and the class is becoming more and more heavy and some of the methods doing something very complicated. I am not sure whether this is a good practice and whether I should convert the dataclass to a normal class. Could you please give me some suggestion about the use case of normal and data classes?
@HugginsNoel-t2i
@HugginsNoel-t2i 20 часов назад
Thea Passage
@treyhannam3806
@treyhannam3806 День назад
Thank you for this video, helped me get up to speed in a couple days and create something useful!
@ArjanCodes
@ArjanCodes 7 часов назад
You're very welcome!
@UNgineering
@UNgineering День назад
I also read that the function name specificity should be inversely proportional to its scope, e.g. a function collect_and_summarize_invoices might be used once or twice within the same class/module, but if a function is used all over the place, it should have a very short name, e.g. python's "open" function. thank you for another great video.
@AshishRanjan-jn7re
@AshishRanjan-jn7re День назад
+91 & +92 are eternal enemies
@alexsece
@alexsece День назад
Just discovered your video and it is very good! Looking forward to watching the next one :)
@ArjanCodes
@ArjanCodes День назад
Glad you enjoyed it!
@ewerybody
@ewerybody День назад
3:15 importing all these from `string_utils` :/ I'd argue you could have just imported `string_utils` and replace the class with the module name!
@rma-nm5vb
@rma-nm5vb День назад
There is an old rule to all of this: KISS :-)
@demolazer
@demolazer День назад
I recently learned about pytest fixtures, they are awesome!
@ArjanCodes
@ArjanCodes День назад
💡 Get my FREE 7-step guide to help you consistently design great software: arjancodes.com/designguide.
@Baloch-g2h
@Baloch-g2h День назад
Video was awesome can you make an other video on how declare value to a variable in depth .
@gaaligadu148
@gaaligadu148 День назад
What if there was a global variable named "T" in the code base ? I know that we aren't supposed to name variables like that. But would the generics still work ?
@serxhiorira4715
@serxhiorira4715 2 дня назад
there is a plugin called devotes in vscode!
@m_sitso
@m_sitso 2 дня назад
your file system here is confusing me, pls try showing the desktop. It will be way better
@jakobullmann7586
@jakobullmann7586 2 дня назад
Also crucial: function arguments should always be annotated with the most general protocol possible, but the return type should always be as specific as possible type as possible.
@jakobullmann7586
@jakobullmann7586 2 дня назад
I disagree about the options object. It’s an approach that is very common in Java and C#, because those languages only know positional arguments, but in Python the configurable fields of the options object are more commonly passed as keyword arguments.
@dharikarsath8852
@dharikarsath8852 2 дня назад
I tried to make this work on classes that takes different arguments like taking differ entire table object, and couldn't able to implement it. I think this approach doesn't suit that I guess
@dharikarsath8852
@dharikarsath8852 2 дня назад
Like I wanted to register user on user table, his skills on skill table and the services he provides with service table.
@rontheoracle
@rontheoracle 2 дня назад
If one can start from A and finish at B by just using function, then why use class? Classes look and feel complicating, more codes are needed to use classes, with no major benefit compared to functions. Seems like classes are only useful in some really edge cases. Thanks for listening to my rants.
@difegam3
@difegam3 2 дня назад
If I’m not mistaken, starting with Python 3.7, the order of dictionaries is guaranteed.
@hcubill
@hcubill 2 дня назад
Loooved this video, so clear and helpful! Keep them coming!
@ArjanCodes
@ArjanCodes 2 дня назад
Happy you liked it. Will do 😊
@Andrumen01
@Andrumen01 2 дня назад
You can also define your own types as variables, and the IDE will recognize them as doctypes (at least PyCharm does). Just define, for example: Real = int | float And use it as: def whatever_function(arg: Real) -> Real: ... It works for me in the latest version of PyCharm.
@ywywywyw612
@ywywywyw612 2 дня назад
Agree, type aliases are very handy for cases where the data type might change e.g. you want to change a string to a UUID
@pokerchannel6991
@pokerchannel6991 2 дня назад
wow. you make VS look so useful. It seems that if you use the docstring helper, you will end up with soem really professional looking docstrings. It makes other people think that you really pay attention to details and make very beautiful looking code. And by using VS, you don't have to expend mental bandwidth trying to figure out what to format a docstring. Nice. You make a good case for VS. If I were a developer, I would def see that VS is a high on the list of preferred ide
@pokerchannel6991
@pokerchannel6991 2 дня назад
when I try to hint that my output is generator, I get an error saying generator is undefined. I have to from typing import Generator as generator. Only then, can I hint def fx() -> generator:
@jaime2911
@jaime2911 2 дня назад
the underscore notation is known snake case, just for curious, as well as camelCase has a name. Super good videos 👍🏻👍🏻
@DrGreenGiant
@DrGreenGiant 2 дня назад
An approach I use is by going a level up to the function that is calling the one I'm about to write. In that calling function, the name and arguments should read in plain English, almost like a story. Ultimately, if you've got your face in a function you can see what it does, but if you are in the outer scope, a good signature means you don't need to dig deeper on that line to reason about what's going on. Great video, thank you!
@ArjanCodes
@ArjanCodes 2 дня назад
Great tip, thanks for sharing!
@matthewnuzzaco2849
@matthewnuzzaco2849 2 дня назад
This is a great tip I’ve not heard before.
@DrGreenGiant
@DrGreenGiant 2 дня назад
You can thank my old C++ days for that one! :)
@quillaja
@quillaja 2 дня назад
Even `calculate_total_minus_discount` is ambiguous. Is the discount subtracted per item? Is the discount a percentage of the total? If the discount is a percentage, should the user pass the percentage as an actual percentage (ie 25%) or a fractional proportion (ie 0.25)? Definitely the best function name would be `calculate _total_of_all_items_and_then_subtract_discount(item_prices: Iterable[int], total_discount_as_an_amount_of_money: int)`. If only there was a way to somehow leave a comment for a function that would document such particulars!
@quillaja
@quillaja 2 дня назад
What about NamedTuple for your Options instead of Dataclass? You can unpack a tuple.
@ChiquitaBone-p7t
@ChiquitaBone-p7t 3 дня назад
enterprise-ai AI fixes this. Avoid these bad practices OOP.
@MCeplekake
@MCeplekake 3 дня назад
A tip I want to share which is slightly related is the “extract function” feature that a lot of IDEs have, which allows you to highlight a code block and press a hotkey to turn it into a function automatically. At least pycharm has this, and I guess you can find extensions for it for most of the popular editors. You can also do the inverse operation, meaning turning a function into inline code).
@estevaoyt
@estevaoyt 3 дня назад
Man, what a beautiful video, I've learned a lot, thank you!
@ArjanCodes
@ArjanCodes 2 дня назад
Happy to hear you enjoyed it!
@karlwiren7517
@karlwiren7517 3 дня назад
Great video Arjen, yes would love to hear your thoughts on function body design 👍
@fatihduzenli5893
@fatihduzenli5893 3 дня назад
What the function!
@Golgafrincham
@Golgafrincham 3 дня назад
Regarding options for functions, I think it is a pretty neat solution to use typing.Unpack together with TypedDict. It basically enables you to add keyword arguments to a function that gets type-checked and provides completion. You would get a function signature such as: def function_x(session: Session, **options: Unpack[Options]): ... With Options defined as: class Options(TypedDict, total=False): """Options for function X.""" begin: datetime end: datetime count: int descending: bool I frequently use this when I'm creating functions that wraps an API endpoint or Database model. It allows me to create fairly general functions but still allow customization about for example how many elements should be returned, certain filters, or ordering. In case of a SQLAlchemy model, this could look like: def function_x(session: Session, **options: Unpack[Options]): query = session.query(Measurements) if begin := options.get("begin"): query = query.filter(Measurements.timestamp >= begin) if descending := options.get("descending"): query = query.order_by(Measurements.timestamp.desc()) if end := options.get("end"): query = query.filter(Measurements.timestamp <= end) if count := options.get("count"): query = query.limit(count) return query.all()
@bokistotel
@bokistotel 3 дня назад
This programming nitpicking is getting ridiculous
@plussin2760
@plussin2760 3 дня назад
자바 코틀린에 비해서 동시성이 떨어질 수 있는 원인이 GIL에 있었구나
@flightmansam
@flightmansam 3 дня назад
Gosh you’re awesome arjan!
@menscheins125
@menscheins125 3 дня назад
Where I can find more info on this notation: def add_number_to_each_element_v3[Numeric: (int, float, Decimal)] ? Numeric is new to me.
@timelschner8451
@timelschner8451 3 дня назад
Hi Arjan, thanks alot for the Video. What do you think about retuning a bool for functions that otherwise could return None? When using a bool as return one can control the main process by knowing If the function actually did work or would you argue that Program flow determines this anyway? Cheers
@guidodraheim7123
@guidodraheim7123 3 дня назад
(a) I do usually teach my guys to use "Iterator" when a (single) yield-statement is used in a function. The editor may detect Generator as the actual return type but it's not a good idea to be that specific. (b) I do also teach my guys to try to use "None" as the default as often as possible, and the actual non-nullable value can be set in a single line after the header - "value = value if value is not None else default". That's even more readable than a full if-block. In terms of string-values you would also want "value = value if value else default" anyway as usually an empty string is not an acceptable value.
@demolazer
@demolazer 3 дня назад
I can't write a function without type hints now, it's just automatic. They are worth using for the IDE hints alone IMO, in Neovim if I have set a function to take an int and accidently returned a string elsewhere, I know before even running any code. Saves a lot of time and frustration in our dynamic typing world.
@dragonfly-7
@dragonfly-7 3 дня назад
Maybe that's related to my programming history - I was tought pure C (K&R 2nd ed.) back in the late 1980ies - but how about abbreviating object names ? E.g. "calculate_total_price_including_discount" becomes something like "calc_ttl_prc_incl_dscnt" with arguments abbreviated similarly ? Is this an absolute no-go ? I hope not ... ;-)