Computer
Representative Line: Not What They Meant By Watching "AndOr"
Today's awfulness comes from Tim H, and while it's technically more than one line, it's so representative of the code, and so short that I'm going to call this a representative line. Before we get to the code, we need to talk a little history.
Tim's project is roughly three decades old. It's a C++ tool used for a variety of research projects, and this means that 90% of the people who have worked on it are PhD candidates in computer science programs. We all know the rule of CompSci PhDs and programming: they're terrible at it. It's like the old joke about the farmer who, when unable to find an engineer to build him a cow conveyer, asked a physicist. After months of work, the physicist introduced the result: "First, we assume a perfectly spherical cow in a vacuum…"
Now, this particularly function has been anonymized, but it's easy to understand what the intent was:
bool isFooOrBar() { return isFoo() && isBar(); }The obvious problem here is the mismatch between the function name and the actual function behavior- it promises an or operation, but does an and, which the astute reader may note are different things.
I think this offers another problem, though. Even if the function name were correct, given the brevity of the body, I'd argue that it actually makes the code less clear. Maybe it's just me, but isFoo() && isBar() is more clear in its intent than isFooAndBar(). There's a cognitive overhead to adding more symbols that would make me reluctant to add such a function.
There may be an argument about code-reuse, but it's worth noting- this function is only ever called in one place.
This particular function is not itself, all that new. Tim writes:
This was committed as new code in 2010 (i.e., not a refactor). I'm not sure if the author changed their mind in the middle of writing the function or just forgot which buttons on the keyboard to press.
More likely, Tim, is that they initially wrote it as an "or" operation and then discovered that they were wrong and it needed to be an "and". Despite the fact that the function was only called in one place, they opted to change the body without changing the name, because they didn't want to "track down all the places it's used". Besides, isn't the point of a function to encapsulate the behavior?
[Advertisement] Utilize BuildMaster to release your software with confidence, at the pace your business demands. Download today!Japanese Media Groups Sue AI Search Engine Perplexity Over Alleged Copyright Infringement
Read more of this story at Slashdot.
Study Shows Which Vehicles Pollute the Least In Every US County
Read more of this story at Slashdot.
Farmers Insurance Data Breach Impacts 1.1 Million People After Salesforce Attack
Read more of this story at Slashdot.
Linux Turns 34
Read more of this story at Slashdot.
Biotechs Turn to Digital Coins, Crypto to Boost Stock Prices
Read more of this story at Slashdot.
AMD Blames Motherboard Makers For Burnt-Out CPUs
Read more of this story at Slashdot.
Apple Accuses Former Apple Watch Staffer of Conspiring to Steal Trade Secrets for Oppo
Read more of this story at Slashdot.
Nvidia's New 'Robot Brain' Goes On Sale
Read more of this story at Slashdot.
Perplexity Launches Subscription Program That Includes Revenue Sharing With Publishers
Read more of this story at Slashdot.
FTC Warns Tech Giants Not To Bow To Foreign Pressure on Encryption
Read more of this story at Slashdot.
Intel Warns US Equity Stake Could Trigger 'Adverse Reactions'
Read more of this story at Slashdot.
In a Hotter World, Some People Age Faster, Researchers Find
Read more of this story at Slashdot.
Google To Require Identity Verification for All Android App Developers by 2027
Read more of this story at Slashdot.
Perplexity's AI Browser Comet Vulnerable To Prompt Injection Attacks That Hijack User Accounts
Read more of this story at Slashdot.
Stock Exchanges Urge Regulators To Crack Down on 'Tokenised Stocks'
Read more of this story at Slashdot.
Musk's xAI Sues Apple and OpenAI Over Alleged Antitrust Violations
Read more of this story at Slashdot.
Chinese Solar Makers' Losses Deepen as Industry Vows To End Price War
Read more of this story at Slashdot.
DHL Deploys AI To Fill Retirement Gap as Third of German Workers Near Exit
Read more of this story at Slashdot.
New Book Argues Hybrid Schedules 'Don't Work', Return-to-Office Brings Motivation and Learning
Read more of this story at Slashdot.