octave-maintainers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Default arguments


From: John W. Eaton
Subject: Re: Default arguments
Date: Fri, 15 Dec 2006 11:28:23 -0500

On 15-Dec-2006, Andreas Romeyke wrote:

| Sure. But default arguments will  be crap. There is no real reason to
| use them I think. It is mostly a sign of smelling code and bad
| interface design.

Please, tell us how you really feel.

In any case, Matlab is full of this kind of thing, and since Octave
implicitly aims to be compatible, it is also full of "crap".  It may
surprise you, but people really want compatibility; it seems to be one
of Octave's most cherished features.

|In your example you deny compiler hints, because if
| you unintentional call foo() without arguments.
| 
| Do you have a good example where defaults really useful?

Yes, default arguments are necessary to implement many functions found
in Matlab, therefore they are useful to have in Octave.  As I said,
you can already implement default argument values by looking at
nargin, but I think the new syntax makes it clearer.  I know I would
prefer to read

  function foo (x, y, z = 13)
    ...

instead of

   function foo (x, y, z)
     if (nargin < 3)
       z = 13;
     endif
     ...

| - From a functional point of view the right way to rewrite your example
| above is:

Although I suppose there are some elements of functional programming
in the "Matlab language" (or whatever it is called), I don't think it
has any delusions about trying to be a pure and beautiful functional
language, so if you are looking for that, I think you've come to the
wrong place.

| function foo(arg)
| ...
| 
| function bar()
|     foo(42)
| ...
| 
| This avoids complexity too,

Really?  It seems to me it trades the complexity of default arguments
for a larger set of functions in the library, which itself is an
increase in complexity.

| Therefore I would say, if anyone use defaults it should be punished by
| extra code lines. :)

Why?  It seems to me that default arguments can make things more
concise.  So are you saying we should be punished for being concise?

Anyway, if you want to complain about the design of the "Matlab
language", maybe you should complain to the MathWorks?

jwe


reply via email to

[Prev in Thread] Current Thread [Next in Thread]