News for hackers. Stuff that matters.
Re:FreeBSD replaces bubblesort with mergesort on SYSINTs, re... by gpvos on Monday August 21, 2023 @04:56AM (#37206950)
> above code only minimally tested

There you have your problem: any programmer can write a bubble sort while half asleep and inebriated at the same time, but for an insertion sort you actually have to think a little. There's much more chance of errors.

Re:FreeBSD replaces bubblesort with mergesort on SYSINTs, re... by moffkalast on Monday August 21, 2023 @05:41AM (#37207243)
This has gotta be the most bullshit justification for writing bad kernel code that will be reviewed and tested by 200 people before it reaches production. Literally any line of code that's as low level has an incredibly large chance of error.
Re:FreeBSD replaces bubblesort with mergesort on SYSINTs, re... by astrange on Monday August 21, 2023 @06:23AM (#37207512)
Old code in BSD wasn't thoroughly tested except by virtue of being old; there's no QA department and traditionally UNIX code was tested by thinking about it really hard rather than automated testing.

(FreeBSD got a test suite in 10.1, which came out in 2014, not that long ago in UNIX terms.)

Re:FreeBSD replaces bubblesort with mergesort on SYSINTs, re... by oblio on Monday August 21, 2023 @07:47AM (#37208193)
Not just in BSD... GNU wasn't much better.

People would be shocked by how little the core tools we use were tested automatically. Some still aren't.

Re:FreeBSD replaces bubblesort with mergesort on SYSINTs, re... by Quekid5 on Monday August 21, 2023 @05:52PM (#37215845)
Quite.

Thankfully the practice of just randomly shelling out to 'random' programs (like the core tools) has been stemmed somewhat, so perhaps we're mostly safe from RCE via that vector. Downloaded files might still be a vector, tho. Maybe I'm an optimist even though I sound very pessimistic.

Re:FreeBSD replaces bubblesort with mergesort on SYSINTs, re... by Quekid5 on Monday August 21, 2023 @06:46AM (#37207695)
If your testing infrastructure is so anemic that a sorting algorithm (of all things) is hard to subject to e.g. property-based/fuzzing tests then it'd probably be worth it to expand that before doing anything else.

I dunno what FreeBSD's test infrastructure is, but I'm just saying that "it needs testing" is not a good reason not to change to a better sort algorithm in this case.

Re:FreeBSD replaces bubblesort with mergesort on SYSINTs, re... by kragen on Monday August 21, 2023 @06:50AM (#37207725)
if only the people working on bsd in 01993 had had access to your wisdom, think how much more successful they would have been
Re:FreeBSD replaces bubblesort with mergesort on SYSINTs, re... by Quekid5 on Monday August 21, 2023 @06:52AM (#37207752)
This is about changing the sorting algoritm. No snark needed. It should be trivial to add a test for the current algorithm (whenever it was introduced) and to replace it afterwards. Heck, even keep running both for bisimulation testing.
Re:FreeBSD replaces bubblesort with mergesort on SYSINTs, re... by kragen on Monday August 21, 2023 @07:06AM (#37207885)
probably colin was more interested in booting faster than in improving testing infrastructure

if your interests run the other way, that's great, and hopefully you will succeed in improving freebsd's testing infrastructure, but it's hardly a reason for colin not to speed up booting

but i don't think i saw anyone claiming that the change should not be made because it wouldn't be adequately tested?

Re:FreeBSD replaces bubblesort with mergesort on SYSINTs, re... by Quekid5 on Monday August 21, 2023 @05:38PM (#37215692)
I don't think you fully read the post I was replying to. I was just saying that that poster's argument against changing the sorting algorithm was misguided.

Quote:

> will be reviewed and tested by 200 people before it reaches production

I was only saying that this is a bad argument for any simple-ish sorting algorithm.

(Granted, if you're doing super-complicated sorting algos with fallbacks for different sizes, heurestics for detecting semi-sorted input, etc. you might want something more sophisticated than trivial property-based checking.)

Re:FreeBSD replaces bubblesort with mergesort on SYSINTs, re... by kragen on Monday August 21, 2023 @08:41PM (#37217155)
i read that as an argument against having done it that way 30 years ago, not against changing it
Re:FreeBSD replaces bubblesort with mergesort on SYSINTs, re... by Quekid5 on Wednesday August 30, 2023 @05:46PM (#37329592)
No worries!
Re:FreeBSD replaces bubblesort with mergesort on SYSINTs, re... by jcelerier on Monday August 21, 2023 @08:14AM (#37208411)
have you ever been bitten by typing a year in a C/C++ program and getting it inadvertently converted to octal?
Re:FreeBSD replaces bubblesort with mergesort on SYSINTs, re... by kragen on Tuesday August 22, 2023 @04:41PM (#37228220)
heh
Re:FreeBSD replaces bubblesort with mergesort on SYSINTs, re... by kragen on Monday August 21, 2023 @05:04AM (#37206998)
i'm not sure; i made a few mistakes in each of them as i was writing them, but they were both working by the time i first tested them. i do feel like the insertion sort was maybe a little more challenging?

edited to add: someonefromca spotted a bug in the insertion sort; where it says

    if (tmp > a[j-1]) break;
it should say

    if (tmp >= a[j-1]) break;
which is both a performance bug and also breaks the stability property the algorithm otherwise has
Re:FreeBSD replaces bubblesort with mergesort on SYSINTs, re... by abecedarius on Monday August 21, 2023 @12:03PM (#37211423)
fwiw that comparison was where I went "wait, is that right?" in my reading.

Maybe a fair judge of mental difficulty would say "you gotta write at least the loop invariant" (termination being too pedantically obvious) -- though admittedly I leave it out more than I used to.

When I was introduced to sorting as a new programmer, via bubblesort, I thought "why that way?" and came up with selection sort as a method that made more obvious sense. It seems to me like bubblesort's alleged intuitiveness is post hoc from the shortness of the code in terms of all-ascending for-next loops -- the intuitive reason it worked was just that the inner loop did move the next max into place just like selection sort, but with extra swaps along the way.

Re:FreeBSD replaces bubblesort with mergesort on SYSINTs, re... by aristophenes on Tuesday August 22, 2023 @10:05AM (#37222898)
You should edit the code in your original comment, someone is bound to copy paste the code somewhere…
Re:FreeBSD replaces bubblesort with mergesort on SYSINTs, re... by kragen on Tuesday August 22, 2023 @04:40PM (#37228216)
it's only editable for two hours, for better or worse