Let's say a code-golf challenge is asking for a program without arguments or function without parameters. Are we allowed to take an empty parameter instead we won't use anywhere?
As example: In Java 8+ when we take no input in our lambda we do this:
And when we have a lambda which does take a single input, we do this:
As you can see, the second is one byte shorter than the first. Because of that I created this meta-post with the following question: Are we allowed to use the second (where
null, or any random value at all, which we don't use in the function), when a program/function without arguments is asked?
EDIT: Please note that by unused empty parameter, I indeed mean unused. For example, you could use an empty parameter which you don't use directly in your code, but still use it for it's
static functions, like (where
s->s.join(...), which should be
s->"".join(...) instead. For Java
Void might be useful to use as unused parameter, since it has no additional
Other unused parameters could be used in other languages, as long as they are indeed empty and unused.
undefined). That's not possible in more strongly typed languages. So in those languages, having a 1-argument function with an ignored argument makes the calling convention weirder. \$\endgroup\$
ias the parameter if there's no reason to use something else. \$\endgroup\$
n. (And in Java you could propose that
Voidis a good default for the purposes of documenting that you don't intend to rely on any useful property of the parameter). \$\endgroup\$
Void, will use that from now on. I've been using
Object o=nullso far in my answers. \$\endgroup\$