Redundant nargin checking in m-files?

Previous Topic Next Topic
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

Redundant nargin checking in m-files?


I happened to be looking at listfonts.m which starts with

function fonts = listfonts (h)

  if (nargin > 1)
    print_usage ();

This is an established input validation strategy to first check the number of arguments, and then look for correct type, and finally check for correct value.

But when I call listfonts with too many arguments I now get

octave:3> listfonts (1,2)
error: listfonts: function called with too many inputs
error: called from

I remember vaguely that you made a change to the parser/interpreter and that it now checks for too many inputs.  Does that make all of the input number checking in m-files redundant at this point?

On the bad side, it will be a lot of work to remove the unnecessary code.  But on the good side, the code will be streamlined and slightly faster since the nargin check is happening in compiled code rather than interpreted code.