Blog post: What D got wrong

Jonathan M Davis newsgroup.d at jmdavisprog.com
Wed Dec 19 01:53:02 UTC 2018


On Tuesday, December 18, 2018 6:35:34 AM MST Pjotr Prins via Digitalmars-d-
announce wrote:
> On Tuesday, 18 December 2018 at 11:25:17 UTC, Jonathan M Davis
>
> wrote:
> > Of course, even if we _did_ have a solution for reversing
> > attributes, slapping an attribute on the top of the module
> > would still potentially be a maintenance problem, because it's
> > then really easy to miss that an attribute is in effect (it's a
> > problem that we've had on several occasions with druntime and
> > Phobos in the few cases where attributes are mass-applied). So,
> > there is no silver bullet here (though regardless of whether
> > mass-applying attributes is something that should ever be
> > considered good practice, we really should add a way to be able
> > to reverse them).
>
> Thanks Jonathan for your elaborate explanation. I personally have
> no problem with the attributes which - in practice - means I
> don't use them much unless I want to make sure something is nogc,
> for example. For library designers it makes sense to be explicit.
> I guess that is where the trade-off kicks in. Maybe it is just a
> feature. We argue against specifying them because other languages
> are not as explicit. It does add a little noise.

In practice, library developers are forced to worry about it more, because
it affects everyone using their code, whereas within a program, how valuable
it is to worry about them depends on the size of the program and what you
expect to get out of them. Very large programs can definitely benefit
(especially with @safe and pure), because it reduces how much code you have
to worry about when tracking down the problems that those attributes
address, but with small programs, the benefit is far more debatable. And for
simple scripts and the like, they're almost certainly a waste of time -
which is part of why more restrictive attributes are not the default. It's
supposed to be easy to write code that doesn't deal with attributes if you
don't want to, but they're there for those who do care. The problem of
course is that when you do care, they tend to become a bit of a pain.

I confess that I do tend to think about things from the standpoint of a
library designer though, in part because I work on stuff like Phobos, but
also because I tend to break up my programs into libraries as much as
reasonably possible. In general, the more that's in a reusable, easily
testable library the better. And with that approach, a lot less of the code
for your programs is actually in the program itself, and the attributes tend
to matter that much more.

- Jonathan M Davis





More information about the Digitalmars-d-announce mailing list