Re: Variables in for loop (style issue)
Anders J. Munch wrote:
Andrei Alexandrescu (See Website For Email) wrote:
So absent such a concept, D is forced to copy data around _more_, o to
expose itself to _more bugs_.
If you duplicate your C++ designs line by line, that might be true. But
in a language with garbage collection and object references, cleaner
designs using fully-immutable value objects become feasible.
instances that just happen to retain the same value. Objects tend to be
passed around much more frequently than they are modified, making this
an attractive trade-off.
Can you back that claim up with anything?
D has less need for the const/non-const distinction than C++ because
fully-immutable objects are more efficient.
That certainly depend on the object. It's not feasible, for example,
to have an immutable container, say, like std::vector<T>. In C++
it's OK to say
struct Foo
{
const std::vector<int>& bar() const;
};
In Java, C# and D you can't do it without breaking encapsulation or
without copying the entire collection before returning a handle.
Pick your poison.
-Thorsten
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]