The Webcomic Hunger Games are in full swing:
- Melody: What type of sorting algorithm did you implement to sort the list of object names? Merge sort? Heap sort? … Bucket sort?
- Richard: Neither. I simply called Java’s “sort” function.
- Melody: You filthy casual.
|
Java? Bad choice to work in a shop that uses Java is she’s into low level programming like writing sort functions. Even most C++ shops just use the STL for containers and sorting. In any event if you are writing sort functions, you are either doing it wrong (99% likely) or you really, really need the performance (1% likely) and only a customized sort function will do the trick. Time spent writing framework code is time lost from writing $$$ code.
There are 10* kinds of programmers.
Those that understand the peformance rant and those that do not:
http://ericlippert.com/2012/12/17/performance-rant/
*binary notation
Richards answer really is the most Java thing to say to that question. If you care about performance, why are you using Java in the first place? If you just want to get it sorted with minimal effort on your part, the function called “sort” is probably what you should look at first.
Also, Quicksort. It’s easy to remember and implement and not consistently outperformed by anything (only with additional constraints on what attribute you can sort by). Or just use a pre-sorted data structure like a tree and never bother about sorting again.
stooge sort is all you need
I already like her.
However, he did the right thing. Using the default sorting function is usually the best decision, since it probably has years of revisions behind to make it perfectly optimized for most common applications and reimplementing it would slow the development process while resulting in a (almost always) worse implementation. Implementing your own sorting algorithm makes sense only for very specific applications that allow for special optimization.
And anyway, the type of data structure you decide to use is usually much more important than the sorting algorithm, it’s better to sort one time with a bubble sort than to sort n times with a merge sort.
@ Ano:
I was expecting this. I’m quite disappointed.
Yep, I’m on Richard’s side as well. If Ms. Crawford really thinks using the standard library of your language of choice is a bad thing, I don’t want to have anything to do with anything she ever headed, nor do I want to have her on any team I’m on.
Given how far she is in her career, if she still believes this, she’ll keep believing it no matter what anyone says. I want productive team mates who can be reasoned with and whose code is readable at least at the speed at which it was written (preferably faster). I don’t want autistic better-than-you micro-optimizers producing unreadable code which might, if it is very lucky, do a small task a bit quicker than standard. But just as likely is just plain broken/buggy.
@ Agarax:
https://xkcd.com/378/
Presumably if they’re using Java, this is a quotidian task anyway, so performance is less of an issue than getting the job done… I’m going to say she’s just being petty at being the fresh fish to someone who doesn’t have as strong a background as she does.
You know when someone is talking about something that you know nothing about and don’t understand any of it, but you nod your head in order to pretend that you do?
I’m not going to pretend here. I have no idea what anyone is ****ing talking about. XD
@ Ajed32:
This is why programmers are not paid by the hour.
It is rather Funny when you realize that, after 40 Years of Tweaking and research into the Best & Fastest ways to Sort, the major vendors of SORT Software stopped competing in claiming Faster or “more Efficient” sorts and, instead, began competing in all the Other Things they had programmed into their Sort Utilities in order to allow programmers to manipulate, reformat, report and otherwise perform multiple functions at the Same Time.
Invoke the Sort Utility and, while it’s Sorting, it can also perform 6 other functions saving you the trouble of writing those Other Programs at all.
I’ve seen as many as 10 separate programs replaced by a single execution of the SORT Utility with the appropriate set of Control statements.
The Competition for “Best Sort Utility” got downright Silly for a while.
And, at the same time, some of the Functions that got built into “Sort” were downright awesome.
Sadly, I do know what they’re talking about.
I also know that I’d take any shortcut I can, because I’ve written out nearly identical code out several times for the simple reason of not knowing how to code it better.
Don’t reinvent things when someone else has already done it better than you could.
Unless it’s fun.
@ Agarax:
Assembler? Binary? Are you into SM?
Okay, can anyone explain the comics to us commoners here who doesn’t understand programming but still want to enjoy the comic ? Or does the comic only cater to niche audience now ?
PS2kid wrote:
TL;DR: she is nerd-raging for no valid reason.
She is expecting him to have made a custom sorting program, but he used a ready-made one. It’s a bit like her asking “Which method did you use to calculate this?” and him replying “I used a calculator”.
It is very, very rare that customized sorting will be worth the extra length of the program, effort to write it, and future effort to maintain it.
Something especially irritating our easily irritated lady is that Java’s sort function is not specified to have a certain implementation. So the program’s speed might vary not only depending on input, but also on the software it runs on. AFAIK, it is likely to be a Merge Sort, but it can be something else, depending on the implementation — i.e., whether you’re on Android’s Dalvik runtime or Oracle’s Java or another one.
The language choice might also be intentional. Java is rather basic and common as programming languages go; many people had to learn it in their education anyway. It’s neither as suited for making fast programs as low-level languages (e.g. C and its dialects, or languages for graphics processing units), nor as expressive as high-level languages (e.g. the # “sharp” languages, Haskell, or various modern stuff).
But again, it’s very VERY unlikely that any of this is relevant. She’s just desperate for a reason to belittle him, or something.
@ Steven:
I was exaggerating slightly. I used to program my VIC-20 and C64 using Supermon. It supported named instructions but not named values.
The binary code in my earlier comment was:
LDA#$68
JSR$FFD2
LDA#$49
JSR$FFD2
BRK
It prints “Hi” (using PET ASCII).
Will they ever wear the same shirt?
Daaaamn, red hair and freckles…Dude, if you and her don’t hook up, I will be seriously dissapointed….
Should be using Radix sort 😉
@ Vandroiy:
I don’t think belittling him is her primary motivation. What we witness here is the ages-old holy war between the C philosophy (performance is god, processor cycles are money, optimize everything) and the Java philosophy (computers are cheap, programmers aren’t).
And while I concede that the Java way is the better business decision 95% of the time (although I’d rather go the whole hog with a very expressive functional language like Erlang, F# or Haskell), hand-optimizing code close to the metal is just so much fun…
I’m with Richard here: There are only two reasons not to use your platform’s default sort functions in production code:
1) Your code is performance-critical and you have proven, with profilers helping, that the sorting algorithm and implementation you’re using will better fit the purpose
2) The default sort function isn’t a stable sort and you need one.
In all other cases, you should keep custom sorting implementations to experimental projects, personal fun, and teaching/learning algorithms.
I don’t know anything about programming, but I am getting the humor and enjoying. So, good job to the writer.
I am torn however. Do I want them to be rival buddies or a rivalmance?
Fred wrote:
There is a Third reason: You are in a programming space that does not have a “Graceful” way to invoke the default sort function. I’ve been in that situation.
Luckily, it was an application that First required the Data to be Input, then later would display it back.
I simply built the application to Insert the data into an In Core Table in the correct sequence when it was first entered. Then, when it was Saved to a File for later display, it was already sorted by virtue of having been inserted into the correct place while it was being input.
This was in a system where the Data was being input by Human beings in Real Human Time, so “Efficiency” wasn’t really an issue.
Invoking the Sort Function was Possible but only at the expense of serious system overhead to sort a few dozen items. A dozen or so lines of code was much easier and a few Comments explained the reason for the next programmer who might have wondered “Why?”.
While I certainly support the ship, I’m thinking that (sadly) it probably won’t be, since it’s a little bit TOO predictable.
I’m hoping that at the very least, we have a new cast member that can be on fairly friendly terms with Richard, though.
Wow, I just finished reading through all of the strips and I am IMPESSED! Keep up the goodwork.
I have the feeling this is going to turn out as a sort of geeky Italian marriage, i.e. fight like Hell so you can make up passionately . . . except she looks Irish. No matter, it’s going to be fun to watch.
Arguing about these kinds of things can be either: a) harmless b) indicative of a general antipathy towards the person.
Nobody really gets angry enough to call someone a “casual” except in jest. We love calling people who don’t believe in how we do things “heretics”. To their faces. But it doesn’t usually mean anything. Mostly because usually people aren’t surrounded by their polar opposites; so it’s more like a darker shade of gray kind of thing.
So… I don’t think we should take her words as harsh as they sound.
Just FOR THE LOVE OF GOD DO NOT google Linus Torvalds for too long, he’s… uh… an exception.
Besides, everyone knows quantum bogosort is the best and coolest sorting algorithm.
Which Java’s sort function?
Which Java’s which sort function?
The main issue with using Java’s sort is boxing and the lack of inlining. Unlike C++’s sort, which is essentially a template, which gets inlined at compile time into practically being the same code as having written the sort yourself, in Java the code maintains a runtime profile that is roughly equivalent to its original program structure.
It is even worse if you’re using a more efficient data structure, like a flat array, and are forced to box it into a collection prior to sorting. (To be clear, an array is more efficient under the assumption that it doesn’t grow or shrink)
In fact, boxing and non-reified generics has been a huge performance impact on Java for a long time, causing the creation of many third-party type-specific collections. For instance, it is considered bad practice to use HashSet. Instead, there’s a third-party implementation of a hash-set that actually uses actual non-boxed integers.
Of course, this all depends on whether the use or sorting of said collection is even done in a frequently called code piece. If this was, for instance, done during document save (an infrequent action that is already slowed down by disk access), it would be pointless to bother with performance there.
If anything, the main thing I’d point out is the use of Java at all. Having nothing resembling a preprocessor, or metaprogramming, and not even reified generics, I’ve found that Java usually results in the most boiler plate or copy-pasted code compared to any of its main competitors. It’s just so cludgy to get anything serious done in a language that doesn’t allow you even the simplest of shortcuts.
@ PS2kid:
I’ll paraphrase the comic for you.
She: “What type of tomatoes did you buy to make this spaghetti sauce? Roma? Alicente? … Better Boy?”
He: “Neither. I bought a jar of Ragu”.
She: “You filthy casual.”
Are they eating venison? If so…
Awwww, trouble:
https://ca.news.yahoo.com/video/toronto-unveils-raccoon-proof-green-174243360.html
I bet like most of the other people, I and 90% of the world don’t understand what the heck is going on around here.
@ SparkSovereign:
VI? Horrors!
Sir_England wrote:
We are all very Carefully dancing Around the Religious Argument over which is better:
To SKUB or Not To SKUB.
To Use the Function or to Prove that you can Write a Better Function.
To Pontificate or Not to Pontificate …
GnarlyDoug wrote:
I suspected that might be the case. Though I have to admit that ,some. of the Ragu flavors aren’t shabby none.GnarlyDoug wrote:
I had a feeling it was something like that. But it is to be admitted that some of the Ragu flavors aren’t shabby none.
Wow… Sandras new Mom has a nice name… “Melody”… I like it.
That moment when you know what they are talking about…. glorious…
Y’know, people be shipping these two…but until she shows more colors she seems kinda rude so far if you ask me!
Anyone mind explaining to me what skub is? very confused by the shirt
theting wrote:
From the Urban Dictionary:
Skub (n. v. adj. adv. pn.) – A political notion, idea, person, object, building, desire, sin, mythical creature, medication, lotion, governmental upheaval and/or reformation, action, description, or any combination or invention therein created and manipulated to inspire intense feelings towards no particular incarnation and, by proximity, others with opposing feelings.
Anti-Skub: “Skub is made from the tears of newborn puppies and kittens!”
Pro-Skub: “Skub increases life expectancy and makes you more attractive to women!”
Anti-Skub: “Skub is proven to cause erectile dysfunction in 80% of cases!”
“Skub is just something bland and insignificant. Perhaps one of those novelty goops that were popular in the 90’s, or a wax to make your turtle’s shell smell like pine.”
-Nicholas Gurewitch, creator of Skub
Origin:
Skub is a fictional substance based on a Perry Bible Fellowship comic strip portraying two individuals at odds with each other due to their opposing stances on the aforementioned material.
I bet the female nerd is married to Jesus like person that works for the FBI and they both have a daughter who they are severly disappointed in that is depressed goth punk.
… ya know… the author seems to making her out to be his opposite… so I bet her husband and kid is also opposite to his family.
@ 1OldBear:
Nice doublepost :^)
If your language of choice has a sort function, and it isn’t complete shit, and you don’t need perfect efficiency, then use that sort function. (Not that Java is a language really worth using.)
Zissle wrote:
For any sane language (like C++), this generalizes pretty well. If it is already part of the STL, think really hard if you can gain anything before rolling your own. The standard libraries are usually written by the same team that wrote your compiler (or they have close connections). If you believe you can out-optimize compiler guys, you either know something important about your program they don’t, suffer from megalomania, or are already part of the standards committee and about to submit the next update.
Meanwhile I’m just sitting here, programming in Basic 🙁
Sigh
@ Ajed32:
yes and no Since the algorithm is the same for pretty much any way you sort it, you only actually need to write the code out once- then either copy/paste it, or, if possible, create a new class library ( or whatever the java equivalent is, if Java has it) with the sorting algorithms in it, and call the algorithms from that.
there’s also the fact that actually coding in the algorithm means that the code won’t be broken if ever an update to Java changes the algorithm used by java’s Sort function.
Having said that, it depends on how important the sort in question IS. If optimising the sort isn’t important, then by all means call Java’s sort function. If, however, scalability is a factor- or the program is going to need to sort a lot of data- it is worth coding the algorithm in yourself.