bug in assigning to dynamic array element

ketmar via Digitalmars-d digitalmars-d at puremagic.com
Sun Nov 2 16:16:36 PST 2014


On Sun, 02 Nov 2014 09:25:54 -0800
Dan Olson via Digitalmars-d <digitalmars-d at puremagic.com> wrote:

> Like D, Java is LTR evaluation for assignment, and I think C# too.  A
> similar situation to OP code can be created in Java by reassigning an
> array reference in saveIt().
what i'm talking about is that implicit changing of .ptr is unsafe and
error-prone. i *NEVER* explicitly touched '.ptr' in my code, yet
somehow it affects me. good compiler should either do what programmer
obviously wants it to do (is there somebody who can say that he
desperately need the feature in the compiler where compiler modifies
stale copy of array data in such code? i doubt), or (and this will be
perfectly safe) simply forbid impure assigns for dynamic arrays.

what compiler does now is using it's type system to carefully hide
error-prone code. no, this is not "another task for lint". not
rejecting such code is "safe" in the terms of "program will not
segfault", but it's obviously not safe in terms of "correct code".

using built-in type system not to help me, but to cheat me is something
i never expected from D. but now i at least learnt that my "safety" and
D "safety" are completely different things. D "safety" is "no
segfaults, and let bad code slip in the cracks. and don't try to help
programmer, he is smart enough to track it all manually." nonsense with
non-uniform function attribures ("@" vs plain), desire to keep prefix
"const" as long as possible, strange requiring of utf-8 even in places
that aren't compiler deal (shebang), having "0x" and "0b", but ommiting
"0o", not allowing 'auto' in foreach... ah, alot of small bits. now
i'm starting to see a whole puzzle. it's all about my "safety" and D
"safety" are completely different things.

my bad, i chose a wrong language. i'll keep looking for the language
that tries to help me writing programs, not cheating me and then
blaming me.
-------------- 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/20141103/b0ad1695/attachment.sig>


More information about the Digitalmars-d mailing list