No video

what is a boolean trap? (programming antipattern) (beginner - intermediate) anthony explains

  Рет қаралды 4,632

anthonywritescode

anthonywritescode

Күн бұрын

today I talk about a boolean trap, how you can spot one in code review, and how you can fix the problem using a few python features!
- all parameter types: • all python argument / ...
playlist: • anthony explains
streamed on / anthonywritescode
==========
twitch: / anthonywritescode
dicsord: / discord
twitter: / codewithanthony
github: github.com/aso...
stream github: github.com/ant...
I won't ask for subscriptions / likes / comments in videos but it really helps the channel. If you have any suggestions or things you'd like to see please comment below!

Пікірлер: 17
@StopThatShitPls
@StopThatShitPls 3 жыл бұрын
Why not just define two functions - pop_first and pop_last?
@anthonywritescode
@anthonywritescode 3 жыл бұрын
that would work well too!
@MagnusAnand
@MagnusAnand 3 жыл бұрын
@@anthonywritescode Here you have some solutions adamj.eu/tech/2021/07/10/python-type-hints-how-to-avoid-the-boolean-trap/
@jurgengmach4636
@jurgengmach4636 Жыл бұрын
I am waiting for the sequel: "what is a troolean trap?" 🤣
@420_gunna
@420_gunna 2 жыл бұрын
I haven't seen someone use the enum.Enum constructor like that before -- I usually see people write a class that inherits from Enum, then defines a bunch of class attributes like Tomato = "TOMATO", Lettuce = "LETTUCE", etc. Is using the enum.Enum primary constructor directly (like enum.Enum("Tomato") the same as writing a class that inherits from Enum with class attributes like Tomato = "Tomato"? I really need to look at how enums actually work under the hood :)
@anthonywritescode
@anthonywritescode 2 жыл бұрын
it's a bit magical -- acts as both a metaclass and a callable
@teslainvestah5003
@teslainvestah5003 2 жыл бұрын
I'd assume dct.popitem(True) would pop (3,4). Because if a method called popitem takes any argument, it should be an integer index. In my projects I just have unlimited line length, and never use positional arguments for anything unless some module (often pygame) forces me to.
@anthonywritescode
@anthonywritescode 2 жыл бұрын
True is an integer, checkmate athiests
@MagnusAnand
@MagnusAnand 3 жыл бұрын
cool video
@C0pernicus
@C0pernicus 8 ай бұрын
Is there an advantage to using an Enum over typing.Literal?
@marco_gorelli
@marco_gorelli 2 жыл бұрын
Do you know if there exists a tool to detect boolean traps? e.g. flake8 extension, or even a tool to re-write them. If not, I'm tempted to try writing one
@anthonywritescode
@anthonywritescode 2 жыл бұрын
not that I know of! but it'd be pretty easy to detect if the codebase uses type extensions (non-namedonly bool parameter) or a call which takes a boolean literal in a positional argument
@darrenlefcoe
@darrenlefcoe Жыл бұрын
great video, but why write code in terminal as opposed to a lightweight editor like vscode which is easier to do ?
@anthonywritescode
@anthonywritescode Жыл бұрын
"vscode" "lightweight" lmao
@darrenlefcoe
@darrenlefcoe Жыл бұрын
@@anthonywritescode fair enough. Just thought that some linting and intellisense might be helpful.
@anthonywritescode
@anthonywritescode Жыл бұрын
implying I don't have linting?
@darrenlefcoe
@darrenlefcoe Жыл бұрын
@@anthonywritescode respect to those who can operate without those tools...
python: str.translate (intermediate) anthony explains #205
10:43
anthonywritescode
Рет қаралды 1,5 М.
Алексей Щербаков разнес ВДВшников
00:47
Harley Quinn's desire to win!!!#Harley Quinn #joker
00:24
Harley Quinn with the Joker
Рет қаралды 16 МЛН
Son ❤️ #shorts by Leisi Show
00:41
Leisi Show
Рет қаралды 10 МЛН
My Favorite Code "Anti-Patterns" (Break These)
16:52
Conner Ardman
Рет қаралды 54 М.
all about xargs ! (beginner - intermediate) anthony explains #200
17:16
anthonywritescode
Рет қаралды 9 М.
Rust and RAII Memory Management - Computerphile
24:22
Computerphile
Рет қаралды 224 М.
py-spy saved our python 3.11 rollout (intermediate) anthony explains #568
13:48
python: what is weakref? (intermediate - advanced) anthony explains #366
10:40
Vim in 100 Seconds
11:53
Fireship
Рет қаралды 1,1 МЛН
I've been using Redis wrong this whole time...
20:53
Dreams of Code
Рет қаралды 353 М.
Алексей Щербаков разнес ВДВшников
00:47