r/gamedev • u/Salty_Role_8539 • 17h ago
Discussion Is a 3D game engine in Forth possible?
I learned about the language maybe a year ago, it's apparently really clean, easy to modify and powerful but very dead language as of 2026.
Some guy on overflow claims its faster than C since it's a tiny step away from assembly.
What do you all think?
0
Upvotes
12
u/finlay_mcwalter 16h ago edited 16h ago
Make - sure. Faster than C - probably not (mostly because C compilers have had huge amounts of money spent on them).
Talking about "code is fast because it's like assembly" is 1990s thinking. On modern architectures code is fast because a) it keeps pipelines full b) it makes efficient use of SIMD c) makes efficient use of cache locality and d) makes sensible use of multiple threads.
None of these concerns exist in either C or Forth. C can be still be fast on modern CPUs (as can other languages) because those huge investments into compilers (and runtime systems, for languages that have them) allow source code that is agnostic to those concerns to still use those advanced architectural features.
Maybe if someone drops literally tens of millions of dollars of engineer time to optimise Forth for all these things, it might work fine. That's probably not impossible - Java and C# are notionally stack-based too, and their extensive runtime compiler systems rewrite them into machine code that is cognizant of these modern architectural features.
At the end of the day, Forth is terse and unpleasant to read, and the "it's close to the hardware" advantage (for some hypothetical 1980s Z80-ish single-threaded cacheless register-poor non-superscalar SISD plain-vonNeuman hardware) is decades from being remotely relevant.
Language cranks are always quick to point out some magical advantage their pet thing has, and that new-fangled things ignore (because of some big-business conspiracy), but they for some reason haven't actually done the thing in language X that they say is much easier and faster in X than in everything else.
5
u/NekuSoul 16h ago
This either very old advice, or they're falling into a common trap: Sure, it's theoretically possible to write code more optimally when the code you're writing is more close to assembly. But in reality, any modern compiler will just outperform you in the optimizations it applies. And if you tried applying optimizations on the same level as a compiler, your code would just end up looking like gibberish.
13
u/DaTruSpork 17h ago edited 16h ago
A 3D game engine is/was possible in excel like 20 years ago, so sure. Go Forth and make your engine
1
u/bird_feeder_bird 17h ago
Forth is awesome, very satisfying to use. It isn’t necessarily faster than C, but is definitely useful for systems that don’t have an adequate C compiler, since a Forth interpreter is much easier to implement.
3
u/cosmo7 16h ago
I like Forth but I wouldn't use it for a game engine for several reasons.
There's no ecosystem; no libraries, no toolchain, no community - you're on your own. This is just as well, since trying to understand other peoples' Forth - and keeping track of the stack - is difficult. And finally, Forth might be faster than some other languages but game development is generally GPU-bound rather than CPU-bound.
2
u/igna92ts 17h ago
I made some raylib bindings in gforth so I don't see why you couldn't do the same but you'll have no guardrails whatsoever and it won't be faster than C.
2
u/mindstorm8191 16h ago
Personally, I wouldn't invest effort into trying to build a 3d engine in an old language, simply because one guy claims it's faster. Are you really going to compete in speed with all the optimizations that long-standing libraries already utilize?
And if you are successful, are people going to stop to learn forth, for a marginal speed improvement?
Modern 3d libraries are already very fast, and hardware is built to compliment such libraries. If your end goal is to build a game with it, then it's like reinventing a rocket engine - and you didn't even know if it'll work, or be better. Indie games rarely push on rendering limitations anyway; even major studios find little reason to increase graphical demand, since players barely notice anyway.
If you're passionate about Forth and want to make a 3d engine with it, then I don't want to dissuade you. But be realistic about what can come of it.
2
u/DaedalusRaistlin 14h ago
Forth is hard to read. I don't think it's a good language for stuff like you'd like to read and understand later.
Here's some Forth code code for part of my C99 style C compiler. It's not very readable.
2
u/Naucto 12h ago
If what draws you is the language itself, imo the most fun way in is to build a tiny Forth first. jonesforth is a classic for that: a whole Forth in one heavily commented assembly file, you read it top to bottom and understand how it works.
After that, a small 2D thing (fixed resolution, a few drawing words on top of SDL or raylib) is a much better fit than a 3D engine tbh. You get to play with the language without fighting the GPU side alone.
2
u/podule-games 10h ago
It's absolutely possible, but "Language x is faster than language y" isn't a useful comparison when you're talking about compilers because it's the compiler that makes stuff fast, not the language. Once you're into LLVM, it doesn't really matter much what language was used.
Forth is a weird language, I used to use it (on PalmPilot of all things), and it's not at all related to assembly languages, it's a high level language just like C is. Look at a program written in Forth, and the same program written in AMD64 assembly language, they're really nothing alike.
Also, "close to assembly" doesn't mean "fast" anymore. It did when compilers were bad and assembly languages were simple enough for humans to use well. These days compilers are way better than you or I will ever be at optimising code, and modern processors have instruction sets that are just too complex for humans.
As an example, the 6502 processor has 56 instructions, a modern Intel or AMD processor has about 1,000 (or almost 4,000 if you count the variants separately). So back in the 1980s you were using a very small processor and competing with compilers with little optimisation. These days we're using extremely complex processors with compilers that have had decades of optimisation by experts in the field.
There is really is no way that you or I write programs of realistic scale in modern assembly language and beat a modern compiler, it really is nigh on impossible.
1
u/Striking_Director_64 17h ago
basically anything that can make syscalls can theoretically be used to make a 3d engine, so yea, it can be used to make a game engine
1
u/Technical_Drink_846 15h ago
As long as you have access to a FFI or ABI I don't see why you couldn't. I wouldn't recommend it though. Write your game in C or asm instead.
1
u/Random 15h ago
Two things.
You would have to include a telescope in your game. Read about this history of Forth...
There is a very cool Eurorack synth module called a Monome Teletype that is coded in Forth...
So Forth isn't... dead... it just has a few flesh wounds?