Computer
CodeSOD: Switching the Order
Let's say you had 6 different labels to display. There are many, many ways to solve this problem. Most of them are fine. Some of them are the dreaded loop-switch anti-pattern.
Julien unfortunately inherited one of those.
for($i=0;$i<=5;$i++) { switch($i) { case 1 : print('<p>Activé</p>'); break; case 0 : print('<p>Désactivé</p>'); break; case 2 : print('<p>En cours d\'inscription</p>'); break; case 3 : print('<p>En cours de désinscription</p>'); break; case 4 : print('<p>Désinscrit</p>'); break; case 5 : default : print('<p>Marqué invalide</p>'); break; } }Indentation in the original.
What's beautiful in this, is that we can see that the order of the fields changed. Originally, it was meant to be "Activé", then "Désactivé". But for whatever reason, that wasn't what needed to be on the page, so they flipped the order… by changing the values in the case statement.
It's that bit there that really made this code special, to me. The out-of-order case is the annoying choice that makes bad code truly awful.
[Advertisement] Utilize BuildMaster to release your software with confidence, at the pace your business demands. Download today!OpenAI Fundraising Set To Vault Startup's Valuation To $150 Billion
Read more of this story at Slashdot.
'An AI Bot Named James Has My Old Local News Job'
Read more of this story at Slashdot.
Americans Used Record 100 Trillion Megabytes of Wireless Data In 2023
Read more of this story at Slashdot.
Mistral Releases Pixtral 12B, Its First-Ever Multimodal AI Model
Read more of this story at Slashdot.
Bluesky Lets You Post Videos Now
Read more of this story at Slashdot.
Mark Zuckerberg Says He's Done Apologizing
Read more of this story at Slashdot.
Android Apps Can Now Block Sideloading, Force Downloads Through Google Play
Read more of this story at Slashdot.
Human Drivers Keep Rear-Ending Waymos
Read more of this story at Slashdot.
Google Partners With Internet Archive To Link To Archives In Search
Read more of this story at Slashdot.
'Sony's PS5 Pro Is a Pricey Test of Next-Gen Consoles'
Read more of this story at Slashdot.
Facebook Admits To Scraping Every Australian Adult User's Public Photos and Posts To Train AI, With No Opt-out Option
Read more of this story at Slashdot.
Sergey Brin Says He's Working on AI at Google 'Pretty Much Every Day'
Read more of this story at Slashdot.
Security Researcher Exposes Critical WHOIS Vulnerability
Read more of this story at Slashdot.
Nvidia CEO Reveals GPU and Software Moat in AI Chips
Read more of this story at Slashdot.
Chrome is Making It Easier To Keep Track of Browser Tabs
Read more of this story at Slashdot.
The Shadow Dollar That's Fueling the Financial Underworld
Read more of this story at Slashdot.
TV News Overtaken By Digital Rivals For First Time in UK
Read more of this story at Slashdot.
Ford Seeks Patent For Tech That Listens To Driver Conversations To Serve Ads
Read more of this story at Slashdot.
Samsung Electronics Plans Global Job Cuts of Up To 30% in Some Divisions
Read more of this story at Slashdot.