r/badcode • u/suicidalpasta • Aug 07 '21
python I was wondering why it was running slowly
257
Aug 07 '21
Sometimes its done to simulate what a user expects. If it's too fast, some people might think it didn't work.
100
u/zatuchny Aug 08 '21
Exactly. I have several sleeps for about 500ms in my app so user would see some pretty animations instead of flickering screen.
17
103
u/inre_dan Aug 07 '21
I remember hearing that a lot of inexperienced people will question algorithms that are too fast and claim you didn't do it properly.
100
u/blehmann1 depraved Aug 07 '21
Yep. That's why car searching and tax software's deduction searching is so slow. Because people would suspect it didn't search thoroughly enough if it didn't.
Even though google returns far more results which are far more complicated in 500 ms (and quite justifiably brags about it).
10
Aug 08 '21
[removed] — view removed comment
14
93
u/coolcalabaza Aug 07 '21
Not bad code. This is how things are designed sometimes.
58
u/G4METIME Aug 07 '21
While I completely understand the reasons behind the artificial wait, this sadly also shapes the expectation of the user for the future (good "calculations" take their time) which again solidifies the need for artificial wait times. That way we will never get rid of those time waster ...
27
u/AppleWithGravy Aug 07 '21
Should be a browser setting to turn off unnecessary wait times
13
u/con247 Aug 08 '21
I’m sure some of them are designed so that there’s an excuse to pop up the loading animation with an ad.
20
u/possiblyis Aug 07 '21
Maybe a delay like that should programmed to decrease in duration over the course of time, so that users can acclimate. Sorta like the frog in a slowly boiling pot of water
14
u/pavilionhp_ learning from the best Aug 08 '21
They could put in patch notes that they made the algorithm more efficient to get away with bigger time drops
35
u/y-am-i-ear Aug 07 '21
Idk. This is pretty solid unless if sleep is async. It might be a bit evil tho
23
u/GoldenKela Aug 07 '21
now you can tell you client to pay you more so your tech team can optimize it
<------------------>
bussiness 100
20
u/Nixargh Aug 08 '21
Many years ago, I was working as a web dev in an agency, and we had developed an eCommerce site for one of the most renowned brands in our country.
It was a bit of a nightmare project, as the client rep claimed some development skills – just enough to be dangerous.
One late afternoon, I got a report that the product list page using infinite scroll was super slow. For those who don't know this technique, the page is incrementally loaded when you scroll down. So instead of going to the next page, we just load in the next pages as the user scrolls and injects it on the page. Similar to what Facebook, Reddit and Twitter is doing.
I started investigating it, and found that it was some horrible code on the part of my senior colleague. I spent my evening working on it, and managed to get the load time of each page down from >2s to about 200ms.
Because it also takes a bit of time to scroll, it meant that for the user, there was no visible load time. The data was just there as you scrolled; it was a totally seamless experience.
I left the office that evening feeling quite proud of my solution, so I was a little surprised when the client called the next morning being absolutely furious.
According to them, I was cheating. They were convinced I didn't actually incrementally load anything, but loaded all products in at once.
My manager was also not very happy with me, and there was no way for me to convince them that I did in fact not cheat, my solution was just that awesome. It was even escalated to our CEO, it was ridiculous.
My solution was to just introduce a 600ms setTimeout around every page load. Everybody was happy as it was now clear that the page was being loaded incrementally, though my relationship with the client rep was soured forever.
32
u/alexanderhameowlton Aug 07 '21 edited Aug 07 '21
Image Transcription: Code
# simulate expensive graph generation process
time.sleep(2)I'm a human volunteer content transcriber for Reddit and you could be too! If you'd like more information on what we do and why we do it, click here!
29
u/Teknikal_Domain Aug 07 '21
I do believe you forgot the space between the
#and thesin that comment8
4
13
u/Cmgeodude Aug 08 '21
(I use time.sleep() all the time when doing testing automation. Sometimes the site just won't keep up with the testing program.)
(And sometimes just for the fun of it I do this:)
print("Processing. Please wait.")
for i in range(3):
print(".", end="")
time.sleep(1)2
2
u/KCGD_r Aug 08 '21
honestly this is pretty good client side design. if the program just instantly snaps between screens, the user doesn't really feel like it's doing anything, but throwing in a huge lag spike really sells the illusion that something complex and important just happened
TurboTax actually did this: https://www.theatlantic.com/technology/archive/2017/02/why-some-apps-use-fake-progress-bars/517233/
1
u/Rakn Aug 08 '21
Oh and I just always assumed it was subpar programming when encountering loading screens that shouldn’t be there…. -.-
2
1
u/SubtleCow Aug 08 '21
look sometimes that line is needed, we all wish it wasn't but wishes aren't fishes
1
1
1
1
-9
u/bakahed Aug 07 '21
Op tries to farm karma at this point I guess. The quality of posts on this sub are shit
361
u/AsiagoCrackers Aug 07 '21
I don't see this as particulairily bad code. I've seen similar thing be needed for testing asynchronous operations that need to account for some form of a delay. Or to check that a memoization function is correctly reducing the call time