this post was submitted on 02 Oct 2023
1147 points (98.6% liked)

Programmer Humor

19589 readers
638 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
 
you are viewing a single comment's thread
view the rest of the comments
[–] bleistift2@feddit.de 170 points 1 year ago* (last edited 1 year ago) (6 children)

There are really few problems that are “impossible.” That is, if you count those customers/managers are interested in. All the rest is just “I’ll need 10 years, 230 million Dollars and a research team”

XKCD 1425 by Randall Munroe. License: CC BY-NC 2.5

[–] xigoi@lemmy.sdf.org 91 points 1 year ago (6 children)

“The other programmers keep accidentally writing code that ends up in an infinite loop. I'd like you to make a program that can reliably detect that.”

[–] elvith@feddit.de 31 points 1 year ago (3 children)

You may joke, but if I had a penny for every time someone asked me to solve a problem, that basically boils down to the halting problem, I'd be rich.

[–] xigoi@lemmy.sdf.org 10 points 1 year ago (1 children)

Yeah, accidentally running into the halting problem is common in automatic code analysis.

[–] PoolloverNathan@programming.dev 13 points 1 year ago

It'd be nice if we wrote something to detect it running into the halting problem.

[–] randon31415@lemmy.world 7 points 1 year ago (2 children)

I have always wondered why the answer to the halting problem isn't: "If no output has been returned in X time, BREAK, restart program from beginning."

[–] niartenyaw@midwest.social 25 points 1 year ago (1 children)

what if it needed just one more second to complete?

[–] Shalaska@programming.dev 14 points 1 year ago (2 children)

Because that will fail to detect a program that halts in X+1 time. The problem isn’t to detect if a program that halts halts, the problem is to generally create an algorithm that will guarantee that the analyzed program will always halt given an infinite time running on an infinite computer.

[–] Brainsploosh@lemmy.world 2 points 1 year ago* (last edited 1 year ago)

But you could also do a mean time analysis on specific tasks and have it cut off at a standard deviation or two (90-98% of task times covered), and have a checkbox or something for when the user expects longer times.

You could probably even make this adaptive, with a cutoff at 2x the standard time, and updating the median estimate after each run.

[–] drcobaltjedi@programming.dev 6 points 1 year ago

I was recently tasked with the traveling salesman problem on a project. My first pass was quick but produced sloppy inefficient results. Well boss didn't like it so he had me go back at it again so it would be far more accurate. Well now it slogs through figuring out an optimal solution of several thousand points.

[–] WhiskyTangoFoxtrot@lemmy.world 10 points 1 year ago

Just check the git blame.

[–] jeff@programming.dev 7 points 1 year ago (2 children)

A full solution to the halting problem can't exist. But you can definitely write a program that will "reliably" detect them to a certain percentage.

And many applications do exactly that. Firefox asked me today if I wanted to stop a tab because it was processing for too long.

[–] bleistift2@feddit.de 19 points 1 year ago (2 children)

That’s not even close to solving the halting problem. FF doesn’t check if the program has been in its current state before. It literally just checks if 10 seconds have passed without JS emptying its event loop.

[–] jeff@programming.dev 9 points 1 year ago (1 children)

Right. There is no solution to the halting problem, that's been proven. But you just showed you can very easily create a way of practically solving it. Just waiting for 10 seconds does it. That will catch every infinite loop while also having some false positives. And that will be fine in most applications.

My point is that even if a solution to the halting problem is impossible, there is often a very possible solution that will get you close enough for a real world scenario. And there are definitely more sophisticated methods of catching non-halting programs with fewer false positives.

[–] xigoi@lemmy.sdf.org 2 points 1 year ago (1 children)

And that will be fine in most applications.

Have you never written a useful program that took more than 10 seconds to complete?

[–] bleistift2@feddit.de 5 points 1 year ago (1 children)

I fully agree with your sentiment. But just in case: If you’re blocking the main thread of a browser for seconds at a time, you should look into that.

[–] xigoi@lemmy.sdf.org 1 points 1 year ago

I'm not talking about web applications.

[–] cheery_coffee@lemmy.ca 4 points 1 year ago

My loop isn’t infinite, just longer than the heat death of the universe.

[–] xigoi@lemmy.sdf.org 6 points 1 year ago

For JavaScript apps, stopping them when they consume too much resources is definitely a good idea. But if you work on some project where it's common to run computionally intensive tasks, it can be harder to detect non-halting.

[–] float@feddit.de 4 points 1 year ago* (last edited 1 year ago)

Just because it's not possible on a Turing Machine doesn't mean it's impossible on a PC with finite memory. You just have to track all the memory that is available to the algorithm and once you detect a state you've seen already, you know it's not halting ever. The detection algorithm will need an insane amount of memory though.

Edit: think about the amount of memory that would need. It's crazy but theoretically possible. In real world use cases only if the algorithm you're watching has access to a tiny amount of memory.

[–] CurlyChopz@programming.dev 2 points 1 year ago (1 children)

Easy.

If( loop == inf) {

End;

}

Pay check please?

[–] xigoi@lemmy.sdf.org 2 points 1 year ago (1 children)
[–] CurlyChopz@programming.dev 3 points 1 year ago

Woah! This is worthless!

[–] mindbleach@sh.itjust.works 1 points 1 year ago

There have been genuine efforts to do that. Obviously (well, for a very niche use of "obviously") it's not always possible, but detecting infinite loops isn't like the uncertainty principle.

It's called The Terminator.

[–] notabot@lemm.ee 46 points 1 year ago

This. Very few problems are truly impossible to solve, they arem in fact, just wildly impractical to solve. So don't try to tell the PM/client/coworker-with-a-'brilliant'-idea it can't be done, tell them what it'll take to work out what it'll take to do it. Either they go away, or you end up in charge of a project with an astronomical budget and no clearly defined deliverables.

[–] randon31415@lemmy.world 25 points 1 year ago (1 children)

I mean, now a days, I can upload the image into stable diffusion automatic1111 and click interrogate CLIP and then see if it outputs "bird" as a reverse promopt, but this comic WAS from 4 and a half years ago, so the programmer was right on the time-frame.

[–] float@feddit.de 7 points 1 year ago* (last edited 1 year ago)

It always depends on which existing tools you have access to. Go back some more years and there is no GPS. Detecting the bird will be the easier problem then.

[–] AccidentalLemming@lemmy.world 23 points 1 year ago (2 children)

Funny thing is, since that comic was originally published bird detection has gotten a lot easier

[–] Ultraviolet@lemmy.world 30 points 1 year ago (1 children)

About 5 years after, and there was a research team behind it.

[–] Brainsploosh@lemmy.world 4 points 1 year ago

Several teams actually

[–] Setarkus@toast.ooo 21 points 1 year ago

I bet it's because the camera now also scans for the 5G radio waves that are used to control the "birds" instead of just recording waves in the visible spectrum

[–] darcy@sh.itjust.works 16 points 1 year ago

respect for uploading the image, linking the page, and crediting the author :)

[–] Pistcow@lemm.ee 13 points 1 year ago (2 children)
[–] Swedneck@discuss.tchncs.de 18 points 1 year ago (2 children)

a miserable little pile of secrets

[–] ryven@lemmy.dbzer0.com 12 points 1 year ago* (last edited 1 year ago) (1 children)

Diogenes bursts into Dracula's throne room while holding a chicken.

[–] AngryCommieKender@lemmy.world 2 points 1 year ago

Plato bursts into Dracula's throne room holding a lantern and a mirror

[–] Pistcow@lemm.ee 2 points 1 year ago

Throws water bowl

[–] unreachable@lemmy.world 8 points 1 year ago (1 children)

insert "bird isn't real" meme

[–] lugal@lemmy.ml 5 points 1 year ago

Bird watching goes both ways