News for hackers. Stuff that matters.
Re:Show HN: Scratch.js – Interactive JavaScript Scratchpad by gitgud on Wednesday November 18, 2020 @04:38PM (#25142772)
Well you can easily detect trivial examples like "while(1)" and "for(i=0;true;i++)". But otherwise how would know some is an infinite loop?

Put a bit more simply, to work out if a problem is unsolvable (infinitly looping) you need to evaluate the problem... By trying to solve it. Checkout the halting problem for more details.

https://en.m.wikipedia.org/wiki/Halting_problem

Re:Show HN: Scratch.js – Interactive JavaScript Scratchpad by teraflop on Wednesday November 18, 2020 @05:02PM (#25143027)
"Solving" infinite loops doesn't necessarily mean accurately predicting a priori whether a piece of code will terminate. It can just mean ensuring that if the code does try to run indefinitely, it doesn't have unfortunate effects such as blocking the UI thread without the possibility of being interrupted.
Re:Show HN: Scratch.js – Interactive JavaScript Scratchpad by gitgud on Wednesday November 18, 2020 @06:03PM (#25143825)
> It can just mean ensuring that if the code does try to run indefinitely, it doesn't have unfortunate effects such as blocking the UI thread without the possibility of being interrupted.

Well that can be achieved by executing the code in a background worker thread. Which doesn't affect the UI thread in browsers... no sure how it's managed but I think you could terminate it after a certain amount of time too

Re:Show HN: Scratch.js – Interactive JavaScript Scratchpad by angleofrepose on Wednesday November 18, 2020 @05:12PM (#25143149)
> ctrl-C functionality

OS implementations dont solve the halting problem. I agree with the sibling comment.