On Sunday, 4 February 2018 at 04:51:00 UTC, Jonathan Marler wrote:

How did it compare to the Go version?

I started implementing one myself as a learning experience and recall I looked at the Go version a few times (https://github.com/marler8997/hacknes). Mine was in C++ though since I was also trying to re-familiarize myself with C++. Definitely curious on your thoughts on how the GO version compared to your D version.


The code itself is pretty much a 1:1 copy. The style Go forces on you is easy to replicate in D.

A few things I learned that stood out:
1. It was incredibly easy to move the code from Go to D. Most of the work only took maybe 4 days. D is very flexible & made it easy.

2. DMD just doesn't produce fast code compared to other modern compilers. It's a shame LDC or GDC isn't the default D compiler.

* Gotchas
Go doesn't use the same operator precedence rules as C & D. Not sure why this surprised me but it lead to some initially confusing bugs.

* Code differences
The only major difference relates to state file serialization.

Go has a binary serialization/encoding library (encoding/gob) in its standard library which the Go author used to save/load the machine state. Each component (CPU, APU, PPU, etc) is passed the binary stream & adds what it needs saved.

In the D version I use D's built-in associative arrays (equivalent to Go's map). D makes it easy to convert to/from a string representation of most types so I just convert the AA to a string, compress it & save it to disk.

* Garbage collector
In the D version this doesn't even come into play because nothing is allocated during "step" execution. The only allocations are during console initialization or during things you won't be doing often like setting the APU sample rate.

Reply via email to