- Feature Articles
- CodeSOD
- Error'd
- Forums
-
Other Articles
- Random Article
- Other Series
- Alex's Soapbox
- Announcements
- Best of…
- Best of Email
- Best of the Sidebar
- Bring Your Own Code
- Coded Smorgasbord
- Mandatory Fun Day
- Off Topic
- Representative Line
- News Roundup
- Editor's Soapbox
- Software on the Rocks
- Souvenir Potpourri
- Sponsor Post
- Tales from the Interview
- The Daily WTF: Live
- Virtudyne
Admin
The code doesn't check
self.purposes
against an array. This is Python, so["special"]
is a list of one element.But regardless, this code smells strongly of malicious compliance.
It also implements annual mileage for someone or something that works seven days a week, 52 weeks a year, with no allowance for weekends, public holidays, and other opportunities for slacking off.
Admin
Perhaps they just handed the spreadsheet to ChatGPT and ask it to translate it to Python. Too early? Maybe, but I guess it won't be long until we see such kind of WTFs in the wild.
Admin
Using 365 for the number of days in a year, only gets it right 303 times in the 400 year cycle of the Gregorian calendar.
I tend to use 365.2425 as the average number of days in a year.
Admin
It also fails to account for the year 46BC problem. That's the one that lasted 445 days on account of the guy in charge of the calendar being off fighting a civil war against the people that told him to do it.
That and leap years. It fails for those as well.
Admin
So you always get paid for exactly 60 "special" miles per day regardless of how many you actually drive?
Admin
Honestly the lack of leap year handling isn't all that WTF-y compared to the rest of it.
Admin
However, it's based on an average
mileage_per_day
, and we have no idea how this was formed. I guess, with all those biases and clamping applied, it doesn't matter that much.Admin
I called lists arrays before Python was a twinkle in Guido's eye, and Python's lists aren't even real lists- they're indexable arrays. When you do everything with CONS, CAR, and CDR, then they can be lists.
Admin
So, if I'm reading this right, if the "special" checks are true then it subtracts mileage_per_day from 60, then adds it to mileage_per_day, thus it will always get 60. And 60 * 365 + 2000 is 23,900 so the max check for 24,000 miles is unnecessary. Although I guess if the theory about possibly having other options in the list is true, then it could be mileage_per_day + 25, in which case the max check might do something.
Admin
WTF. the max() operation will never result in a value greater than 4000, so the min() operation will always result in a value 4000 or less.
That can't be right, the code must have been copied wrong.
Admin
That about 46BC is pretty much backwards. Julius Caesar did not neglect the calendar (even though he was fighting a civil war with the Senate while pretending to serve it), he corrected past neglect, then introduced a new calendar.
The old Roman calendar was lunisolar. The months started on the new moon, so were 29 to 30 days. Some official had the job of looking at the sky and deciding when it was the new moon to start the next month. Their year had 12 months, March - February, but that was about 11 days short of the solar year. To keep the calendar aligned with the seasons, they added a 13th "intercalary" month every two to three years. Other cultures with lunisolar calendars did elaborate measurements and calculations to create a chart of where the intercalary months would fall for decades ahead. The Romans just added another job onto one of their existing officials; go look at the sky and judge whether the extra month was needed.
Sometimes the man in charge was busy and forgot to add the intercalary month - or perhaps felt politically vulnerable and didn't want to be accused of deliberately stretching the terms of the consuls and other officials that were elected in March. By the time Caesar became the unofficial dictator of Rome, the calendar had slipped nearly 3 months behind the season. So Caesar added 3 intercalary months to the year and put the calendar back on track. Then he introduced a new solar calendar that would automatically stay on track for centuries: 12 months of fixed lengths, not linked to the phase of the moon, total 365 days. Because the astronomical year is about 365-1/4, every fourth year there would be an extra day at the end of February. He rewarded himself for this work by renaming Quintilus (#5, counting from March) after himself, then taking a day from February and adding it to July.
It wasn't perfect. 365-1/4 days/year is off by about 3 days in 400 years, so in the 16th Century Pope Gregory introduced another correction. But Caesar's calendar outlasted his Empire.
Admin
FWIW, back when I was working on federal gov't contracts, mileage commuting to work was of course not chargeable. If we travelled to some other place, we could only charge the difference between distance to said location and our normal commuting distance. I bet that rule is blended in here, and one of those magic numbers relates to his normal commute.
Admin
Also using this syntax is just nightmare: weekly_miles += extra_miles if "special" in self.purposes else 0 and why else 0? just drop it
Admin
Sorry, but you're wrong. max(x,y) returns the maximum of the two inputs. Hence, max(5000,4000) returns 5000. Similarly, min(max(25000,4000),50000) returns 25000. I'm not a fan of the code, but it is correct.
Admin
Not sure why they need to enforce a minimum of 4000, unless self.mileage_per_day can be negative, which seems unlikely. If it must be >= 0, then it's going to be at least 25, * 365 + 2000 = 11125.
I think this code looks like the rules keep getting bumped and tweaked, so different bits made a bit more sense in some previous versiona.
Admin
Regarding the ChatGTP reference above: 1- This code had got to be human made because no machine could write such silliness. 2- I hope we never ever train code bots on such low quality code, to avoid #1. 3- Unfortunately "errare est humanum" and thus #2 will happen.
Admin
Thanks for the correction.
I was operating off memory from a history class that happened many decades ago so my memory failed me.
Admin
Yes this is all very well, but where people in this company expensing mileage in 46BCE?