Sort This Out

montrealish1 pts0 comments

Sort This Out - The Daily WTF

Feature Articles

Most Recent Articles

Let's Be Facebook!

Whales Ahoy!

Three Digit Acronyms

The Pride Goeth

Empty Pockets

A Whale of a Problem

Turning Thirty

A Hole in Your Plan

CodeSOD

Most Recent Articles

Weekly Calculated

Required Fields

Caught a Mistake

Dating in Hungarian

Delicious Fudge

Driven Development

Check and Check

Build Up

Error'd

Most Recent Articles

No Rush

Bridge for Sale

Super SEO Strategies

April is Special, and so are you

Balmenach Bad Gateway Single Malt

Null Null Null

Parametric Projection

April Showers

Forums

Other Articles

Random Article

Other Series

Alex's Soapbox

Announcements

Best of…

Best of Email

Best of the Sidebar

Bring Your Own Code

Coded Smorgasbord

Mandatory Fun Day

Off Topic

Representative Line

News Roundup

Editor's Soapbox

Software on the Rocks

Souvenir Potpourri

Sponsor Post

Tales from the Interview

The Daily WTF: Live

Virtudyne

feature articles

codesod

error'd

forums

other articles

random article

Sort This Out

by Remy Porter<br>in Representative Line<br>on 2026-06-18<br>Edit

Remy Porter<br>Computers were a mistake, so I accidentally became a farmer? Editor-in-Chief for TDWTF.

Today's anonymous submitter has spent a long time toiling through many, many tickets. Their effort has been an attempt to "save" their employer from the disaster left behind by by a highly-paid consultant. As one does, our submitter started with the highest priority tickets with the highest severity. Eventually, they whittled down that list, and had some bandwidth to start looking at the pieces of the code which clearly weren't exploding right now (because there were no tickets), but were likely to explode at some point in the future (creating a storm of tickets).

Scanning through the JavaScript, our submitter found a sort function. That was automatically concerning- why was that particular wheel being reinvented?

The first line of the sort function was this:

obj[x._id.account_id] = x.count_total

In this case, x._id is meant to be the unique identifier from their Mongo DB. That, uh, should be not precisely a UUID (Mongo does its own weird version), but it definitely shouldn't have an account_id field on it. They are storing an arbitrary object as their unique identifier in the database. Which, I'm no Mongo expert, but I don't need to be Flash Gordon to know that's a bad idea.

But setting aside the choice of using random objects as unique identifiers, there's also the other question: how is this furthering the goal of sorting? Why on Earth am I building an object in the form: {"id0": 5, "id1": 7, "id2": 11}? Or am I even doing that? This is the first line of the function, so we're not even doing a loop, it's just {"id0": 5}.

This isn't just an unexploded bomb, it's a mystery: the primary mystery being why hasn't this exploded already? The second mystery is: what's going to happen when your luck runs out?

[Advertisement]<br>ProGet’s got you covered with security and access controls on your NuGet feeds. Learn more.

View all 1 comments "

" Weekly Calculated

Contact<br>Privacy Policy<br>RSS

Copyright © 2026 Inedo Publishing - v2024.9

Monitored by Panopta<br>&bull; Deployed with BuildMaster

articles sort line tickets recent null

Related Articles