this post was submitted on 08 Nov 2024
420 points (100.0% liked)

Programmer Humor

421 readers
44 users here now

Welcome to Programmer Humor!

This is a place where you can post jokes, memes, humor, etc. related to programming!

For sharing awful code theres also Programming Horror.

Rules

founded 1 year ago
MODERATORS
 
top 34 comments
sorted by: hot top controversial new old
[–] BatmanAoD@programming.dev 92 points 1 week ago (3 children)

Reminds me of quantum-bogosort: randomize the list; check if it is sorted. If it is, you're done; otherwise, destroy this universe.

[–] Zaphod@discuss.tchncs.de 18 points 1 week ago (1 children)

The creation and destruction of universes is left as an exercise to the reader

[–] BatmanAoD@programming.dev 3 points 1 week ago

Creation is easy, assuming the many-worlds interpretation of quantum mechanics!

[–] SubArcticTundra@lemmy.ml 9 points 1 week ago (2 children)

What library are you using for that?

[–] jcg@halubilo.social 22 points 1 week ago* (last edited 1 week ago) (1 children)

is-sorted and a handful of about 300 other npm packages. Cloning the repo and installing takes about 16 hours but after that you're pretty much good for the rest of eternity

[–] Swedneck@discuss.tchncs.de 8 points 1 week ago (1 children)

that explains why it took god 7 days to make the universe

[–] onlinepersona@programming.dev 2 points 1 week ago* (last edited 1 week ago)

We still suffer from the runtime errors that could've been caught at compilation time.

Anti Commercial-AI license

[–] SkaveRat@discuss.tchncs.de 7 points 1 week ago

In Python you just use

import destroy_universe
[–] frezik@midwest.social 1 points 1 week ago

Since randomizing the list increases entropy, it could theoretically make your cpu cooler just before it destroys the universe.

[–] state_electrician@discuss.tchncs.de 77 points 1 week ago (1 children)

My favorite is StalinSort. You go through the list and eliminate all elements which are not in line.

[–] Incandemon@lemmy.ca 4 points 1 week ago (1 children)

I tend to prefer Hiroshima sort. Sorting completed in O(1) time, and it frees up memory too.

[–] 0x4E4F@infosec.pub 2 points 1 week ago

Underrated comment.

[–] ChaoticNeutralCzech@feddit.org 36 points 1 week ago (1 children)
[–] MajorHavoc@programming.dev 23 points 1 week ago
// portability

Gave me the giggles. I've helped maintain systems where this portable solution would have left everyone better off.

[–] Swedneck@discuss.tchncs.de 21 points 1 week ago* (last edited 1 week ago) (1 children)
import yhwh  

def interventionSort(unsortedList):
    sortedList = yhwh.pray(
    "Oh great and merciful Lord above, let thine glory shine upon yonder list!", 
    unsortedList
    )  
    return sortedList
[–] porous_grey_matter@lemmy.ml 7 points 1 week ago

Camelcase in python, ew, a fundamentalist would do that

[–] 1984@lemmy.today 20 points 1 week ago (1 children)

This is the algoritm I use at work.

[–] 0x4E4F@infosec.pub 1 points 1 week ago

Everyone does... it's funny how it eventually works.

[–] Allero@lemmy.today 17 points 1 week ago (3 children)

The most beautiful thing about this program is that it would work.

Various bit flips will once lead to all numbers being in the correct order. No guarantee the numbers will be the same, though...

[–] Midnitte 7 points 1 week ago

Might also take a very long time (or a large amount of radiation).

[–] fallingcats@discuss.tchncs.de 3 points 1 week ago (1 children)

Those bitflips are probably more likely to skip the section erroneously than waiting for the array to be sorted.

[–] Allero@lemmy.today 2 points 1 week ago (1 children)

Fair enough! But won't they flip again to start the program?

[–] fallingcats@discuss.tchncs.de 1 points 1 week ago

The OS would crash entirely before that happens

[–] ProgrammingSocks@pawb.social 1 points 1 week ago (1 children)

Not necessarily. I don't have the numbers in front if me, but there is actually a probability that, past that point, something is so unlikely that you can consider it to be impossible (I.e. will never happen within the lifetime of the universe)

[–] Dyskolos@lemmy.zip 1 points 1 week ago

Yet... The chance is never zero 😁

[–] lemmydividebyzero@reddthat.com 12 points 1 week ago (1 children)
[–] Ephera@lemmy.ml 24 points 1 week ago

I hear, it actually significantly increases the chance of the miracle occurring when you pass the array into multiple threads. It's a very mysterious algorithm.

[–] aeharding@vger.social 9 points 1 week ago* (last edited 1 week ago) (1 children)

Shameless plug for my sort lib

edit: Looking at my old code it might be time to add typescript, es6 and promises to make it ✨  p r o d u c t i o n   r e a d y  ✨

[–] breakcore@discuss.tchncs.de 2 points 1 week ago

Goos stuff, I will start using it. My code needs to chill out anyway

[–] TheOakTree@lemm.ee 6 points 1 week ago (1 children)

Hello programmers...

I recently took a course that went through basic python, C, and C++.

I had a hard time implementing various forms of sorting functions by hand (these were exercises for exam study). Are there any resources you folks would recommend so that I can build a better grasp of sorting implementations and efficiency?

[–] 90s_hacker@reddthat.com 4 points 1 week ago* (last edited 1 week ago) (1 children)

Skiena's Algorithm design manual is very widely recommended for learning algorithms, I've also heard good things about A common sense guide to algorithms and data structures. Skiena's also has video lectures on YouTube if you prefer videos.

From what I've seen, a common sense guide seems to be more geared towards newer programmers while Skiena assumes more experience. Consequently, Skiena goes into more depth while A common sense guide seems to be more focused on what you specifically asked for. algorithm design manual

A common sense guide

[–] TheOakTree@lemm.ee 1 points 1 week ago

Thank you, awesome! I will definitely check out this material :)

[–] mavu@discuss.tchncs.de 1 points 1 week ago (1 children)

Wait, that's exactly how i tidy up my kitchen!

[–] 0x4E4F@infosec.pub 1 points 1 week ago

On a long enough time scale, yes, it will get tidy.