Input validation in old-style @classes

I’m reviewing the @audioplayer and @audiorecorder classes and I believe the input validation can be simplified. Here is the complete function file for @audiorecorder/isrecording.m

function tf = isrecording (recorder)

  if (nargin != 1)
    print_usage ();
  endif

  tf = __recorder_isrecording__ (struct (recorder).recorder);

endfunction

My question is whether the nargin check is required. When I am at a command prompt the function isrecording is not visible. It only becomes visible when I use isrecording (recorder_obj). All of these old-style classes require a class object as the first input and so it seems unnecessary to make the check that there is at least one input.

@jwe: Is this correct about the way old-style classes work?

Yes, when class methods are called, the first argument will be the class object. And now that the interpreter automatically checks for too many arguments, I agree that the check shown in your isrecording example is not needed.

As a follow up, I removed other instances of unnecessary checking for at least 1 argument in old-style @class functions in this changeset: http://hg.savannah.gnu.org/hgweb/octave/rev/78c3dcadf130.

1 Like