AAYFN
by in CodeSOD on 2026-07-14Jason M sends us some Ruby code.
def bv(prop, tv="Yes", fv="No", nv="Not Specified")
v = self.send(prop)
if v === true
tv
elsif v === false
fv
else
nv
end
end
Code Snippet Of the Day (CodeSOD) features interesting and usually incorrect code snippets taken from actual production code in a commercial and/or open source software projects.
Jason M sends us some Ruby code.
def bv(prop, tv="Yes", fv="No", nv="Not Specified")
v = self.send(prop)
if v === true
tv
elsif v === false
fv
else
nv
end
end
TJ inherited a NestJS project. The original developers left the team many years ago, but they've left their mark in the codebase.
// ProjectsModule.ts
@Module({
controllers: […],
providers: […],
exports: […],
})
export class ProjectsModule {}
"Dragoncoder" supports a web application that has a "wait time" for access. I hate that that's a thing, but I recognize that there are real-world constraints where this might make sense. Still, I hate it. But that's not the WTF.
var minutes = parseInt( 12 , 10);
var time = document.getElementById('waitTime');
if ( minutes < 2) {
time.innerText = "Your estimated wait time is 12 minute."
} else if (minutes < 60) {
time.innerText = "Your estimated wait time is 12 minutes."
} else if (minutes === 60) {
time.innerText = "Your estimated wait time is 0 hour."
} else if (minutes < 120 && (minutes % 60 === 1)) {
time.innerText = "Your estimated wait time is 0 hour and 12 minute."
} else if (minutes < 120) {
time.innerText = "Your estimated wait time is 0 hour and 12 minutes."
} else if (minutes > (60 * 4)) {
time.innerText = "Your estimated wait time is more than 4 hours."
} else if (minutes % 60 === 0) {
time.innerText = "Your estimated wait time is 0 hours."
} else {
time.innerText = "Your estimated wait time is 0 hours and 12 minutes."
}
While we talk about bad video game code periodically, we generally avoid it because it's so specialized and while something like fast inverse square root is bad code from a maintainability perspective, it's great code for abusing floating points to make math fast.
Işıtan Yıldız sends us a snippet from a game's config file. I won't pick on the specific game, but this isn't some random build of TuxCart, but a released game sold on multiple platforms. It's from a small team, but it's an actual professional product running on many devices. What's notable about this is the game has multiplayer elements, which means networking code, which means…