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:
()->doSomething
And when we have a lambda which does take a single input, we do this:
n->doSomething
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 n
is 0
, ""
, 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 String s=null
) 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 static
uses.
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\$i
as the parameter if there's no reason to use something else. \$\endgroup\$_=>
instead of()=>
in JavaScript changes nothing about the way the function is called, and it will behave the same no matter what it is passed. I don't think you can say that for Java. \$\endgroup\$n
. (And in Java you could propose thatVoid
is 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 usingObject o=null
so far in my answers. \$\endgroup\$