this post was submitted on 14 Dec 2023
1012 points (99.2% liked)
xkcd
8766 readers
40 users here now
A community for a webcomic of romance, sarcasm, math, and language.
founded 1 year ago
MODERATORS
you are viewing a single comment's thread
view the rest of the comments
view the rest of the comments
To break it down a bit further, the code that was provided is specifically trying to get the 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.
Thanks!
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.