About structs and performant handling
deadalnix
deadalnix at gmail.com
Sun Mar 10 12:03:53 PDT 2013
On Saturday, 9 March 2013 at 20:19:10 UTC, Namespace wrote:
> So I like to suggest a new syntax for this behaviour.
> If you want that your function/method/whatever takes a struct
> as well as rvalue and lvalue, you declare this parameter with a
> '&' (Or whatever, the syntax doesn't matter at all. I like the
> '&' because I know it from C++ and many (C++) Newcomer will
> know what it means. Furthermore '&' is a lot shorter than eg.
> 'auto ref').
I don't think this is a good idea for several reasons.
First, it introduce a new syntax, which is always a concern. It
add language complexity, and it likely to not be used everywhere
it should.
Second, the default behavior must be the most beneficial one.
Simply because it will be the most used, and we don't want good
code to be crippled with many addition here and there. Providing
a default suboptimal behavior (here performancewise).
Finally, I think this behavior is very dangerous. Pass by
reference and value have very different. With that construct,
you'll never know which one you get as the compiler decide ! If
the compiler and not the programmer decide what the program does
(not implementation wise, but semantically), we have a problem.
More information about the Digitalmars-d
mailing list