Writing game engine in C++, considering switching to D

Will Cassella via Digitalmars-d digitalmars-d at puremagic.com
Wed Feb 18 12:29:33 PST 2015


Hi,

I have been working on a neat little game engine in C++ for the 
past year or so, and while C++ has served me well in the past, 
there are some points where its just awful to write. While I 
certainly can't call myself a master of C++, there's very little 
about the language that I am not familiar with, and I'd like to 
try something new.

Since I am writing this engine just for fun and experience and 
C++ game engines have been done to death, a D game engine would 
make for an interesting project as well as providing great 
experience with system/application oriented programming.

One of the main differences it seems between D and C++ is that 
the D compiler actually tries to be your friend by avoiding all 
the header/preprocessor/forward-declaration madness. I actually 
don't mind the syntax of C++ for the most part, but there are 
some cases where it just wants to make you tear your eyes out so 
you don't have to look at it anymore (ie, the '.template 
MemberName<T>()' syntax for calling dependant member functions on 
templated variables. I understand why its necessary, but its 
still ugly as hell. I also think that forward-declarations are 
hideous devil-spawn and have no reason to exist in 2015).

I like that D has a garbage collector, because while I intend to 
utilize RAII heavily in lower-level portions of code, having a 
native garbage collector to handle higher-level aspects (ie 
gameplay) would be extremely helpful.

That's not to say I don't have concerns about switching to D, and 
so I'm outlining them below:

Pros:
- Prettier code (this is actually a very big plus for me, I'm 
almost OCD about the cleanliness of my code)
- Modules: Less frustration with the compiler, faster compile 
times
- Larger standard library. I hate it when C++ people complain 
about "non-utility" features for the standard library. You don't 
see C# people whining about how much more productive they are for 
it.
- Garbage collection. Garbage collection allows you to focus on 
algorithms, not management, so I don't understand why some people 
are so vehemntly opposed to it.

Cons (I'm not very experienced with D so these may be inaccurate):
- Not as easy to get up and running (I haven't gotten DMD to work 
with VisualD yet, even though they both appear to be set up 
correctly. There may be an easy fix, but it doesn't exactly 
inspire confidence). PHP may be an awful language, but you can't 
deny that its incredibly easy to get up and running on a web 
server - and there's a lot of appeal to that.
- DLLs. C++ DLLs/SOs are pretty simple for the most part, and 
don't require your code to really know that it's being referenced 
through a DLL. I really don't want to have to write dllmain and 
.def files for my DLLs.
- Portability (?) While I'm not currently targeting more exotic 
platforms like PS4 or XBone or Android or the iPhone or even 
asm.js, I would like to keep those options open. I don't know how 
portable D is towards more gated platforms like those, so if 
anyone can clarify on this I'd appreciate it.
- Library support. This may become a non-issue, as Ds support of 
C libraries seems pretty solid, and it sounds like further 
support for C++ is coming.

Anyway, if anyone here can give me advice on whether I should 
transition or not, I'd appreciate it.

Thanks!


More information about the Digitalmars-d mailing list