On Sat, 20 Nov 2010 21:21:58 +0100 Tomek Sowiński <j...@ask.me> wrote:
> Dnia 20-11-2010 o 17:09:00 spir <denis.s...@gmail.com> napisał(a): > > >> It's busting the whole const system to smithereens. > >> > >> char[] chars = "abc"; > >> char[] backdoor = chars; > >> string s = chars; > >> assert (s == "abc"); > >> backdoor.front = 'k'; > >> assert (s == "abc"); // fails. not so immutable, huh? > > ??? > > backdoor and s do not denote the same element. One is a mutable array, > > the other is immutable. Why should changing backdoor affect s? Whether > > backdoor and chars denote the same array depends on whether "=" copies > > or not dyn arrays. But from immutable string to mutable array, there > > must be a copy (read: dup). > > OK, I get it. I still like it the way it is. Having worked with C++ code > with overloaded assignment ops and implicit conversions, I see = that > sometimes dups and sometimes aliases as a source of confusion and > performance bugs. All this just to remove .idup (it's 5 chars!). > Yes, you may be right on this ("explicit is better than implicit", as python folks say). Denis -- -- -- -- -- -- -- vit esse estrany ☣ spir.wikidot.com