Computer
Asteroid 2024 YR4 Has a 4% Chance of Hitting the Moon
Read more of this story at Slashdot.
Ancient Martian Beach Discovered, Providing New Clues To Planet's Habitability
Read more of this story at Slashdot.
CodeSOD: A Field Terned Visible
Today's anonymous submitter sends us some C# code. This particular block of code controls whether two different columns are visible on the screen. If the field Dist_Por equals one set of constants, we display one column, if it equals a different constant, we display the other. Seems simple enough.
My question to you is this: how many nested ternaries do you need to solve this problem?
ColHectarias.Visible = Dist_Por == TIPO_DIST_COSTO.Directo ? false : Dist_Por == TIPO_DIST_COSTO.Plantilla ? false : Dist_Por == TIPO_DIST_COSTO.Hectáreas ? true : Dist_Por == TIPO_DIST_COSTO.CCosIndirecto ? true : false; ColPorcentaje.Visible = Dist_Por == TIPO_DIST_COSTO.Directo ? false : Dist_Por == TIPO_DIST_COSTO.Plantilla ? true : Dist_Por == TIPO_DIST_COSTO.Hectáreas ? false : Dist_Por == TIPO_DIST_COSTO.CCosIndirecto ? false : false;If you read through just the first ternary, you'll notice the pattern: if the field equals Directo, this is false. If the field equals Plantilla this is false. If the field equals Hectáreas, it's true. If the field equals CCosIndirecto, also true. And when you write it out that way, it's just a simple or expression: ColHectarias.Visible = Dist_Por == TIPO_DIST_COSTO.Hectáreas || Dist_Por == TIPO_DIST_COSTO.CCosIndirecto;
The ColPorcentaje column is even worse: it's only visible when Dist_Por equals TIPO_DIST_COSTO.Plantilla.
Our anonymous submitter adds:
Simple, right? If only, starting with the fact they even got the ColHectarias column name wrong: it should have been ColHectareas. Do not make the mistake of assuming those are the only lines with issues or this is the first time it happens. I known the person who wrote that and if I had any choice in the matter I would never, ever, look a their code, because my sanity drops every time I do.
[Advertisement] Keep all your packages and Docker containers in one place, scan for vulnerabilities, and control who can access different feeds. ProGet installs in minutes and has a powerful free version with a lot of great features that you can upgrade when ready.Learn more.Amazon Inadvertently Announces Cloud Unit Layoffs In Email To Employees
Read more of this story at Slashdot.
US Government Lost More Than 10,000 STEM PhDs Last Year
Read more of this story at Slashdot.
Apple Updates iOS 12 For the First Time Since 2023
Read more of this story at Slashdot.
Scientists Launch AI DinoTracker App That Identifies Dinosaur Footprints
Read more of this story at Slashdot.
SoundCloud Data Breach Impacts 29.8 Million Accounts
Read more of this story at Slashdot.
Supreme Court To Decide How 1988 Videotape Privacy Law Applies To Online Video
Read more of this story at Slashdot.
OpenAI Releases Prism, a Claude Code-Like App For Scientific Research
Read more of this story at Slashdot.
Amazon To Pay $309 Million To US Shoppers In Settlement Over Returns
Read more of this story at Slashdot.
Internal Messages May Doom Meta At Social Media Addiction Trial
Read more of this story at Slashdot.
Citigroup Mandates AI Training For 175,000 Employees To Help Them 'Reinvent Themselves'
Read more of this story at Slashdot.
Mozilla is Building an AI 'Rebel Alliance' To Take on Industry Heavweights OpenAI, Anthropic
Read more of this story at Slashdot.
Instagram, Facebook and WhatsApp To Test Premium Subscriptions
Read more of this story at Slashdot.
Android Phones Are Getting More Anti-Theft Features
Read more of this story at Slashdot.
France To Ditch US Platforms Microsoft Teams, Zoom For 'Sovereign Platform' Amid Security Concerns
Read more of this story at Slashdot.
Microsoft Was Routing Example-Domain Traffic To a Japanese Cable Company for Five Years
Read more of this story at Slashdot.
Doomsday Clock Ticks To 85 Seconds Before Midnight, Its Closest Ever
Read more of this story at Slashdot.
Amazon To Shut Down All Amazon Go and Amazon Fresh Stores
Read more of this story at Slashdot.
