Comment on xkcd #2867: DateTime
reverendsteveii@lemm.ee 11 months agoholy shit, yeah it would have. tyvm, I’ll be putting in a PR first thing monday!
Comment on xkcd #2867: DateTime
reverendsteveii@lemm.ee 11 months agoholy shit, yeah it would have. tyvm, I’ll be putting in a PR first thing monday!
Jarix@lemmy.world 11 months ago
Would you mind trying to explain (ELI5 style) what you did before and why you are excited for this new method for those of us who dont understand code?
reverendsteveii@lemm.ee 11 months ago
it does in a way that’s been reviewed, vetted and tested by a lot of people the thing that I’m trying to do with code that’s only ever been seen by me and one other guy and has been tested to this best of my ability, which i hope is quite good but one person can easily miss edge cases and weird coincidences.
Jarix@lemmy.world 11 months ago
So how is the new thing different/better (other than less lines i guess?) If you dont me asking
hikaru755@feddit.de 11 months ago
It’s easier to understand, easier to review for correctness, and less likely to cause problems with additional changes in the future. Even though it sounds counterintuitive, software developers generally try to write as little code as possible. Any code you write is a potential liability that has to be maintained, so if you can instead just use code that others have already written and that has been tested, you’ll want to use that. (Note that “less code” doesn’t mean fewer lines of code, it means less logical complexity, which is often, but not always, also less in terms of characters/lines)
reverendsteveii@lemm.ee 11 months ago
it’s simpler and a lot easier for another engineer to look at and understand later, so they can verify that it’s right or change it if it’s wrong or we decide to do something a little bit different. it’s also been reviewed and tested by a lot of people working in a lot of cases that are all a little bit different from one another, so the odds that their code is correct are better than the odds that my code is correct, all other things being equal
And009@reddthat.com 11 months ago
Tried and tested, now gotta brush up those searching skills and use llm to get your work done quicker
drislands@lemmy.world 11 months ago
To break it down a bit further, the code that was provided is specifically trying to get 5e last day of a month, which I’ll call Month X since it will vary. The code is doing these things, in this order:
All this to get the last day of the month from Month X. The reason they did it this way is so they didn’t have to say “Is this February? Then get day 28. Is this January/March/etc? then get day 31.” and so on.
The code that the other user provided will instead get the last day of Month X without having to do all those steps. It’s doing something in the background to get the same data, but the coder doesn’t have to worry about exactly how because they can trust it will work as expected.
It ultimately boils down to the user carving out a round piece of wood, fitting it on an axle and bolting it on, then to find someone already has cheap wheels for sale that are more stable than what they just made.
Jarix@lemmy.world 11 months ago
Thanks!
drislands@lemmy.world 11 months ago
You’re welcome! A big part of coding is finding how other people solved the problems you’re solving and finding how to incorporate their work into yours.