Removing nargin & nargout checks

The News file for Octave 7 says that because the interpreter automatically checks for the number of inputs and outputs for functions, manually checking nargin and calling print_usage for many cases is unnecessary and can be deleted.

I am going through the scripts directory with “grep -Riw -A2 nargin scripts”, and removing the nargin/print_usage pattern for files where it seems safe (meaning no use of default arguments, no use of varargin, and no use of nargin to construct non-obvious default arguments). I am not touching other users of nargin (actions other than print_usage()).

I would like feedback on whether this removal of code is of interest for the 7.1 release. If it is, I would like your thoughts on how to break it up, whether to submit one big patch at the end of the process, or lots of small patches for every few directories.

IIUC, @rik already went through the code base and removed nargin checks that are no longer necessary.
See this changeset:
octave: 28de41192f3c (gnu.org)

Agreed. I acknowledge Rik removed a lot but I still see many uses of the pattern scattered throughout, like in ctime.m, etime.m, eomday.m and several more. From grep counts, there are probably a few hundred files like that which are safe to remove. Should they be removed?

Edit: previous Discourse thread here from @rik

The test in ctime needs to stay. The interpreter can only check if a function was called with more arguments than expected. It can’t know if a function supports being called with less arguments.

I haven’t looked at the other functions. But I suspect that they use a similar pattern.

That simplifies the search task a bit. I think etime, eomday, addtodate etc all use a check that is no longer needed.

If a function needs one argument and is called with zero, what happens? Will the interpreter call print_usage? EDIT: I see that it didn’t call print_usage but directly gave an undefined variable error.

EDIT: I see that @rik removed cases where “nargin > foo”. The cases remaining with “nargin < foo” by your answer probably need to stay, and so do all the cases with varargin or default arguments. The only cases unclear to me are the ones with “nargin != foo”.

As you have now discovered, the interpreter only checks for calling a function where the number of arguments exceeds the number of inputs specified in the function prototype. There is no method, currently, to indicate to the interpreter the minimum number of arguments that are required so that is why the nargin > XXX tests are still used. The pattern nargin != XXX is used when there is only one way to call the function. For example,

z = function myfunc (x, y)

If both arguments are required one could write

if (nargin < 1)
   print_usage ();
endif

but it is clearer to use the != formulation.