This is the kind of shit I am terrified of. No one knows what else it might break. So now we gotta discover all the possible combinations of state just to recreate it. And it’s probably some trivial part of the app that we should rewrite anyway
Basically, it’s a shit show. Global variables polluting the namespace, functions marked async for no reason, tons of unnecessary function calls. Who the hell knows how they’re using moment.js (a deprecated package for manipulating date objects). In summary, every line has a code smell, it’s hard to read, naming conventions suck, and there is a ton of branching logic which contributes to the overall high cognitive complexity of the code. The person documenting this is probably having a great day trying to comment the code to understand the potential state positions so that it can be tested and refactored later
Really? It doesn't seem like it to me. If its not too much time for you, could you show a small example of how you'd do it better to avoid this?
moment.js
Okay, but what if it wasn't deprecated when this was written and its just x years old code?
naming conventions suck,
Could you give an example of a bad naming choice here and how you'd do it better?
there is a ton of branching logic
I think I'm inclined to agree. At the top, the "if(timezone)" part could have all been moved into another function, and that function converts that overarching if into a guard statement that returns early before doing anything if(!timezone) instead of checking if(timezone)
Branching logic is worse than you say I think. Several functions return 1 of as many as 4 things. These functions have high cyclomatic and cognitive complexity. Very hard to determine at first glance what to expect in a given scenario.
Naming. Instead of date, UTC, what about getDateString, getUTCString, etc. something indicating what the function is supposed to actually do. None of the functions operate clearly or have a name that tells me what to expect.
Eh, on second look there aren’t global variables and this is likely contained. Just offset bugs me for some reason.
Moment.js might not have been deprecated, but now that it is, it’s just another thing to go wrong later if a bug is found. Also, if they HAVE to remove and trade moment for dateFNS or something, this is going to be a pain.
No I really want to know. So like if its all async, its possible the dates and times returned are out of sync with each other, what else is bad about it?
I made another comment with the other issues. The fact they are async isn’t likely causing a problem. However, why are they async if they don’t perform asynchronous data calls? It’s just confusing and makes me look twice. It’s a code smell, or laziness.
I'm no expert, but making a Date/Time function asynchronous seems like a bad idea lol, unless multiple threads are gonna be running in 1 core (I think I'm wrong, I gotta read the documentation just to be sure) Edit: I didn't see the flair lol, now I know it's JS
I didn't see the flair lol, I thought it was another language. I actually know more about JS than other langs, and I can tell you you're right. However, there are functions such as setInterval that put other functions into a "Message Queue", allowing multiple pieces of code to run pseudo-simultaneously in 1 thread (the main, unless you use WebWorkers to create more threads and/or to use more cores)
Holy mama.... Seeing this makes me wanna sit on the floor, under the table, turn the lights off and start crying and begging for another life in another world in another universe...
This is probably what a product/project managers notes look like documenting estimates they pry out of devs. It meant a lot to the person writing it, but to everyone else it seemed like a waste of time, and after the fact it still does
24
u/kristallnachte Mar 15 '22
woah!!!
So they made this wrapper essentially...not even for the standard Date object, but for Moment?!?!?
3
u/raam86 Mar 15 '22
WhatToDo isn’t even used smh
121
u/[deleted] Mar 15 '22
now this is good bad code!
It's very clearly labeled. Clearly people spent time trying to organize it. And it's completely stupid.
Omg, I just realized this is all in a static class variable too, which is async for no reason. 10/10
72
u/rafal9ck Mar 14 '22
My eyes are DRY.
66
u/MurdoMaclachlan public boolean isInt(int i) { return true; } Mar 14 '22
Image Transcription: Code
I'm a human volunteer content transcriber and you could be too! If you'd like more information on what we do and why we do it, click here!
33
u/[deleted] Mar 14 '22
Wtf is going on?!
20
u/JonnyBoy89 Mar 15 '22 edited Mar 15 '22
This is the kind of shit I am terrified of. No one knows what else it might break. So now we gotta discover all the possible combinations of state just to recreate it. And it’s probably some trivial part of the app that we should rewrite anyway
12
u/PenFift33n Mar 15 '22
Makes me want to puke
Good post
23
u/Rudxain let let.let = 'let' Mar 15 '22 edited Mar 15 '22
I'm no expert, but making a Date/Time function asynchronous seems like a bad idea lol, unless multiple threads are gonna be running in 1 core (I think I'm wrong, I gotta read the documentation just to be sure)
Edit: I didn't see the flair lol, now I know it's JS
6
u/[deleted] Mar 15 '22
I hope there is no recursive code here. We faced async feedback loop in two redis channel due to configuration issue and lead's ass was on fire.
I think it's still burning till date.
3
u/evaxadam Mar 15 '22
Stuff like this is why im so afraid of working on other/older projects...
2
u/Razakel Mar 15 '22
Dickens code, where the author is paid per line.
1
u/[deleted] Mar 15 '22
Holy mama.... Seeing this makes me wanna sit on the floor, under the table, turn the lights off and start crying and begging for another life in another world in another universe...
1
u/itzNukeey Mar 15 '22
Using async for fun
1
u/flyinmryan Mar 16 '22
This is probably what a product/project managers notes look like documenting estimates they pry out of devs. It meant a lot to the person writing it, but to everyone else it seemed like a waste of time, and after the fact it still does
1
u/SquigglyHL Apr 09 '22
since when was "static" in js?