Old problem with performance
Tom S
h3r3tic at remove.mat.uni.torun.pl
Thu Feb 12 17:41:07 PST 2009
Rainer Deyke wrote:
> Because unintentional object aliasing a problem orders of magnitude more
> common than unintentional object slicing, and at least an order of
> magnitude harder to detect and fix.
>
> Because you can't correctly duplicate a multi-dimensional dynamic array
> in D by using the built-in 'dup' property.
Simply because shallow copies are the default. Usually you can't even
have automatic deep copies. What if the array was supposed to be
malloc'd or put in a contiguous memory block taken from a memory cache?
A .dup that made a deep copy of it would introduce even a larger problem
(since it would seem correct) than remembering that dups/struct copies
are shallow by default and you need special code to do otherwise.
> Because having two syntactically similar ways of creating user-defined
> types with different features sets and different semantics is confusing,
> especially if you later decide that you need a struct to be a class and
> all your copies turn into reference or vice versa.
> [snip]
> Would it remove the need for both classes and structs in the language,
It's not a bug, it's a feature.
What if I decide that I want my int to be a float? Suddenly I have to
add all those NaN checks, change my scanf calls, inspect all divisions
and places where rounding might happen, not to mention any inline asm or
binary shifts... Let's unify floats and ints so this cannot happen.
--
Tomasz Stachowiak
http://h3.team0xf.com/
h3/h3r3tic on #D freenode
More information about the Digitalmars-d
mailing list