what is a boolean trap? (programming antipattern) (beginner - intermediate) anthony explains
ฝัง
- เผยแพร่เมื่อ 11 ม.ค. 2021
- 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/asottile
stream github: github.com/anthonywritescode
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! - วิทยาศาสตร์และเทคโนโลยี
Why not just define two functions - pop_first and pop_last?
that would work well too!
@@anthonywritescode Here you have some solutions adamj.eu/tech/2021/07/10/python-type-hints-how-to-avoid-the-boolean-trap/
I am waiting for the sequel: "what is a troolean trap?" 🤣
cool video
Is there an advantage to using an Enum over typing.Literal?
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
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
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 :)
it's a bit magical -- acts as both a metaclass and a callable
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.
True is an integer, checkmate athiests
great video, but why write code in terminal as opposed to a lightweight editor like vscode which is easier to do ?
"vscode" "lightweight" lmao
@@anthonywritescode fair enough. Just thought that some linting and intellisense might be helpful.
implying I don't have linting?
@@anthonywritescode respect to those who can operate without those tools...