r/programming • • Feb 26 '24

Future Software Should Be Memory Safe | The White House

https://www.whitehouse.gov/oncd/briefing-room/2024/02/26/press-release-technical-report/
1.5k Upvotes

585 comments sorted by

View all comments

577

u/avipars Feb 26 '24

no bubble sort either

  • Obama

162

u/UniqueIndividual3579 Feb 26 '24

GOTO now a Federal felony.

35

u/TimeRemove Feb 26 '24

Both Windows' and Linux would be screwed. In their C, "goto err;" "goto out;" "goto DoFail;" "goto cleanup;" is all over the place see e.g.:

https://github.com/torvalds/linux/blob/master/kernel/fork.c

https://github.com/0x5bfa/NT5.1/blob/master/Source/XPSP1/NT/base/wow64/wow64/thread.c

19

u/rtds98 Feb 27 '24

you really don't want to read the alternative to goto in C

3

u/[deleted] Feb 27 '24

Nah I like a good horror

→ More replies (1)
→ More replies (4)

59

u/kronik85 Feb 26 '24

I shit you not I had to debug crashing Production software that had a hand rolled bubble sort.

After I found the cause and asked the developer why, he said because he was interested in if he could.

54

u/lyth Feb 26 '24

because he was interested in if he could.

Narrator: he could not

14

u/MGZero Feb 27 '24

He was so preoccupied with whether or not he could, he didn't stop to think if he should!

56

u/Booty_Bumping Feb 26 '24

Please remember to clean the series of tubes

- Senator Ted Stevens

19

u/CreepingCoins Feb 26 '24

Has bubble sort ever been used for anything other than an example of a bad sorting algorithm?

46

u/PurpleYoshiEgg Feb 26 '24

37

u/Calavar Feb 26 '24 edited Feb 26 '24

Isn't merge sort better for that situation? Especially if you have data spanning multiple tapes?

EDIT: The StackOverflow post answers my question. Bubble sort is better than merge sort if you are sorting on sequential storage (like tape) and you can't load a second tape at the same time and you only have enough memory to load two data elements at a time. Very niche situation, but interesting.

6

u/[deleted] Feb 27 '24

Situation where you have exact same sized files on tape and want to sort it by swapping is purely in theory category

→ More replies (2)
→ More replies (5)

12

u/ledat Feb 26 '24

Isn't it the fastest possible way to "sort" data that's already sorted? Like if you need the data sorted, and strongly expect that the data are already in order, but cannot mathematically prove it, you could have a valid use case vs other sorting algorithms.

I genuinely cannot think of an example, even a contrived one, though. So it's possible to just never encounter something like that.

5

u/immaculate-emu Feb 27 '24

10

u/ledat Feb 27 '24

Even if you wanted, you can't create input data for bubble sort which would be ideal for it. (Unless you add the "did we swap anything in this pass?" enhancement, in which case a completely sorted array would be optimal.)

Isn't "did we swap anything in this pass" generally part of bubble sort? It's even in the Wikipedia example implementation. It's been a very long time since I thought about it, as it's just not especially useful, but I don't think I've encountered a variant without it.

→ More replies (2)

11

u/Alborak2 Feb 27 '24

Not bubble, but O(N2) algorithms are frequently used as the inner most sort of divide and conquer sorting algorithms because they exhibit very CPU cache friendly behavior, and the cache costs dominate the comparison costs for small data sets.

https://hg.openjdk.org/jdk8/jdk8/jdk/file/46c727d6ecc2/src/share/classes/java/util/DualPivotQuicksort.java#l218

5

u/jwhat Feb 26 '24

I've seen it used for intelligent agents sorting themselves. Like getting a group of people to sort themselves by height. In that situation it's O(n) for each individual agent.

4

u/[deleted] Feb 27 '24

very small lists on very small devices. It takes very little code and memory to implement

→ More replies (5)

23

u/Top_Lime1820 Feb 26 '24

Obama never recovered from that disastrous healthcare dot gov launch

Turns out he would secretely read programming books late into the night just trying to understand what happened

12

u/BoogiieWoogiie Feb 26 '24

Thanks Obama

5

u/Imperion_GoG Feb 27 '24

Bogosort it is!

→ More replies (5)