Instructor: Now, here are a couple of examples.
And let's start with this example
where I have a save user function,
which takes an email and a password, so two parameters.
And where we then create a user object on the fly.
This is all written in Java script, by the way.
And in this object, I save the email and the password,
I also add a randomly generated new ID,
which is not a perfect unique ID by the way,
but good enough for this example.
And then we reach out to some database,
as it seems we could have also named this database,
of course, and insert this user
into a user's table or collection.
Now don't get me wrong.
This function is absolutely not horrible
and if you have code like this,
it's not the end of the world.
Still, if you call this function,
it would look something like this.
And you probably would have to take a closer look
at the function to understand that it wants an email address
and a password, and that the email should be the first
and the password should be the second argument.
Again, not the end of the world
and definitely also not totally unexpected.
Still, when we write code like this,
we might be able to come up with a better solution.
For example, we could come up with a function like this,
which only takes one argument,
which is the already finished user.
So we would outsource this task of creating the user
out of this function into another place and code.
So obviously this only works if we construct a user
ahead of time, but then we have a simpler
save user function, which ultimately of course,
also is very easy to call.
Still it takes one argument but now I would say
it's easier to understand and call
and it doesn't leave us guessing
whether email or password should be first
and which kind of values this function might want.
Now an even better solution could be this one here.
Here, we have a class user which acts as a blueprint
for a new user objects, which then has a safe method,
which can be called without any arguments.
Therefore, user.safe is very easy to read
and very clear and understandable.
And instead, we now outsourced the problem
of passing in values for the email address and the password
to the user constructor function.
And there you could argue it's a bit more expected
and obvious than on a safe user function.
As I mentioned, that also wasn't horrible,
but this code might make even more sense
and might be even easier to understand.
And therefore, this acts as an example
of how you could transform code to be easier to understand
and to not use any arguments on certain parts of your code,
where arguments might not be obvious
and the order could be unclear.
I also got one other example of a function
that takes no arguments, and that would be this one here.
Let's say we have a is logged in state,
which we managed somewhere
and then we have a function which just changes that state.
Therefore this function does something,
but it simply needs no arguments for that.
It just inverts this is logged in state all the time.
So that would be another example of a function
without any arguments, because in this case
it doesn't need any.
So these are some examples.
And again, I wanna emphasize that this original solution
still isn't horrible,
but maybe the other solutions we derived make more sense
or improve readability even more.