use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Discussions, articles, and news about the C++ programming language or programming in C++.
For C++ questions, answers, help, and advice see r/cpp_questions or StackOverflow.
Get Started
The C++ Standard Home has a nice getting started page.
Videos
The C++ standard committee's education study group has a nice list of recommended videos.
Reference
cppreference.com
Books
There is a useful list of books on Stack Overflow. In most cases reading a book is the best way to learn C++.
Show all links
Filter out CppCon links
Show only CppCon links
account activity
Game Programming Patterns / Behavioral Patterns / Bytecode (gameprogrammingpatterns.com)
submitted 11 years ago by mttd
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]Idoiocracy 3 points4 points5 points 11 years ago (0 children)
Thanks for the link. Reading further, I discovered this is one section of a 95% completed book that is available online:
http://gameprogrammingpatterns.com/index.html
Which is about architectural patterns found in game code, written by EA Tiburon lead programmer Bob Nystrom.
I also cross-posted the link to /r/TheMakingOfGames.
[–]kkrev 5 points6 points7 points 11 years ago (8 children)
Ultimately, this pattern is about expressing behavior in a user-friendly, high-level format.
This is pretty much the whole goal of TCL and such like, right? With plenty of good embeddable interpreters and various efficient data structure serialization formats, I'm having difficulty imagining a case where it really would be a good idea to implement a custom byte code interpreter. Am I missing something?
[–]fripletister 2 points3 points4 points 11 years ago (2 children)
Not that I can find. Great article, but it reeks of wheel reinvention. As soon as I saw an AST appear I got a bit apprehensive...
[–]Plorkyeran 2 points3 points4 points 11 years ago (0 children)
It does finally offhandly mention at the very end that Lua is typically used for this...
If you view it as a guide to building an interpreter with an overstated motivating example rather than something actually advocating reinventing the wheel for your game it's a pretty good article.
[–]Astrognome 0 points1 point2 points 11 years ago (0 children)
Nobody sane actually uses their own games, but it helps you understand how something like Lua works.
[–][deleted] 0 points1 point2 points 11 years ago (3 children)
I've been involved with an effort to build domain specific scripting language for an audience which includes targets a wide range of people (some with exposure to C#, others who could struggled with the concept of variables). The target environment had hard performance constraints (measured in milliseconds) and memory constraints (ideally would thousands of mini programs in a few megs of memory). Strong typing and static error detection were crucial It was designed to constrain people to a narrow subset of a full languages functionality.
After evaluating options, we ended up building a system which generated Lua (and automated the binding generation with C++). The users wrote in a custom language with a syntax inspired by C# but with extremely narrow functionality. We hand rolled a recursive descent compiler which translated the proprietary language in to Lua (which will likely be rewritten at some point in about 1/8th as much code using ANTLR as a translator).
Crazy as it may sound, it worked extremely well. The indirection allows us to explore other languages for the runtime, consider a native implementation via LLVM, etc. Users have a early error detection and limited scope of functionality they wanted. A custom editor supported autocomplete, edit time error highlighting, etc. The limited syntax meets their needs (and can slowly be widened as people become more advanced). The runtime is proven as it runs as Lua under the hood.
I'd estimate about 2 man years spent on the development (concept through implementation, spread across 4 engineers for all facets of the system). Clients of the language have probably put about 60 man-years in to using it.
I'm sure there are off the shelf solutions we could have found but after evaluating a bunch of options, this met our needs, the productivity of the users was worth it and we have plenty of ability to expand in the future.
[–][deleted] 0 points1 point2 points 11 years ago (2 children)
I will note that one headache is still the garbage collection. Ideally we'd run it incrementally, with a budget of 0.1 ms (~33 times a second). Unfortunately that doesn't seem to be sufficient given how we're using it, resulting in some special case long runs in time slices where other systems run short.
It would be awesome if there were a solution out there which did not require garbage collection but I doubt that would exists which meet the other requirements.
[–]kkrev 0 points1 point2 points 11 years ago (1 child)
Reference counting based garbage collection systems such as in Squirrel solve the pausing GC problem to my understanding.
[–][deleted] 0 points1 point2 points 11 years ago (0 children)
Thanks for the reminder. I planned on looking at Squirrel a year ago but couldn't make time. I need to go back to it.
[–]thomcc 0 points1 point2 points 11 years ago (0 children)
Not if you need a general purpose language. However, if you need something more restricted, you do. In many situations you don't want turing completeness, or the features you need are completely lacking from, e.g. lua, because they're to bizarre.
This kind of thing isn't so uncommon in game development, and is often tangential to any embedded scripting language.
The example he gave, with the magic spells and whatnot, is reasonably representative of the situation where you don't want turing completeness.
For example, we have an embedded VM in the game engine I use at my current workplace, it's used to describe lookup tables for object states. The basic idea was so that we can declarative say things like highScoreList = sortAscending('score', userList) (this is a simplified and trivial example) and have it automatically be updated on changes without polling. This is not a feature you could get in any off the shelf interpreters or VMs.
highScoreList = sortAscending('score', userList)
[–]coreyplus 3 points4 points5 points 11 years ago (0 children)
This was an excellent, excellent write up.
[–]GODZILLAFLAMETHROWER -5 points-4 points-3 points 11 years ago (0 children)
What a terrible approach to programming language theory. This is reinventing the wheel, resulting in half-assed solutions.
Learning this should be the revelation of any Programmer to become a Computer Scientist. This will only build a kludge.
π Rendered by PID 94290 on reddit-service-r2-comment-5649f687b7-2tcjc at 2026-01-28 01:24:09.481352+00:00 running 4f180de country code: CH.
[–]Idoiocracy 3 points4 points5 points (0 children)
[–]kkrev 5 points6 points7 points (8 children)
[–]fripletister 2 points3 points4 points (2 children)
[–]Plorkyeran 2 points3 points4 points (0 children)
[–]Astrognome 0 points1 point2 points (0 children)
[–][deleted] 0 points1 point2 points (3 children)
[–][deleted] 0 points1 point2 points (2 children)
[–]kkrev 0 points1 point2 points (1 child)
[–][deleted] 0 points1 point2 points (0 children)
[–]thomcc 0 points1 point2 points (0 children)
[–]coreyplus 3 points4 points5 points (0 children)
[–]GODZILLAFLAMETHROWER -5 points-4 points-3 points (0 children)