News for hackers. Stuff that matters.
Re:Threaded Code (1999) by pjc50 on Friday May 07, 2021 @03:36AM (#27073342)
Slightly confusing with the other meaning of threading, this is more like what is pejoratively called "spaghetti code" which was mostly superceded by structured programming. Easier to understand, marginally less efficient, especially for the interpreter case.
Re:Threaded Code (1999) by talideon on Sunday May 09, 2021 @09:48AM (#27095857)
No, it's nothing like that. It's a method for implementing interpreters that works well for Forth. It has absolutely nothing to do with 'spaghetti code' or structured programming.

In this case, the term 'thread' is the same in both usages. The confusion is that people started using 'multithreading' and 'threading' interchangeably. The concept of a 'thread' existed before Forth and any form of multitasking were invented, and MVT (which used the term 'task' rather than 'thread') and Forth were both invented around the same time.

I'd recommend you read the Wikipedia page for 'Threaded code': it's much clearer than the linked page, and will give some background of the purpose behind it. Most interpreters that don't do something like walking an AST do some form of it, even if that's by using some kind of bytecode. If you've ever seen code written using continuation-passing style, it's implementing a form of threaded code.

Re:Threaded Code (1999) by saagarjha on Friday May 07, 2021 @06:49AM (#27074487)
Threading can be a fairly significant speedup for most VM interpreters, and an optimization often worth making in cases where performance matters.
Re:Threaded Code (1999) by rusty-cohle on Friday May 07, 2021 @03:38AM (#27073353)
It is often used as a perjorative but the spaghetti is in the eyes of the beholder.