r/gamedev • • 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

22 comments sorted by

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.

4

u/NekuSoul 16h ago

Java and C# are notionally a stack-based too, and its extensive runtime compiler system rewrites it into machine code that is cognizant of these modern architectural features.

And not just that. Such a system can even swap out pieces of code at runtime based on metrics in order to automatically minimize branching and choose the code path that's actually the fastest on your specific CPU in real conditions.

That's just something you can't realistically achieve with native code.

(That doesn't mean interpreted code is faster/better of course.)

1

u/OkAccident9994 12h ago

That is, if the C# runtime actually loads within a countable number of business days and actually starts doing things.

1

u/Active_Name5021 11h ago

I like how long it takes for .NET and the JVM to start up, it's telling you to take a break, relax, have a sip of coffee, check your posture.

It's actually a killer feature

0

u/Salty_Role_8539 16h ago

My main idea is that it can be used to solve problems more quickly than C, in some cases at least, since it's a language for a specific problem. Like a certain type of game you want to make so you can fairly quickly set up boilerplate and solve the specific problem.

Maybe I've been using UE4 too much, it's a pain any time I see shaders compiling or when I have to pull teeth to make some functionality that wasn't intended by the devs since the engine mostly supports FPS games (since Fortnite was made in it)

5

u/NekuSoul 16h ago

Some guy on overflow claims its faster than C since it's a tiny step away from assembly.

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.

2

u/Salty_Role_8539 16h ago

True but maybe I can use Forth to write way less code (or use features that C lacks, mainly true metaprogramming) and take up less memory which will come out as faster than using say, Unity or Unreal which loads who knows what just for an empty level

1

u/NekuSoul 16h ago

That's exactly that wishful thinking I was describing: Yes, it's technically achievable, but in real world conditions you are never going to achieve that for anything more than the tiniest proof of concept. It just doesn't scale. And neither Forth nor C are particularly good choices for making actual games.

But if you feel like Unity or Unreal Engine are too heavy for your taste there's three tips of advice:

  1. Sure, these engines might feel heavy for an empty level, but your game won't be an empty level for long. Once you've added all the things you need for your game that overhead of the engine might not be so big anymore.
  2. If that still doesn't satisfy you, there are not only more lightweight engines like Godot waiting for you, but you might also take a look at frameworks instead of engines. These just bring the bare essentials for making games to the table and can be a viable option, particularly for 2D games.
  3. Lastly, and most importantly, choose what you actually want to make: A finished game, or a game engine. You can't do both.

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.

1

u/Salty_Role_8539 17h ago

Chuck Moore is obsessed with efficiency so it might be possible to make a game engine that is custom made for a specific kind of game, and have it run faster because there's no boilerplate. But that's just my theory.

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.

1

u/RobertKerans 12h ago

"read to hard is Forth" mean you do what?

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?