1175
you are viewing a single comment's thread
view the rest of the comments
[-] jeff@programming.dev 6 points 1 year ago

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 21 points 1 year ago

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 8 points 1 year ago

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

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

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.

[-] xigoi@lemmy.sdf.org 8 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.

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

Programmer Humor

19488 readers
1171 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