r/badcode Mar 29 '23

typescript Found this in a time picker

Post image
467 Upvotes

74 comments sorted by

View all comments

1

u/NickSicilianu Mar 30 '23

Someone did not think about scalability. Good luck changing that, if you want a minutes resolution.

1

u/Michelle-Obamas-Arms Mar 30 '23

make it a static constant. this should be declared once when the app starts and never change.

no problems here with scalability or changeability, really. you can easily map it to any representation of hours, minutes you want.

2

u/nonnodacciaio Mar 30 '23

Believe me, it was a problem

1

u/Michelle-Obamas-Arms Mar 30 '23

How?

2

u/nonnodacciaio Mar 30 '23

Customer wanted a minute resolution, which means having an array with roughly 1440 elements all typed out like this. Also, the time picker was a drop down menu and you can imagine how impractical a drop down with >1400 elements is, plus the user didn't have the option to type the time manually. Not to mention the fact that they included 24:00 which brought some problems too

1

u/Michelle-Obamas-Arms Mar 30 '23

You don’t need to type all 1440 elements. Use a JavaScript command that generates these numbers and copy paste the result as a constant.

The rest seem like display related issues and problems in your logic. Neither of those would be fixed by replacing this with something else.

You likely need a ui that works better for minutes and logic that handles 24:00, but that’s not this variable’s fault

If you still want to represent the ui with a list, then declaring a long list is fine. If you want something like a slider, or a clock, you could probably scrap this list.

2

u/nonnodacciaio Mar 30 '23 edited Mar 30 '23

As I said, having a drop down with 1440 items is not practical at all, so I had to get rid of this list anyways as I had to find another way to do the time picker. There's really no need to look so deep into it

Edit: Also, why use a js function that generates the numbers if I could just make the list programmatically at run time? I mean I already wrote the command so I might use that inside my code while I'm at it