Style for checking that one input to a function is necessary

Consider the following function prototype

function output1 = func_name (input1)

If the function must be called with one input (there is no default) then we have a variety of input validation styles. I have seen

if (nargin == 0)
  print_usage ();
endif

OR

if (nargin < 1)
  print_usage ();
endif

OR

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

I’d like to consolidate the core m-files to use a single style. Does anybody have a preference for one of the three styles and any reasoning behind it?

I prefer the middle one because it references the number of arguments that are required (1) and because it would be consistent with functions which require a minimum number of arguments where that number is greater than 1. For example, `

if (nargin < 3)
  print_usage ();
endif

for a function which requires three (3) arguments.

Fully agree with that!

1 Like

Okay, I went with nargin < 1 style in this changeset: https://hg.savannah.gnu.org/hgweb/octave/rev/de5f2f9a64ff.

Thanks for the great effort :slightly_smiling_face: :+1: