bug in assigning to dynamic array element

ketmar via Digitalmars-d digitalmars-d at puremagic.com
Mon Nov 3 18:05:31 PST 2014


On Mon, 03 Nov 2014 09:50:26 -0500
Steven Schveighoffer via Digitalmars-d <digitalmars-d at puremagic.com>
wrote:

> There is a reason we get at least 1 question a week on how D arrays work.
and this is a clear sign that something is *very* wrong with them. i
fully understand the mechanics behind dynamic arrays, slicing and so
on. what i *can't* understand here is why compiler allowing me to shoot
my foot even without a warning.

compiler *knows* that this is dynamic array. it *knows* that assign is
impure (as saveIt() obviously not "pure" and it can't be). yet it
silently allows me do that. it's *very* error-prone code. it's easy for
compiler to reject such code (or at least warn me). but it choses to
carefully hide the possible bug.

i'm nat talking about "it must work as i expect!" here. what i'm
talking about is that D compiler allows potentialy unsafe and
error-prone code. it's ok for pointers, i'm walking in dangerous area
with pointers, but it's not ok when i using *built-in* *type*! it's
like "ahahaha, let's see how smart you are! i will not warn you about
problematic code (despite i can do that without big problems) and we'll
see how fast you'll find that gotcha!"

it's very funny to read discussions about safety and environment
variables here. they were boring before, but now i realised the
sarcasm, and they becomes very amusing.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 181 bytes
Desc: not available
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20141104/683b4b51/attachment.sig>


More information about the Digitalmars-d mailing list