article comparing Rust and Zig, many points relevant to D

H. S. Teoh hsteoh at quickfur.ath.cx
Tue Mar 9 20:56:12 UTC 2021


On Tue, Mar 09, 2021 at 04:48:28PM +0000, Mark via Digitalmars-d wrote:
> "Why I rewrote my Rust keyboard firmware in Zig: consistency, mastery,
> and fun"
> https://kevinlynagh.com/rust-zig/
> 
> D is not mentioned, but the article focuses on issues of conditional
> compilation and compile-time execution, so I thought the D people will
> find it interesting.

Favorite quotes from the article:

> Despite all this, I still don’t feel comfortable with Rust. It feels
> fractally complex — seemingly every time I use Rust on a new project,
> I run into some issue that forces me to confront a new corner of the
> language/ecosystem.

> Rust has many language features and they’re all largely disjoint from
> each other, so knowing some doesn’t help me guess the others.

These sound alarming to me, as someone who does not know Rust. Maybe I'm
reading too much into it, but it does make me hesitant to try out Rust.

While D is far from perfect, I think it does a lot better in the
department of guessability. I've found IME D generally does what I
thought it would do, except for the occasional hiccups, bugs, or
unexpected corner cases.

Also, IMO D does much better in avoiding fractal complexity -- the core
language features generally integrate well with each other, and things
generally work without too much nitpicking.  Some of the newer features,
however, feel like they're less integrated, and more edging towards
fractal complexity territory.


> I was tempted to conclude that, well, all this complexity must be
> inherent. Perhaps it’s just hard to do compile-time configuration and
> to iterate over distinct types efficiently in a safe, compiled
> language?

This was also how I felt in C/C++ before I found D. :-D  I'd say that
70-80% of the time I spent writing C++ is spent wrestling with the
complexity of the language and peripheral things like memory management
concerns.  It conditioned me to accept that programming is inherently
complex, programming languages are consequently inherently complex, and
therefore the act of programming must necessarily also be complex.

Then I found D.

Suddenly, many things that were complex in the past are now simpler,
sometimes by a lot. I found my mental resources freed up to focus on the
problem domain rather than wrestling with the language.  D hits many of
the points of friction with other languages IME:

- The tedium of memory management in C/C++: thanks to the GC, my APIs
  are liberated from memory-management clutter, and my brain is freed
  from the constant drone of memory-related concerns to actually make
  progress in the problem domain. (And once in a while when the GC isn't
  good enough, D is flexible enough to allow me to rewrite select parts
  of the code with manually-managed memory -- without having to
  re-architect the entire program from scratch.)

- Boilerplate in Java: when writing Java, I find myself fighting with
  the language more often than actually making progress with the problem
  domain.  A lot of this has to do with metaprogramming features, that
  let me factor away the endless stacks of boilerplate that I'm forced
  to write in Java.

- Too many (nested) loops: lately I've also been enjoying writing
  functional-style code with UFCS -- it's been a big time-saver. Instead
  of writing yet another loop, or worse, N-level-nested loops to express
  some complex data manipulation, a UFCS one-liner neatly encapsulates
  all of that complexity into a form not only fast to write, but also
  easy to read and easy to rearrange, extend, and refactor.

- Single paradigm: languages like Java (or Haskell) force you to
  shoehorn every problem into an OO paradigm (resp. functional
  paradigm). Sometimes, some code is simply better to write in a
  different paradigm, but in these languages you're straitjacketed and
  have no choice, so you end up fighting the language more than making
  progress in the problem domain.  D being multiparadigm is a big boon
  in this respect.

D certainly isn't perfect -- it has its own share of dark corners, WATs,
and poorly-interacting corner cases.  But it's a lot better than the
other alternatives I've tried so far.


T

-- 
My program has no bugs! Only unintentional features...


More information about the Digitalmars-d mailing list