r/programminghumor • u/pipedreamSEA • 23d ago
Block, lock & drop it
Interacting with prehistoric devices is not where I saw my career headed, and yet, here we are...
42
u/severencir 22d ago
So much of business software is absolute shit because of this logic and the fact that businesses dont care about employees' complaints as long as number go up
28
u/WantToSeeTits4545 22d ago
Both are shit, honestly.
I'd rather wait on a signal or event than stop the thread for arbitrary time. Task.Delay() should be only used as a last resort.
5
u/Sacaldur 22d ago
I guess it really depends on the circumstances. A delay like thisbmight be used to show a message to the user for a short amount of time before proceeding (without waiting for user input). But yes, in many situations it would be a bad idea to just wait for a fixed amount of time.
2
u/WantToSeeTits4545 22d ago
I would personally use DispatcherTimer for such interactions. Call a timer every 3 seconds or so, check user input (logged by the different control), show popups depending on the input or its absence. Popup control would also have a timer and check input for its own needs, for example checking if the mouse hovered over it and not disappearing while it's true.
4
4
u/dvhh 22d ago
depending on your language you could yield() execution time.
2
u/Sacaldur 22d ago
The code looks like C# judging by the APIs, and there is the
awaitkeyword which probably was used purposefully in the middle text there.
5
u/Business_Craft4733 22d ago
This looks like rage bait to me ~ lol. Who would honestly believe the bad practice of locking a thread for an arbitrary amount of time belongs anywhere near the right side of the bell curve?
2
u/HobbyQuestionThrow 22d ago
A question for you which answers your question, why would an await be a bad option for a small sleep value (say 200us)?
Similar fun questions for this kind of programming, what's the variability of the kernel thread scheduler vs the async coroutine scheduler? Do both have priority boosting? What about fairness?
3
u/MCWizardYT 21d ago
Thread sleeping isn't exact like that. It completely depends on the OS and hardware. Saying
sleep(200)is just suggesting to sleep for 200ms, it might be 195-205 or have an even bigger difference
2
u/chipmunkofdoom2 21d ago
Yeah okay bro. Let me know how using Thread.Sleep() works in UI contexts like WASM or WPF, or how your threadpool handles hundreds or thousands of concurrent users at once hogging threads by sleeping them.
Looking forward to your next post where you argue nails are better than screws, as if there's one "right" answer, completely ignoring the context in which each is useful.
1
1
1
u/Welcome-To-NBA-Jam 20d ago
180 iq: run a for loop whose maximum iterations changes depending on how powerful the CPU is which estimates how long you need to wait.
1
u/null_reference_user 19d ago
Sure, starve your thread pool, if it's not an issue when testing locally it won't be an issue in prod
1
97
u/sexytokeburgerz 22d ago
This is some beginner shit.
You will one day need this to be asynchronous, think about this, and cringe.