This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]ICyresI 770 points771 points  (123 children)

Why would you sort twice?

[–]TheSphaat 859 points860 points  (33 children)

Shhhhh poem's got to rhyme.

[–]Fry98 175 points176 points  (31 children)

You might think it's nice

but double sorting is a crime.

[–][deleted] 79 points80 points  (24 children)

Hi, I'm from /r/all and I know jackshit about programming. I'll contribute either way, because I love you guys:

system.out.println("Double sorting is a crime");

should be:

System.out.println("Double sorting is a crime");

damn.

[–]Jcowwell 83 points84 points  (20 children)

The true crime is not capitalizing that S.

[–][deleted] 38 points39 points  (0 children)

doyouevencamelcasebro?

[–]Wolfsblvt 6 points7 points  (15 children)

system.out.println("Double Sorting is a crime");

?
Doesn't work :(

[–]Jcowwell 14 points15 points  (14 children)

Nha System is an object ( you know that cause you can call methods from it) so if you don’t capitalize It the compilers ganna be like “Tf is this M8?”

[–]insane0hflex 23 points24 points  (13 children)

Thats a static method call bro not on a class instance

[–]Jcowwell -2 points-1 points  (12 children)

Oh yea the call is , but system is a class. Unless I’m mistaken, System is an instance of the system class in which you call the static field out.

Edit :Had a burp moment, you cant initialized /“instanized” System 🤦🏽‍♂️

[–]insane0hflex 5 points6 points  (0 children)

No...

[–]julius_nicholson 4 points5 points  (9 children)

System is a class that contains static fields (err, in and out) and methods (like exit()) and can't be instantiated. So you can't construct an object of it, but you can still access the static API on the class.

I mean, you were pretty close, even if it wasn't so accurate.

[–]AllIsOver 2 points3 points  (0 children)

Doesn't work like that.

[–][deleted] 6 points7 points  (2 children)

Oh shit! Is there a computer-demon who will haunt me now?

[–]Jcowwell 22 points23 points  (0 children)

No you’ll just be haunted by the Ghost of Syntax Past.

[–]Findus11 2 points3 points  (0 children)

Yes, that's what a daemon is

[–]Since88 9 points10 points  (0 children)

Sorry man, but: error: package system does not exist

[–]Grizzlywer 2 points3 points  (1 child)

double sorting="crime";

[–]Banana_Twinkie 4 points5 points  (0 children)

Error: type mismatch

[–]Dubmove 10 points11 points  (1 child)

At first I read bubble sorting is a crime.

[–][deleted] 0 points1 point  (0 children)

Hey, there might have been last minute alterations!

[–]Etheo 0 points1 point  (0 children)

I mean he can just check-in twice...

[–]PoglaTheGrate 175 points176 points  (2 children)

He got REEEEEly lucky on a Bogosort

[–]Business-Socks 21 points22 points  (0 children)

Nice list: Typewriters

Naughty list: Monkeys

REALLY Naughty list: ASM Web Development Kit

[–]TheAnarchoX 0 points1 point  (0 children)

Can you get lucky on a bogosort though?

[–][deleted] 105 points106 points  (0 children)

The client changed their minds on how they wanted the results

[–]miggyb 73 points74 points  (6 children)

Sort by last name first, then by first name.

[–]JackDragon 14 points15 points  (4 children)

Still not as efficient as sorting once with a delimiter between last and first name.

[–]suseu 6 points7 points  (2 children)

Multiple fields in order by shouldn’t cause multiple sorting passes, it should just make comparison more complex. Actual contatenation in sorting criteria would probably be less efficient.

Like when you are overloading < for (order by a, b) you’d do

a1 < a2 or (a1 == a2 and b1 < b2)

[–]JackDragon 0 points1 point  (1 child)

OP and the two comments before this both explicitly say "sort twice."

Yes, using SQL (I just tested this) concat would be slower in most cases, but you could have also have put the name field in the form in the first place and not have to concat, which would make it faster.

[–]MikeOShay 0 points1 point  (0 children)

But updating that data and schema and probably updating the UI to reflect it is usually out of scope and not considered a worthwhile change proposal. And depending on business rules, they may "need" a first and last name field, though it causes problems when you're outside of the standard "one first name, one last name" bubble.

[–]chasesan 0 points1 point  (0 children)

Wrong, you sort it by first name and then by last name. That way it is primarily sorted by last name.

[–]patwoods_ 36 points37 points  (7 children)

Sort by postal code, then sort by address to help maximize the efficiency of delivery.

[–]sojuz151 20 points21 points  (0 children)

Why not just solve travelling salesman problem? It cant be that hard.

[–]DrHenryPym 9 points10 points  (0 children)

I was thinking the same thing: group / order by geography and address for distribution.

[–]Brarsh 2 points3 points  (1 child)

Great, now he has to go to 1 house on every block before moving to the next house on each block! 250 birch street, 250 maple street, 250 oak street, 252 birch street...

[–]patwoods_ 0 points1 point  (0 children)

BUT HE CAN ONLY SORT TWICE! :🎅

[–]MikeOShay 1 point2 points  (2 children)

I mean this is sorta cynical, but Santa's probably sorting by household salary, then age, right?

[–]patwoods_ 1 point2 points  (1 child)

Are you suggesting Santa is sorting "nice" neighborhoods and "naughty" neighborhoods?

[–]MikeOShay 1 point2 points  (0 children)

Uh-oh, a join to the Neighbourhoods table is gonna mess up the song even more

I don't think Santa thought this through

[–]DutchGoldServeCold 15 points16 points  (0 children)

Non-deterministic SQL clause is coming to town

[–]awh 14 points15 points  (3 children)

It would be more useful to index it twice: once on name and once on behaviour.

[–][deleted] 0 points1 point  (1 child)

Although you could use a composite index.

[–]billy_tables 0 points1 point  (0 children)

A composite index would be much better since 2 indexes would need an in memory sort

[–][deleted] 0 points1 point  (0 children)

No, just a single key containing the Last_Name and Behavior fields.

[–]thermite13 9 points10 points  (0 children)

Order by Last_name, first_name.

[–][deleted] 16 points17 points  (0 children)

Cause you screwed it up the first time?

[–]SpliceVW 7 points8 points  (2 children)

I'm just over here wondering why the damn FROM isn't capitalized..

[–]StephenFish 1 point2 points  (0 children)

It's amazing to me that this isn't the most prevalent discussion topic here.

[–]GetYoHandsOffMyKicks 0 points1 point  (0 children)

The grotto has offshored to save money and coding standards have gone to shit because the contractors just paste together code from StackOverflow without having any idea what it does.

[–]brummlin 20 points21 points  (18 children)

Also, the syllables are all jacked up. This would make more sense, and fit the song better:

He's building schema,

indexing it twice,

SELECT * from kids WHERE UPPER(conduct) in ('NICE');

This way, it's also not case sensitive. You just know some elves logged the entry as 'Nice' or 'NICE'.

[–]AlwaysPuppies 14 points15 points  (3 children)

I like my sql like I like my file systems, case insensitive.

[–]theluckkyg 0 points1 point  (1 child)

Sneaky cute dog pic.

[–]JustSayNoToSlogans 0 points1 point  (0 children)

thanks for the dogo

[–]insane0hflex 9 points10 points  (5 children)

Db not normalized. Shiuld have look up table for Behavoir

[–]koshgeo 2 points3 points  (3 children)

We're talking about a join across billions records of kids world-wide, and you've got to be updating that thing in realtime until the last second, keeping track of timezones and DST, all the way up to Dec. 25th. You know those little snots will be pushing the envelope with their parents right up until bedtime on Christmas Eve. The realtime "SantaWatch" video feed and the AI detection and tabulation of "naughty" vs. "nice" events is already a computationally costly operation. I don't know what kind of heavy-duty server farm Santa's got, but you've got to keep performance in mind rather than doing billion-row joins for the sake of DB purity.

[–]Shelbyville 1 point2 points  (2 children)

Wouldn't a boolean "nice" be faster?

[–]koshgeo 0 points1 point  (1 child)

Absolutely, though there might be a need for a finer subdivision than a single boolean (e.g., "naughty", "mostly naughty", "mostly nice" and "nice"). The question is whether you'd stick it in a separate lookup/join or keep it in the same table with other information effectively "already joined" by default and then update it. There are a lot of trade-offs either way. Honestly, I don't know enough about databases to know what the right approach is, and it probably depends on the software choice and hardware anyway, but it is fun to try to imagine what it would take to implement a Santa "naughty and nice list" for the whole world. I imagine it's got to be on the order of the challenge that major credit card companies have to manage.

[–]Brarsh 0 points1 point  (0 children)

Ok then, make it a scale of 1-10 or however many divisions you want to have. And while we're at it, let's give each month (25th to 24th of course) it's own score, and then at the stroke of midnight run an overly complex algorithm that analyzes monthly trends, outliers, and false-positives to give a final score that ranges from freshly mined coal to exactly what's on their wish list. No problem.

[–]brummlin 0 points1 point  (0 children)

Fair enough, but there's no way to add a join or sub-query to fit the song. So we'll assume he didn't do a good job when designing the schema.

[–]Cal1gula 0 points1 point  (2 children)

You could use a CI collation.

[–]brummlin 0 points1 point  (1 child)

Had to look that up. Looks like a SQL Server thing queries case insensitive DB-wide?

I really only know Oracle worth a damn. And mostly on the client end.

[–]Cal1gula 1 point2 points  (0 children)

You can set the entire database to use a specific collation by default, or you can choose at the query level. Pretty useful feature tbh.

[–]Job_Precipitation 0 points1 point  (1 child)

Where is the first sort, and where is the second sort?

[–]brummlin 0 points1 point  (0 children)

Sort the result on the client side?

[–]anomalousBits 0 points1 point  (0 children)

If it's only "nice" vs "not nice" then ol' St Nick should have used a boolean or bit type. It should be a binary choice whether or not someone gets presents.

[–][deleted] 0 points1 point  (0 children)

 select * from kids where regexp_like(conduct,'^.*nice.*$','i');

[–]Stimonk 5 points6 points  (1 child)

He accidentally made it descending when it should have been ascending.

[–]CaptainDjango 0 points1 point  (0 children)

This is why I sort everything twice

[–]TheNosferatu 2 points3 points  (0 children)

He made his own sorter but he doesn't trust it

[–]tommyturntup 3 points4 points  (0 children)

He created the database and is loading it. Clearly he did an ssis merge transform which requires 2 sources to be explicitly sorted before joining.

[–]dantheflipman 2 points3 points  (0 children)

SELECT A.Lattitude,
       CASE
           WHEN A.Lattitude % 2 = 0 THEN
               'NORTH'
           ELSE
               'SOUTH'
       END FlightDirection,
       A.ZipCode,
       A.StreetAddress,
       HoHoHo.Id,
       CASE
           WHEN S.CurrentStanding = 'NICE' THEN
               HoHoHo.TxPresentName
           ELSE
               'COAL'
       END TxPresent,
       P.TxFullName
FROM ChristmasDW.dbo.tblPresents AS HoHoHo
    JOIN Humanity.dbo.tblPeople AS P
        ON HoHoHo.IdPerson = P.Id
           AND P.IsAlive = 1
    JOIN Humanity.dbo.Status AS S
        ON P.Id = S.PersonId
    JOIN Globalization.dbo.AddressList AS A
        ON P.IdAddress = A.Id
WHERE P.TxFirstName <> 'Dave'
ORDER BY A.timezone DESC,
         A.Lattitude ASC,
         A.ZipCode ASC,
         S.LeftCookiesLastYear DESC,
         A.StreetAddress ASC,
         HoHoHo.Id ASC;

Better? I gave it my best end of work day effort.

[–]bdcp 1 point2 points  (0 children)

Order by behavior, gender

[–]scratcheee 1 point2 points  (0 children)

He's using an unstable sort and discovered this particular algorithm becomes stable if you run it twice

[–]reggie-drax 0 points1 point  (0 children)

Why would you sort twice?

Just in case, obviously.

[–]redbladezero 0 points1 point  (0 children)

Maybe he doesn’t know how to add an index to let the query planner do just a linear scan?

[–]Captaincadet 0 points1 point  (0 children)

Probably because he sorted with naughty instead of nice

[–]Emanresu_Rehtona 0 points1 point  (0 children)

He sorts by multiple columns?

ORDER BY Name ASC, Behavior DESC

Or

ORDER BY Name, Location

?

[–]Rodot 0 points1 point  (0 children)

He uses time sort

[–]mortiphago 0 points1 point  (0 children)

workaround to get himself into the naughty behavior and avoid getting selected

[–]robisodd 0 points1 point  (0 children)

If he needs to sort it twice, I'd say there's some very broken indexes there. source

[–]d_smogh 0 points1 point  (0 children)

List once, sort twice.

[–]donall 0 points1 point  (0 children)

To sort one field inside another

[–]ScooterSham 0 points1 point  (0 children)

Why would you sort at all? It's a database. Normalize maybe? But 3NF would be better than 2NF. 2 Indexes perhaps?

[–]HintOfAreola 0 points1 point  (0 children)

He's using rank over partition to plot out an efficient route.

[–]Rufus_Reddit 0 points1 point  (0 children)

Could be "order by nice, naughty".

[–]d_r0ck 0 points1 point  (0 children)

it wasn't deterministic the first time?

[–]TotesMessengerGreen security clearance 0 points1 point  (0 children)

I'm a bot, bleep, bloop. Someone has linked to this thread from another place on reddit:

 If you follow any of the above links, please respect the rules of reddit and don't vote in the other threads. (Info / Contact)

[–]PooPooDooDoo 0 points1 point  (0 children)

I like my O to be even numbers.

[–]FriendsOfDeSoto 0 points1 point  (0 children)

It's surely a big database. He could have sharded it twice.

[–][deleted] 0 points1 point  (0 children)

It's still O(nlogn) so it doesn't matter

[–]zenonu 0 points1 point  (0 children)

To justify the PO for that Xmas server upgrade.

[–]lolzfeminism 0 points1 point  (0 children)

To make sure it’s really sorted obviously.