May 29, 2002
Walter,

Even though I'm the last fan of C#, I do think its params implementation is good. Would the performance be prohibitive? Do you have any figures/impressions as to how much it would cost?

"Walter" <walter@digitalmars.com> wrote in message news:ad0uv7$cbc$1@digitaldaemon.com...
>
> "cblack01" <cblack01@cox.net> wrote in message news:ad0rbq$88q$1@digitaldaemon.com...
> > A quick question.  I like C#'s implementation of reflection. Does D do reflection?
>
> Only partially, via the .classinfo property.
>
> > Also, Does D do variable parameters?  C# has a good convention for
> variable
> > parameters using the params keyword like this:
> >
> > void Print(params string stuffToPrint[])
> > {
> >     foreach(oneThing in stuffToPrint) System.Console.WriteLn(oneThing);
> > }
> >
> > Then you would call it like this:
> >
> > Print("Printing ", "variable ", "parameters");
>
> D does variable parameter lists exactly like C does. While not typesafe,
it
> is efficient.
>
>


May 29, 2002
Agree that this is a good policy. Now, if only we can get mandatory braces ... ;)

"Walter" <walter@digitalmars.com> wrote in message news:ad0tkb$as8$1@digitaldaemon.com...
>
> "Sean L. Palmer" <seanpalmer@earthlink.net> wrote in message news:acurhn$foq$1@digitaldaemon.com...
> > In debug build I got a "switch default" runtime error!
> > Is this true, that you *must* provide a default case, and that a switch
> > without a matching case is an error?
>
> Correct.
>
> >  I dislike the idea of having to
> > provide an explicit default which does nothing, but there may be other
> > reasons for this (safety I guess)
>
> The reason for it is all the bugs I've had over the years where I add another value to something, and forget to add a case for it in a corresponding switch somewhere in the code. It means one must be explicit about ignoring the default case.
>
> > Lotta little things to get used to in D.  ;)
>
> Yup <g>. D doesn't have one killer feature, it is more the aggregate of a lot of little things.
>
>


May 29, 2002
Surely the cost of writing some code is inconsequential c/w the effort of diagnosing bugs and/or maintaining & updating code? Or have I missed something fundamental in all these years ... ? ;)

"anderson" <anderson@firestar.com.au> wrote in message news:acv659$tb5$1@digitaldaemon.com...
>
>
> "Pavel Minayev" <evilone@omen.ru> wrote in message news:acuuif$kq6$1@digitaldaemon.com...
> > "Carlos" <carlos8294@msn.com> wrote in message news:acurl4$g05$1@digitaldaemon.com...
>
> <Snip>
>
> > And besides, is a single "default:" at the end of case so hard to type?
>
> 1. The less code often makes things quicker to read (compare reading point
> for to an essay).
> 2. Allowing optional components don't make things much more difficult.
> 3. If you can shave 10% of typing in a program, that's 10% more time to
> spend elsewhere.
>
> I agree that a language needs to be strongly typed, but something like not using "default:" isn't going to cause that many more errors.
>
>


May 29, 2002
"anderson" <anderson@firestar.com.au> wrote in message news:ad035g$2960$1@digitaldaemon.com...

> PS - I wonder if they had the same arguments when inventing A,B,C, C++ and C#?

Oh yes, of course. Just remember that #%$@ C# rule that each case-block must be terminated...


May 29, 2002
"Matthew Wilson" <mwilson@nextgengaming.com> wrote in message news:ad1mcg$2bir$1@digitaldaemon.com...

> Walter,
>
> Even though I'm the last fan of C#, I do think its params implementation
is
> good. Would the performance be prohibitive? Do you have any figures/impressions as to how much it would cost?

After all, both ways could be left, old C-style for printf (and whoever cares of perfomance can always use it), and something new, safe and easy to use.


May 29, 2002
"Pavel Minayev" <evilone@omen.ru> wrote in message news:ad1qrq$2hau$1@digitaldaemon.com...
> "Matthew Wilson" <mwilson@nextgengaming.com> wrote in message news:ad1mcg$2bir$1@digitaldaemon.com...
>
> > Walter,
> >
> > Even though I'm the last fan of C#, I do think its params implementation
> > is
> > good. Would the performance be prohibitive? Do you have any
> > figures/impressions as to how much it would cost?
>
> After all, both ways could be left, old C-style for printf (and whoever cares of perfomance can always use it), and something new, safe and easy to use.
>

...at which point, I have to mention my favorite design again.  :-)

    void takes_variable_args(int... args)
    {
    }

This function takes a variable number of arguments, all of type int.  The variable "args" really has the type "int[] args" (just as, in C, a function parameter declared with [] really has type "pointer to...").  The "..." variation indicates that, when the caller codes separate function parameters, they are collected for the user into a dynamic array.

    class ArgType
    {
        this(char[] var) { }
        this(int var) { }
    }

    void mixed_types(ArgType... args)
    {
    }

The arguments are collected into a dynamic array "ArgType[] args" where ArgType is some user-defined class.  The arguments given must be of the parameter type; else a derived type; else an instance of the parameter type must be constructible using the given expression; else it's an error.

So when the user writes this:

    ArgType myVar;
    mixed_types(myVar, 1, "string");

...this would compile *as if* the user had coded:

    ArgType[] _temp_;
    _temp_.length = 3;
    _temp_[0] = myVar;
    _temp_[1] = new ArgType(1);
    _temp_[2] = new ArgType("string");
    mixed_types(_temp_);

--
Richard Krehbiel, Arlington, VA, USA
rich@kastle.com (work) or krehbiel3@comcast.net  (personal)



May 29, 2002
"Pavel Minayev" <evilone@omen.ru> wrote in news:ad1qrq$2hau$1@digitaldaemon.com:

> "Matthew Wilson" <mwilson@nextgengaming.com> wrote in message news:ad1mcg$2bir$1@digitaldaemon.com...
> 
>> Walter,
>>
>> Even though I'm the last fan of C#, I do think its params implementation
> is
>> good. Would the performance be prohibitive? Do you have any figures/impressions as to how much it would cost?
> 
> After all, both ways could be left, old C-style for printf (and whoever cares of perfomance can always use it), and something new, safe and easy to use.

extern(C) functions could use to old way.

There is already a typeInfo class for a lot of types.
Why not automatically push the number of parameters and
then push pairs of TypeInfo references and values?  It would
nice to have a replacement for the va* macros too.

void func(vararg,...)
{
  for(int i = 0; i < vararg.length; ++i)
  {
    TypeInfo t = vararg.GetType(i);
    void* pv = vararg.getValue(i);

  }
}

May 29, 2002
"Patrick Down" <pat@codemoon.com> wrote in message news:Xns921D6A359FF5Apatcodemooncom@63.105.9.61...

> > After all, both ways could be left, old C-style for printf (and whoever cares of perfomance can always use it), and something new, safe and easy to use.
>
> extern(C) functions could use to old way.

I thought about this as well. It seems like the best approach. "..." is already known to C/C++ programmers to indicate vararg function, why break the tradition?



May 29, 2002
"Matthew Wilson" <mwilson@nextgengaming.com> wrote in message news:ad1mcg$2bir$1@digitaldaemon.com...
> Walter,
>
> Even though I'm the last fan of C#, I do think its params implementation
is
> good. Would the performance be prohibitive? Do you have any figures/impressions as to how much it would cost?

The proper way to do it would be to create a variant type, and then have variable parameter lists be passed as arrays of variants.


May 30, 2002
"Walter" <walter@digitalmars.com> wrote in message news:ad3pg0$2hgm$1@digitaldaemon.com...

> The proper way to do it would be to create a variant type, and then have variable parameter lists be passed as arrays of variants.

So, what about variants?