Developers build the best tools for developers – and are now defanging the AI menace
CodeSOD: Weekly Calculated
There's a language out there called "Progress Advanced Business Language" (or "Open Edge Advanced Business Language"). Just hearing that string of words in a sequence tells you you're in for it. It's a verbose, "English-like" programming language. But we're not here to pick on the language.
A long time ago, Mirjam had the "pleasure" of working in a Progress ABL environment. At some point, one of the developers had needed to find a date six months prior to the current date. It didn't need to be accurate, and thus said developer littered the code with comments reminding everyone that it didn't need to be that accurate. They arguably spent more time defending the choice to be inaccurate than it would have taken to write code that would have been accurate.
Mirjam doesn't have the code anymore, so what we have here is a mix of her remembered pseudocode, Progress syntax, and my attempts to clarify all of it. Let's not worry too much about the language, and instead focus on the logic:
ASSIGN v-date = TODAY. /* Calculates the current week/year */ RUN week.p(INPUT v-date, OUTPUT v-weeknumber, OUTPUT v-year). IF v-weeknumber > 26 THEN ASSIGN v-weeknumber = v-weeknumber - 26. ELSE ASSIGN v-weeknumber = 52 - 26 - v-weeknumber v-year = v-year - 1. /* Turn the result of that calculation back into a date */ RUN week2.p(INPUT v-weeknumber, INPUT v-year, OUTPUT v-resultdate).This code gets the current date. It then breaks that into week number of the date (1-52), and the year of the date. Then, if the week number is greater than 26, it subtracts 26 from it, giving us a date half a year ago, ish. If the current weak number is less than or equal to 26, we do 52 - 26 - v-weeknumber, and decrement the year. Which yes, is a fairly round about way to handle the rollover- 52 - 26 happens to be… 26.
It's worth noting, that as primitive looking as this syntax is, Progress ABL does have an ADD_INTERVAL function, which lets you do date arithmetic, without all this nonsense. In fact, Mirjam went ahead and replaced all of this with a single line.
That said, as a little bonus WTF, Progress does have some weird date quirks, for example, you can construct a date from an integer. Which has a very unsurprising (but also, weirdly surprising) range of possible values:
The value of the expression cannot be a date value before 12/31/-32768 or after 12/31/32767.
At least that covers a range that includes both the discovery of agriculture and the eventual rediscovery of agriculture after the event that enters into legend as "The Fall".
Moment balaclava-clad thieves use a stolen telehandler to rip a cash machine from a Nationwide before lowering it into a getaway truck
A12 delays as traffic builds due to 'emergency repairs'
Toy Story 5 review: This is more than yet another sequel... it's a five-star Hollywood miracle
Five-time champion jockey Willie Carson reveals his final meeting with the late Queen - having ridden her beloved horses for nearly two decades
Miles of delays on A12 as 'emergency repairs' carried out
Miles of delays on A12 as 'emergency repairs' carried out
Who's the new Queen Bee of WAGs? As England kick off their World Cup, the women cheering them on
I've dressed countless women for big events: Here are the chic and timeless hats that won't make you look dated
Aldi plans to open new supermarket in this Essex town as part of national expansion
Jelly Roll's daughter, 18, breaks silence on his divorce despite close bond with stepmom Bunnie XO... as she calls it a 'private family matter'
Boss of children's services at council which missed a string of chances to save murdered baby Preston Davey received a £23,000 golden goodbye after ending time there 'on such a high'
World Cup Unfiltered Poll: Will England win their opening game against Croatia tonight?
Once-failing Essex secondary school 'rapidly and substantially improved' in rating turnaround
Under siege from newbuild estates: Million-pound homeowners fear their village is being turned into a 'metropolis' after series of controversial planning applications
Hundreds march as villagers fight plans for giant Great Bardfield sand quarry
Ex-serviceman sent sexual texts and pictures to who he thought was 14-year-old
World Cup fans claim the tournament is RIGGED as Lionel Messi avoids a red card after stamping on rival before scoring hat-trick
HPE Tempts VMware Users, Partners With Year of Free Virtualization Software
Read more of this story at Slashdot.