Moderator: Now let's next have a look
at a couple of examples for one-argument functions.
For example here, I have a log function
which simply wraps the built in console log method.
Now we can argue whether such a function
makes too much sense, but we could be doing that,
if we want the option of quickly swapping console log
for some other outputting or logging mechanism.
Then having our own logging function,
which we use for our program, could make sense,
because if we ever switched from console log
to some other mechanism,
we only need to make that switch in one place
instead of in multiple places.
And then we have a function where it makes a lot of sense
that we need one-argument and just one-argument
and that would be the message which should be logged.
Now we could also come up with a way of writing this
such that no arguments are needed
again by creating a class,
which takes the message into constructor
and then has a no parameter log method.
But I'm not to sure whether it is really as an improvement.
It's a lot of extra code and we just replace a function
where it was totally obvious that we might have a parameter
and where the kind and value of that parameter
also is no surprise at all.
So here, I'm absolutely not a fan of changing this
just for the sake of changing it.
Instead, I think the original example
with one-argument here makes a lot of sense
and is absolutely something we can keep around.
Now, here are more functions
where one-argument makes a lot of sense
and is totally obvious.
For example this square function,
which simply squares a number
and therefore for takes that number as a single parameter
or the email is valid function,
which takes the email address,
which should be validated as input.
These are all examples for functions,
which we can leave like that
and where having one-argument
is totally fine, obvious, easy to read
and easy to understand.