Topic: Default argument, simple naive question.


Author: tob@world.std.com (Tom O Breton)
Date: Tue, 19 Jul 1994 04:48:39 GMT
Raw View
ldh@cs.brown.edu (Laurent Hasson) writes:
>   BOOL TruthTeller(Prop* p, int Level=10, int Efficiency=100);
>       [...]
>     TruthTeller(P1,10,y);
>       [...]
>
> the problem is that in the first call, i have to remember the default
> value '10'! Wouldn't it be easier, and harmless, to do:
>
>     TruthTeller(P1,,y);

Yes. And beyond that, it would be easier, convenient, and a significant
help to some programs readability to have named arguments, EG:

        TruthTeller(P1, Efficiency:y );

It has been proposed here more than once. I am told there are no plans
to ever include it in the ANSI C++ standard. Don't ask me to defend this
decision -- I'm biting my toungue to not rag it down. I would have made
the opposite choice.

        Tom

--
finger me for how Tehomega is coming along (at tob@world.std.com)
Author of The Burning Tower (from TomBreton@delphi.com) (weekly in
rec.games.frp.archives)





Author: ldh@cs.brown.edu (Laurent Hasson)
Date: Tue, 19 Jul 1994 14:05:48 GMT
Raw View

Is there some "logical" reason for it not to be considered seriously?

Laurent.




Author: pete@genghis.interbase.borland.com (Pete Becker)
Date: Tue, 19 Jul 1994 15:14:47 GMT
Raw View
In article <LDH.94Jul19090548@cslab1g.cs.brown.edu>,
Laurent Hasson <ldh@cs.brown.edu> wrote:
>
>
>Is there some "logical" reason for it not to be considered seriously?
>
>Laurent.

 No, there is no "logical" reason for it not to be considered seriously.
In fact it has been considered seriously, and rejected.
 -- Pete





Author: tmwitmer@steven.b15.ingr.com (Thomas M. Witmer)
Date: 19 Jul 1994 12:49:48 -0500
Raw View
ldh@cs.brown.edu (Laurent Hasson) writes:


>Let's say i have the following function:
>  BOOL TruthTeller(Prop* p, int Level=10, int Efficiency=100);

>My truth teller function needs 2 parameters and i do about 1/4 of
>each call:
>    TruthTeller(P1,10,y);
>    TruthTeller(P2,x);
>    TruthTeller(P3,x,y);
>    TruthTeller(P4);

>the problem is that in the first call, i have to remember the default
>value '10'! Wouldn't it be easier, and harmless, to do:

>    TruthTeller(P1,,y);

   Personally, I don't think so. It looks too much like a typo to me. Someone
else maintaining your code might try to "fix" it.

   A couple of options:

1. Use a #define or const for 10, as in "#define DEFAULT_TRUTH_LEVEL 10".
   That way you don't have actual numbers in your code. (Good to avoid anyway!)

2. I don't suppose switching "level" and "efficiency" would help any? ;-)

3. Reanalyze what you're doing to see if there isn't a better or simpler way.
   (Not a flame. But sometimes rethinking a "solved" problem leads you to a
    better way.)

 - Tom

--
         |Tom Witmer             |Check all that apply:    |
         |tmwitmer@ingr.com      | (X) D*mned if you do    |
         |Intergraph Corporation | (X) D*mned if you don't |




Author: tob@world.std.com (Tom O Breton)
Date: Tue, 19 Jul 1994 20:40:39 GMT
Raw View
ldh@cs.brown.edu (Laurent Hasson) writes:
> Is there some "logical" reason for [named arguments] not to be
> considered seriously?

I'm just telling you what they decided, I'm not defending the decision.

        Tom

--
finger me for how Tehomega is coming along (at tob@world.std.com)
Author of The Burning Tower (from TomBreton@delphi.com) (weekly in
rec.games.frp.archives)





Author: ldh@cs.brown.edu (Laurent Hasson)
Date: Mon, 18 Jul 1994 17:58:20 GMT
Raw View

Let's say i have the following function:
  BOOL TruthTeller(Prop* p, int Level=10, int Efficiency=100);

My truth teller function needs 2 parameters and i do about 1/4 of
each call:
    TruthTeller(P1,10,y);
    TruthTeller(P2,x);
    TruthTeller(P3,x,y);
    TruthTeller(P4);

the problem is that in the first call, i have to remember the default
value '10'! Wouldn't it be easier, and harmless, to do:

    TruthTeller(P1,,y);


Laurent.