On 8/26/2018 11:16 PM, Manu wrote:
The code looks the same, and in fact, is about 98% the same.
This code appears to be a mechanical translation.

It's not. It's by hand. But I had a specific goal of minimizing the diffs, so that if the translation didn't work, it reduced the number of places to look for the mistake. And in fact, this has saved me a LOT of grief :-)


That's not what
happened in this case; he wrote his game in D from scratch.
It was just that he arrived at mostly the same place. He was googling
for styling and sample material, but I suspect the problem was a lack
of topical material demonstrating how he might write his D code
differently.

It takes time to learn how to write idiomatic D effectively. I'm still learning how to do it right, too.


It's also the case that the significant difference between C++ and D
(in my experience) mostly come down to: D has modules, tidier meta,
UDA's, slices, and ranges/UFCS. In trade, D struggles with const, and
ref is broken.
If your code doesn't manifest some gravity towards one of those
features, it will tend to be quite same-ey, and advantage may not be
particularly apparent.

I suspect that is still a bit stuck on looking at individual instruments and not seeing the orchestra.

Let's take the much-maligned D const. It isn't C++ const (let's call that "head-const", because that's what it is). Head-const for a function parameter tells us very little about what may happen to it in the function. You can pass a head-const reference to a container, and have the function add/change/delete every element of that container, all without a peep from any C++ tool. Looking at the function signature, you've really got no clue whatsoever.

The reason people have trouble with transitive-const is that they are still programming in C++, where they *do* add/change/delete every member of the "const" container.

That includes me. I try to add transitive-const, and it won't compile, because I as well am used to replacing the engine and tail lights in my head-const car. In order to use transitive-const, it's forcing me to fundamentally re-think how I organize code into functions.

For example, dmd is full of functions that combine data-gathering with taking-action. I've been reorganizing to separate data-gathering and taking-action into separate functions. The former can be transitive-const, maybe even pure. And I like the results, the code becomes much easier to understand.

Reply via email to