What are (were) the most difficult parts of D?

H. S. Teoh hsteoh at quickfur.ath.cx
Thu May 12 18:03:24 UTC 2022


On Thu, May 12, 2022 at 01:06:02AM +0000, Christopher Katko via Digitalmars-d-learn wrote:
[...]
> Cool useful library functions like sumElement that magically don't
> work on static arrays.

Just slice it with []:

	int[5] data = [ 1, 2, 3, 4, 5 ];
	auto sum = data[].sumElement;

The main reason is that static arrays cannot shrink (their length is
constant), so they don't qualify as ranges. No problem, [] takes a slice
of them that *can* shrink.


> 'private' is per module, not per class, making it pretty much useless
> for preventing incorrect access and using .

This is a common complaint.  But IME, I haven't really run into problems
with it.  Accessing private members really only becomes a problem when
you have multiple separate modules interacting with each other. If a
module has grown large enough that this starts becoming a problem, it's
usually a sign that it's time to refactor the module into two (or more)
smaller ones.


> completely different semantics for a class vs a struct. Is it a
> reference?  Is it a value? Look up the entire declaration and have the
> entire Dlang manual open to find out.

class == by reference
struct == by value

Very straightforward.


> As far as I remember, no automatic RAII support, even though it's
> insanely useful. You have to manually write scope(end) stuff which
> means any person forgetting one is now leaking memory.

???  Structs with dtors have RAII. You only need scope(exit) if you're
manually managing resources.

What exactly are you referring to here?


> Writing output in a deconstuctor (for learning) works. But then you
> accidentally combine two strings inside it and the garbage collecter
> crashes without a stack trace.

Yeah, class dtors and GC don't mix, in general. There was a proposal to
remove class dtors from the language some years ago. But it didn't
happen, probably because more people complained about that than about
dtors not being allowed to allocate memory or access GC'd resources. :-D


> Documentation. Documentation. Documentation.
[...]

What exactly is wrong with the docs?  A concrete list of actionable
items would be nice. (I admit the docs could use some improvements,
btw.)


T

-- 
"I'm not childish; I'm just in touch with the child within!" - RL


More information about the Digitalmars-d-learn mailing list