[Issue 13670] bug in assigning to dynamic array element

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Sun Nov 2 01:32:45 PST 2014


https://issues.dlang.org/show_bug.cgi?id=13670

--- Comment #6 from Ketmar Dark <ketmar at ketmar.no-ip.org> ---
i'm not looking for perfection, i'm looking merely for sanity. dynamic arrays
should either work as static arrays, or not looking like static arrays. or
compiler at least must to reject such code, as this code is obviously
meaningless.

i'm accepting alot of things in D. while i can argue that "@safe" and "nothrow"
is nonsence too (do either "@safe" and "@nothrow", or "safe" and "nothrow"), or
that prefix "const" in function declaration should be forbidden, that doesn't
makes me to throw D away. it's the things i can live with, albeit not very
happy. ;-)

but this case is completely different. compiler behavior clearly violates the
principle of least astonishment here. what it does is absolutely insane.
really, no sane person would want this code to modify the stale copy of the
array! and this is easily fixable — just postpone .ptr loading.

why, in heaven's sake, somebody will want the current behavior? it's useless.
it's fixable. fixing it doesn't need to change evaluation order rules. what fix
will make is just "sanification".

ok, if such fix is completely unacceptable, i can live with that too. but
*only* if compiler will reject such code. this code is heavily error-prone. if
list was a static array, and then was changed to dynamic one… everything will
compile as before, but misteriously failing in production. and not with
segfault, which is at least traceable, but with processing of invalid values.

this is what i can't call "safe". this is not just unsafe, this is completely
undetectable without manual code checking! so compiler not only avoids using
it's type checking system to help me write better code, it carefully protecting
my invalid code with it! that is what i can't accept.

dynamic arrays are built-in type. compiler is perfectly able to generate error
on the code like this which can cause side effects. just forbid it and insist
on "pure" assigns for dynamic arrays. i bet such change will uncover some
hidden problematic code in people's codebases (and maybe even in runtime/phobos
too).

but doing nothing with that just makes the language unsafe for no reason. and
if i have to use unsafe language anyway, i'd better go with C++. C++ has alot
of code written, it has no problems interfacing both C and C++ code, and it's
quirks are well-known.

i can live with things i don't like in D, but i can't live with features that
not only hides problematic code, but tries to do their best to not tell me that
i may doing something wrong. i'd better abandon such a language before i get a
significant codebase written with it.

i will really miss D great metaprogramming abilities and it's great template
system. but i don't want to use the language that tries to cheat me without
even warning. we already have such languages, having one more is pointless.

and this really hurts me, 'cause i love D with passion, this is the only
language (in it's class) that makes me feel like it cooperates with me to help
me achieve my needs. maybe i'm overreacting, but i feel this like a betrayal
from an old trusted friend. it hurts.

--


More information about the Digitalmars-d-bugs mailing list