octave-maintainers
[Top][All Lists]
Advanced

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

Re: default parameter values


From: David Bateman
Subject: Re: default parameter values
Date: Tue, 25 Mar 2008 21:36:22 +0100
User-agent: Thunderbird 2.0.0.12 (X11/20080306)

John W. Eaton wrote:
> Looking at the new contrast function, it could also be written like
> this:
> 
>   function map = contrast (x, n = rows (colormap ()))
> 
>     if (nargin == 1 || nargin == 2)
>       if (! isscalar (n))
>       error ("contrast: n must be a scalar");
>       endif
> 
>       [... code to do real work ...]
> 
>     else
>       print_usage ();
>     endif
> 
>   endfunction
> 
> I had to fix a small bug that was preventing the function call in the
> initializer from working correctly, but assuming that works, what do
> people think about using this style when possible?  Note that nargin
> still refers to the number of arguments supplied when the function is
> called, but the parameter N is always defined, either by the caller or
> from the initializer experession.
> 
> I'd like to know whether people think that using this style would be
> an improvement (and so we should encourage it), or whether it would be
> a possible source of confusion and we should avoid it (and perhaps
> remove the feature from Octave given the possibility of future
> compatibility issues).

I kind of like this syntax and think it simplifies the code, but yes if
mathworks decides they want to do something similar it might cause us
some pain in the future.. Perhaps keep feature, and suggest it as a
means of initializing parameters, but don't enforce it or change
existing code.

D.


reply via email to

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