On 11/21/2010 9:23 AM, Tomek Sowiński wrote:
Tyro[a.c.edwards] <nos...@home.com> napisał(a):

What would be the harm if upon seeing your code the compiler did this:
char[] chars = "abc".dup;
char[] backdoor = chars;
string s = chars.idup;
assert (s == "abc");
backdoor.front = 'k'; // [1]
assert (s == "abc");
Slightly magical but works according to expectation. I don't see the
problem.
[1] Assuming your are using std.array, this would fail because
backdoor.front is not an lvalue.

The harm is confusion. Now = on arrays always means aliasing, but with
your proposal, it may *sometimes* mean dupping. Imagine real-life code
with type aliasing and type inference in play, and trying to determine
whether some line makes a dupping string<->char[] conversion or not.

alias char[] firstClassString;
alias firstClassString stringGold;
alias stringGold lightAtEndOfTunnel;
alias lightAtEndOfTunnel daBomb;
alias daBomb iAmThe;

iAmThe man;

if I want to know the actual type of shiznit:

writeln(typeid(man)); // outputs char[]

What would be the harm if everyone just put .(i)dup where it belongs?


Actually, I don't see any harm in using .(i)dup. However, my limited experience does not allow me to think on the same level as you so I'm just trying to understand your point a little better. That being said, I still don't understand the gravity of the implied problem.

Reply via email to