December 23, 2010
On Thu, 23 Dec 2010 12:34:45 -0500, Don <nospam@nospam.com> wrote:

> bearophile wrote:
>> spir:
>>
>>> 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.
>>  The main problem here is that I have never felt the need of that feature, so for me it's useless. Has Walter added it after a good number of people have asked for this feature? Has any one here needed it?
>>  Bye,
>> bearophile
>
> I'm almost certain that the behaviour is not intentional.

From http://www.digitalmars.com/d/2.0/function.html :

"Typesafe variadic functions are used when the variable argument portion of the arguments are used to construct an array >>>> or class object <<<<."

(emphasis added)

And it goes on to show a similar example as to what has been discussed here.

I think it's intentional, and I agree that I've never used or thought "gee, I wish D did this".  I wouldn't be sorry to see it go.  In fact, I'd advocate for getting rid of it.  It creates a hidden allocation, which I'm very much against.

-Steve
December 23, 2010
On Thu, 23 Dec 2010 13:38:30 -0500
"Steven Schveighoffer" <schveiguy@yahoo.com> wrote:

> I think it's intentional, and I agree that I've never used or thought "gee, I wish D did this".  I wouldn't be sorry to see it go.  In fact, I'd advocate for getting rid of it.  It creates a hidden allocation, which I'm very much against.

Agreed. Not only hidden allocation, but the "feature" may be unintentionally used, leading to hard-to-find bugs. There should never by (user) type instanciation without explicite mention of the type (if only on the left side of an assignment). Surprise --> bugs.

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

spir.wikidot.com

December 23, 2010
On Thu, 23 Dec 2010 14:51:02 -0500, spir <denis.spir@gmail.com> wrote:

> On Thu, 23 Dec 2010 13:38:30 -0500
> "Steven Schveighoffer" <schveiguy@yahoo.com> wrote:
>
>> I think it's intentional, and I agree that I've never used or thought
>> "gee, I wish D did this".  I wouldn't be sorry to see it go.  In fact, I'd
>> advocate for getting rid of it.  It creates a hidden allocation, which I'm
>> very much against.
>
> Agreed. Not only hidden allocation, but the "feature" may be unintentionally used, leading to hard-to-find bugs. There should never by (user) type instanciation without explicite mention of the type (if only on the left side of an assignment). Surprise --> bugs.

To drive the point home, we can examine the problem that typesafe variadic args solves.  Take an array example.  If we didn't have typesafe variadic args for arrays, this code:

void foo(int[] args...);

foo(1, 2, 3);

would become:

void foo(int[] args);

int[3] x;
x[0] = 1;
x[1] = 2;
x[2] = 3;
foo(x[]);

Not so nice.  Almost the same issue for a typesafe variadic with fixed-sized arrays.

Now, let's look at the same thing for a class:

class C
{
   this(int i, string s);
}

void foo(C arg...);

foo(1, "hi");

And the code without typesafe variadics:

void foo(C arg);

foo(new C(1, "hi"));

Not a lot different, we have just basically shown that you are doing an allocation (which is a good thing to show).

Going even further, we can even do this:

void foo(int i, string s)
{
  foo(new C(i, s));
}

And then we get *exactly* the same api.  This feature brings absolutely nothing to the table IMO.

-Steve
December 24, 2010
Steven Schveighoffer:

> This feature brings absolutely nothing to the table IMO.

Added as issue 5368.

Bye,
bearophile
1 2
Next ›   Last »