Hacker News new | past | comments | ask | show | jobs | submit login
My history with Forth and stack machines (2010) (yosefk.com)
56 points by pmoriarty on Jan 11, 2015 | hide | past | favorite | 26 comments



Hacking for the latest and greatest Xeon CPUs feels a lot like Forth on small machines to me. Each core has only 256KB of fast private memory (L2 cache). Squeezing the working set into that memory means fast execution that is independent of the other cores. That is really worth spending some brain cycles on when optimizing for 36+ core servers.

The more things change, the more they stay the same?


Some days ago, we only had 64kb main memory to squeeze our applications into ... that was also a great experience. The old times come back?? ;)


Do you know any interesting links about these kinds of optimizations?


Sure:

Intel optimization reference manual: http://www.intel.com/content/dam/www/public/us/en/documents/...

Agner Fog's Software optimization resources: http://www.agner.org/optimize/

I don't think it starts making sense until the 5th reading or so :).


I'm among those who have enjoyed the satisfaction of making my own Forth-like, and I've even used it only to find the same kinds of difficulties as author. Aiming for less is always a valid approach, but it's hard to reconcile with this era of software and the benefits of sheer magnitude. It might have been less true in the early 70's when software was less of an "ecosystem."

But on re-reading this for the n'th time I think the lede of this one is in the comments. Like any guru who is selling a "right way of doing," Chuck Moore has always had a business interest in selling snowflake Forth services of some kind. He, and other Forth followers, may well believe the pitch fervently. It is, at least, a relatively self-consistent ideology, and it discards the messy aspect of building any kind of institutional presence. But it also has a kind of dogmatic quality.


I also wrote my own Forth implementation, in 6502asm, back in high school. Was great fun and a great learning experience. I later wrote a Star Trek space battle game in it. As for aiming for less is hard to reconcile - that's where you and the majority of programmers in the industry go wrong. You should have said "aiming for less is always a valid approach." - full stop.

My LMDB database engine is the world's smallest/fastest/most reliable full ACID transactional data store. The core of the engine is less than 32KB of x86-64 object code - it can execute entirely within a CPU's L1 instruction cache. It blows away other DB engines that are several times bulkier in size. It's only 6kloc of C. It does what it does precisely by following the Forth philosophy - do what you need, throw everything else away. http://symas.com/mdb/

Efficiency always matters, even today with CPUs whose L2 cache is larger than entire computer systems of 30 years ago. Efficiency always matters because all of these compute resources have a cost - electricity isn't free, and time spent is irreplaceable.

I have other ongoing projects in Forth because it can handle some cases easily that are awkward in other languages. (E.g., an ASN.1 parser for dynamically adding new syntaxes to the OpenLDAP server. Forth is the perfect tool for the job because it's inherently a language designed for extension.)


Forth has good affordances for compact solutions. Compactness is the is the single most important metric in robust solutions. Tractable, low inertia, retargetable and emulatable are all qualities that come with compactness.

One would do well I think to explore through old code bases and algorithms for stuff that ran well on those old systems. Because memory is plentiful doesn't mean we need to waste memory bandwidth or cache locality.


Various past comment threads:

* https://news.ycombinator.com/item?id=1680149

* https://news.ycombinator.com/item?id=8146306

* https://news.ycombinator.com/item?id=3963896

* https://news.ycombinator.com/item?id=2985601

* [a handful of zero-comment and one-comment reposts I've elided]

This is a very popular repost—as it should be, because it's a very good and well-thought-out article, and a surprisingly well-reasoned and well-written example of the "meditation on a programming language" genre of blog post—and each of the past comment threads is also worth consulting.


Eric LaForest did a nice course on stack machines : http://csclub.uwaterloo.ca/media/Eric%20LaForest:%20Next%20G...


I'm building a Javascript based Forth-like that uses JS values (including functions) rather than bytes.

http://github.com/lawless-m/North

Stack based is fun.


Smalltalk bytecode also works on a VM with a stack that accepts random objects


That's interesting. I am looking for things to write in my new language. The itch was to make a Forth, coming up with an application of it is the next problem.


I never did much Forth, but I wrote a lot of PostScript and I really enjoyed it in a lisp-like kind of way.


I love Forth.

It's quirky but extremely elegant.

Either its time has long gone or its time hasn't come yet, hard to decide which.


FYI, bitcoin's programmable signature language is Forth. Variants of Forth are used on many NASA spacecraft and rovers. Forth is doing quite well, thank you :)


> Forth is doing quite well, thank you :)

I know. But I feel that it still has not reached anywhere near its potential and I'm not sure if it ever will.

First time I worked with it was in the 1980's, I've been only an observer since then but the bug never left me. It's a language for the equivalent of software jewelers.


I used Forth professionally in an industrial single-board computer product in the late 1980s. But I haven't see it "in the wild" since, with the exception of the occasional mention in spacecraft control.


There's a good chance that one of the embedded systems in your car uses it. Especially the really small ones (too small to run RTOS).


You might like Kitten (work in progress):

http://kittenlang.org/

Or Factor:

http://factorcode.org/


Also the basis of the CPU used on Philae : http://www.cpushack.com/2014/11/12/here-comes-philae-powered...

Quite an achievement for that little not popular enough language


Could you please elaborate: what's 'bitcoin's programmable signature language' and where is it used?



Thanks! Is scripting support adopted by any other cryptocurrencies?


Everything based on bitcoin's code base.


I was just discussing Forth metacompilers a moment ago:

http://www.reddit.com/r/tinycode/comments/2rzuwp/da_here_h_2...

http://www.reddit.com/r/Forth/comments/2s0g4a/da_here_h_2_h_...

I think there is an opening again for Forth in the Internet of Things. That's many low-power (and thus) small computers.


At one period, there was a lot of interest in stack machines; IIRC, there was a BYTE issue that either covered it in many articles, or was dedicated to that topic. Can't remember the month and year.




Consider applying for YC's Spring batch! Applications are open till Feb 11.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: