Copy Constructor DIP and implementation

Jonathan M Davis newsgroup.d at jmdavisprog.com
Mon Sep 24 23:22:13 UTC 2018


On Monday, September 24, 2018 3:20:28 PM MDT Manu via Digitalmars-d-announce 
wrote:
> copy-ctor is good, @implicit is also good... we want both. Even though
> copy-ctor is not strictly dependent on @implicit, allowing it will
> satisfy that there's not a breaking change, it it will also
> self-justify expansion of @implicit as intended without a separate and
> time-consuming fight, which is actually the true value of this DIP!

@implicit on copy constructors is outright bad. It would just be a source of
bugs. Every time that someone forgets to use it (which plenty of programmers
will forget, just like they forget to use @safe, pure, nothrow, etc.),
they're going to have a bug in their program. However, unlike, with
attributes like @safe or pure, they're not going to get a compiler error in
their program; they're going to get a logic error. They may or may not find
that bug quickly, but the compiler isn't going to point it out to them. And
if @implicit weren't a thing, then the problem wouldn't even exist.
@implicit is trying to get around breaking an extremely unlikely piece of
code which would be far better fixed by using a transitional compiler flag
and which adds _no_ value for copy constructors in the long run.

Even if we do later add @implicit to the language for regular constructors,
it has no business on copy constructors. And its value on other constructors
needs to be evaluated and examined on its own separately from the issue of
copy constructors. We should not be letting @implicit be put onto copy
constructors just to get it into the language. If it's such a valuable
feature on regular constructors, it should be able to get in on a separate
DIP specifically for that purpose without piggybacking in on the copy
constructor DIP - especially when it's clearly going to be a source of bugs
if it's required to be on copy constructors. And it just needlessly adds to
the attribute soup. At least if it were added for regular constructors, it
would be adding value. For copy constructors, it's just adding annoyance and
the risk of bugs.

- Jonathan M Davis





More information about the Digitalmars-d-announce mailing list