octave-maintainers
[Top][All Lists]
Advanced

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

Re: Default arguments


From: Andreas Romeyke
Subject: Re: Default arguments
Date: Fri, 15 Dec 2006 14:30:43 +0100
User-agent: Icedove 1.5.0.8 (X11/20061116)

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi,

Søren Hauberg wrote:
>> Do you have a good example where defaults really useful?
> In the "imshow" function your can specify a viewing range (i.e.
> tell the function that a pixel value of 0 equals to black, and 100
> equals white).
>
> The default is to let 0 equal black, and 255 white, but at times
> you want to change this. If "imshow" didn't have default arguments,
> I would have to write imshow(im, [0, 255]) a lot of times, which
> would make me go insane (some might argue, that it's too late...).
> Since imshow supports default arguments I just write imshow(im)
> which is a lot easier to read (IMHO).
>
I disagree. The right way should be to use a specialized function.

Use "imshow_fullrange(im)" which calls "imshow(im, [0,255])". This
does not hide information. Remember that code is written once, but
read many times. It also makes it easier to change projects, if your
data-range is changed.

For example if imshow() or a caller function will support HDR-pictures
in the near future. It is easier to adopt "imshow_fullrange()" spread
to HDR as to break "imshow()" of your example, because some functions
will call it in HDR- and other in normal  semantics.

Bye Andreas

- --
Software Developer / Dipl. Inform. (FH)
Max Planck Institute for Human Cognitive and Brain Sciences
Department of Psychology
Stephanstr. 1a, 04103 Leipzig, Germany

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.5 (GNU/Linux)

iD8DBQFFgqOCGBhgJGthyeERAkndAKCQymQdnkQ9TuWTv+n169vD2NzxSQCfRbGb
LegfKe3eQhr2waJzCeT2yTg=
=slK5
-----END PGP SIGNATURE-----



reply via email to

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