Thread 105974709 - /g/ [Archived: 911 hours ago]

Anonymous
7/21/2025, 7:09:55 AM No.105974709
file
file
md5: 8ad1292680eaedbf3d27a0f0adf1c635🔍
Is this bad practice?
Replies: >>105974720 >>105974761 >>105975678 >>105975716 >>105975972 >>105976174 >>105976520 >>105976533 >>105977042 >>105977600 >>105977654 >>105977663 >>105977686
Anonymous
7/21/2025, 7:11:46 AM No.105974720
>>105974709 (OP)
I don't understand shit
Anonymous
7/21/2025, 7:11:49 AM No.105974721
Yes.
Anonymous
7/21/2025, 7:17:52 AM No.105974761
>>105974709 (OP)
Will probably eat your cpu if f is called often
Replies: >>105975934
Anonymous
7/21/2025, 9:59:05 AM No.105975678
>>105974709 (OP)
why not just do the division there and accept numerator and denominator in the parameters and check if denominator is 0?
instead of allocating god knows how much resources python uses for an additional function call and hitting slow exception paths
Replies: >>105979384
Anonymous
7/21/2025, 10:06:10 AM No.105975716
>>105974709 (OP)
i dont get why the extra function
Replies: >>105975736
Anonymous
7/21/2025, 10:11:37 AM No.105975736
>>105975716
He's trying to do the thing that Python calls a "decorator", which here is a wrapper. He's also mentally retarded and wants a division that can't happen to return a value. Unemployable shit.
Replies: >>105979384
Anonymous
7/21/2025, 10:22:44 AM No.105975789
PR declined
Anonymous
7/21/2025, 11:03:16 AM No.105975934
>>105974761
Sir, this is Python.
Anonymous
7/21/2025, 11:10:04 AM No.105975972
>>105974709 (OP)
Why the fuck are you dividing by zero like a retard?
Replies: >>105979384
Anonymous
7/21/2025, 11:45:26 AM No.105976174
>>105974709 (OP)
Yes, using decorators in Python is generally a bad idea.
Anonymous
7/21/2025, 12:46:16 PM No.105976520
>>105974709 (OP)
https://github.com/ajalt/fuckitpy
Anonymous
7/21/2025, 12:46:59 PM No.105976525
I dont understand anything
Anonymous
7/21/2025, 12:48:27 PM No.105976533
>>105974709 (OP)
Defining a function within a function has always felt wrong
Only ever done it in very weird situations
Replies: >>105976816 >>105977477 >>105977508
Anonymous
7/21/2025, 1:36:39 PM No.105976816
>>105976533
why a wrapper doe?
why not just a guarding clause?
Anonymous
7/21/2025, 2:10:34 PM No.105977027
It's a bad practice to use python at all.
Replies: >>105978628
Anonymous
7/21/2025, 2:11:42 PM No.105977042
>>105974709 (OP)
SAAAAR please refer to compliance code 9586/2955Z. This is not ok, Benchod Bastard!
Replies: >>105979384
Anonymous
7/21/2025, 3:23:17 PM No.105977477
>>105976533
t. brainlet who can't handle abstraction
Replies: >>105977508
Anonymous
7/21/2025, 3:26:46 PM No.105977508
>>105976533

I don't even get the point. Never in my life have I needed to do that. Seems like shit for queers to stroke their ego over like >>105977477

If some junior tries to pass that shit by me he's getting berated
Replies: >>105977707
Anonymous
7/21/2025, 3:38:09 PM No.105977600
>>105974709 (OP)
Python is a Lisp.
(defun /0=0 (f)
(lambda (&rest args)
(handler-case (apply f args)
(division-by-zero () 0))))
Anonymous
7/21/2025, 3:45:50 PM No.105977654
>>105974709 (OP)
in rust, this is just:

num.checked_div(0).unwrap_or_default()


imagine not having monads in 2025.
Anonymous
7/21/2025, 3:47:34 PM No.105977663
>>105974709 (OP)
You return 0 if the function has a divide by zero exception, but it isn't clear what f() is supposed to return and if your return is even appropriate.

so yes, it's bad practice.
Replies: >>105979384
Anonymous
7/21/2025, 3:50:21 PM No.105977686
>>105974709 (OP)
also you should use @functools.wraps(f) so your decorator doesn't fuck up the function name + docstring.
Anonymous
7/21/2025, 3:52:53 PM No.105977707
>>105977508
>I don't get the point of decorators
do you even code or what? decorators are common patterns in python because there aren't a lot of good ways to do certain things, like resource cleanup or dependency injection. yes, with: exists, but it isn't quite as useful in many cases for more complex types.
Anonymous
7/21/2025, 5:47:19 PM No.105978628
>>105977027
/thread
Anonymous
7/21/2025, 6:59:21 PM No.105979384
>>105975972
>>105975678
>>105977042
>>105977663
>>105975736
It's in some researchers NLP code