What were some of your biggest breakthroughs while learning D?
solidstate1991
laszloszeremi at outlook.com
Mon Jul 19 17:23:03 UTC 2021
On Tuesday, 6 July 2021 at 20:53:12 UTC, Dylan Graham wrote:
> [Inspiration from this r/C_Programming
> post](https://www.reddit.com/r/C_Programming/comments/oeoq82/what_were_some_of_your_biggest_breakthroughs/)
>
> What's something you learnt or realised, a habit you developed,
> something you read or project you worked on that helped
> accelerate your understanding and/or productivity in D?
>
> For example, mixin templates finally clicking and you realise
> how to use them in your code base. Stuff like that.
1) Actually learning how to write code.
Unfortunately in college, we were learned to "just follow orders
of our higher ups", and often were discouraged from software
optimization, with the claim that modern CPUs have many cores and
stuff.
2) Learning that following a single programming paradigm isn't
good.
Prior to D, we mainly learned Object Oriented languages, and
learned that that's the end of all things. We learned that
"Aspect Oriented Programming" also exist, but that's all.
When I started to write my own game engine, I did it in a
strictly OOP sense, then, after it was unable to render more than
one million pixels per seconds on my outdated PC, I decided to
switch gears, and looked up a lot more things beyond what OOP
could offer. First I've learned about Data-Oriented Design, which
made me change so many things I immediately incremented the
version number from 0.1 to 0.9 (biggest mistake). It was faster
than before, so I looked even harder. I remembered a thing we
learned, called SIMD, so I looked it up to utilize it for
alpha-blending. I had to run a lot of circles with it, the
initial assembly code I copied from the web had serious issues
and otherwise everyone on the internet wanted to tell me the true
gospel of OpenGL and shaders (which are nice and stuff, but
couldn't do integer arithmetic easily, and not at all on older
cards), then I needed to switch to using intel-intrinsics instead
of using hard to maintain and seemingly easy to malfunction code.
Then I learned some functional programming. I think many of its
evangelists are quite irritating and think it'll replace
everything, but it has its own place. Nowadays I started to label
my functions with `const` whether its possible, so I won't get
the possibility of a getter function writing unintentional data.
:) It might have leaded to LDC2 better optimizing stuff in my
engine by parallelization, with lead to a few confusing, hard to
debug issues, that were resolved by using `synchronized`.
While in many cases I had to give up the OOP parts, I managed to
keep its modularity. However, sometimes I use function pointers
or delegates instead of classes: similar kind of modularity, but
often simpler. Using `@nogc` and `nothrow` helps a lot with
performance, especially as I'm now forced to not allocate on the
heap if possible. I'm at a point that with my knowledge and small
team, I dared to begin to write a few simple software synths for
it, which is quite fitting for a "retro-focused" game engine.
More information about the Digitalmars-d
mailing list