double -> double[]... | feature or bug?

spir denis.spir at gmail.com
Thu Dec 23 03:34:17 PST 2010


On Thu, 23 Dec 2010 00:34:41 -0600
Christopher Nicholson-Sauls <ibisbasenji at gmail.com> wrote:

> On 12/22/10 15:06, Andrej Mitrovic wrote:
> > Oooh. That cought me off guard, sorry.
> > 
> > Thanks Steve.
> > 
> 
> I'll concede that the syntax can be odd at first, but it also enables
> some interesting things.  For example, this works:
> 
> class Foo {
>     this (int i, double f) { /*...*/ }
>     /*...*/
> }
> 
> void someFunc ( Foo foo ... ) { /*...*/ }
> 
> someFunc( 5, 3.14 );
> 
> Basically, given a class (and I think struct's work as well) as the
> variadic type, it will accept either an instance of said class, or any
> combination of values which can be mapped to a constructor of that
> class.  It can be convenient sometimes.

While I understand some may consider this a nice feature, for me this is an enormous bug. A great way toward code obfuscation. I like D among other reasons because it's rather clear compared to other languages of the family. There should be no automagic constructor call (at least in this case, when the type is not even mentionned on the caller side).
This may even lead to very naughty bugs. And what if Foo has subtypes, and the one actually invoked is the one intended by the user?

Denis
-- -- -- -- -- -- --
vit esse estrany ☣

spir.wikidot.com



More information about the Digitalmars-d-learn mailing list