A hybrid SUV that can really go the distance: Chery Tiggo 7 is a Chinese car that will tick the boxes for families in Britain
Home insurance premiums fall 9% in a year with London and Scotland seeing the sharpest drops
US Cybersecurity Adds Exploited VMware Aria Operations To KEV Catalog
Read more of this story at Slashdot.
CodeSOD: Qaudruple Negative
We mostly don't pick on bad SQL queries here, because mostly the query optimizer is going to fix whatever is wrong, and the sad reality is that databases are hard to change once they're running; especially legacy databases. But sometimes the code is just so hamster-bowling-backwards that it's worth looking into.
Jim J has been working on a codebase for about 18 months. It's a big, sprawling, messy project, and it has code like this:
AND CASE WHEN @c_usergroup = 50 AND NOT EXISTS(SELECT 1 FROM l_appl_client lac WHERE lac.f_application = fa.f_application AND lac.c_linktype = 840 AND lac.stat = 0 AND CASE WHEN ISNULL(lac.f_client,0) <> @f_client_user AND ISNULL(lac.f_c_f_client,0) <> @f_client_user THEN 0 ELSE 1 END = 1 ) THEN 0 ELSE 1 END = 1 -- 07.09.2022We'll come back to what it's doing, but let's start with a little backstory.
This code is part of a two-tier application: all the logic lives in SQL Server stored procedures, and the UI is a PowerBuilder application. It's been under development for a long time, and in that time has accrued about a million lines of code between the front end and back end, and has never had more than 5 developers working on it at any given time. The backlog of feature requests is nearly as long as the backlog of bugs.
You may notice the little date comment in the code above. That's because until Jim joined the company, they used Visual Source Safe for version control. Visual Source Safe went out of support in 2005, and let's be honest: even when it was in support it barely worked as a source control system. And that's just the Power Builder side- the database side just didn't use source control. The source of truth was the database itself. When going from development to test to prod, you'd manually export object definitions and run the scripts in the target environment. Manually. Yes, even in production. And yes, environments did drift and assumptions made in the scripts would frequently break things.
You may also notice the fields above use a lot of Hungarian notation. Hungarian, in the best case, makes it harder to read and reason about your code. In this case, it's honestly fully obfuscatory. c_ stands for a codetable, f_ for entities. l_ is for a many-to-many linking table. z_ is for temporary tables. So is x_. And t_. Except not all of those "temporary" tables are truly temporary, a lesson Jim learned when trying to clean up some "junk" tables which were not actually junk.
I'll let Jim add some more detail around these prefixes:
an "application" may have a link to a "client", so there is an f_client field; but also it references an "agent" (which is also in the f_client table, surpise!) - this is how you get an f_c_f_client field. I have no clue why the prefix is f_c_ - but I also found c_c_c_channel and fc4_contact columns. The latter was a shorthand for f_c_f_c_f_c_f_contact, I guess.
"f_c_f_c_f_c_f_c" is also the sound I'd make if I saw this in a codebase I was responsible for. It certainly makes me want to change the c_c_c_channel.
With all this context, let's turn it back over to Jim to explain the code above:
And now, with all this background in mind, let's have a look at the logic in this condition. On the deepest level we check that both f_client and f_c_f_client are NOT equal to @f_client_user, and if this is the case, we return 0 which is NOT equal to 1 so it's effectively a negation of the condition. Then we check that records matching this condition do NOT EXIST, and when this is true - also return 0 negating the condition once more.
Honestly, the logic couldn't be clearer, when you put it that way. I jest, I've read that twelve times and I still don't understand what this is for or why it's here. I just want to know who we can prosecute for this disaster. The whole thing is a quadruple negative and frankly, I can't handle that kind of negativity.
.comment { border: none; }Machine Gun Kelly enjoys Paris Fashion Week with daughter, 16, amid rumors he is back with Megan Fox
I'm trustee for my toddler grandson: I'm not taking a penny, but will I lose my benefits? HEATHER ROGERS replies
Rachel Reeves urged to reform 60% tax trap that will catch 2.1MILLION this year, as OBR says it will look at high marginal rates
Exact date Colchester residents will get new wheelie bins 'to clean up streets'
Canada's PM refuses to rule out military involvement in Middle East as US releases dramatic footage of Iran blitz - LIVE UPDATES
Emotional Kelly Osbourne makes surprise Masked Singer cameo for Ozzy-themed show... after firing back at 'cruel' body-shaming trolls
Deadliest Catch star's devastated mom begs producers not to air footage of his fatal fall at sea
Wellness guru charged with manslaughter after man died during a ayahuasca and frog poison ceremony at his Byron Bay retreat
Group takes action against 5,000 new homes plan in Kelvedon
How Chelmsford could look in 2036 after potential major housing, infrastructure and other developments
Google embraces third party app stores and payments to put Epic Games case behind it
Google has spelled out changes it will make to the fees it charges developers who use its app store and payment services, and says they represent the end of its long legal battle with Epic Games.…
Fancy a morning dip? King penguins on the Falkland Islands spotted after their sunrise swim
Clues in 'Majestic-12' UFO files the FBI claimed were fake prove secret alien unit was real, researcher claims
Broadcom says AI companies can’t make their own silicon any time soon
Broadcom will soon deploy multiple gigawatts worth of custom accelerators at Meta, OpenAI, and Anthropic, a feat it says shows AI companies and hyperscalers can’t successfully develop and deploy their own silicon any time soon.…