3 Functions Together what called?

Started by FarisDon, Feb 13, 2016, 08:46 PM

Previous topic - Next topic

FarisDon

Well as you can see the topic, you are surely understanding right folks, I just want to know if, I combine three functions together, what will be they actually called?
E.G: - player.Vehicle.Driver.Nameas you can see
I'm taking player.Vehicle function to get the vehicle(1), so i can know the driver(2), and than get the Name of the Driver(3).
So, i'm just damn curious to know what it will be actually called, mean like In squrriel language .-. if we use three functions together, like the one which can only return values, and the one which can recieve the values, or is it just me asking a silly question, and it doesn't really have a kinda name cause it's so stupid?
P.S: - Sorry, for my bad English, and yes i know it's a kinda really stupid, but just curious to know the things....

MacTavish

#1
Yes It Would

Edit: Tested

player.Vehicle.Driver.Name
Kusanagi
player..Vehicle.Driver
Kusanagi

Grand Hunting Project
Join #SLC, #KAKAN, #Doom, #GHP @LUnet

Retired VC:MP Player/Scripter :P

Murdock

It's called chaining functions

With "player.Vehicle.Driver.Name" you get the vehicle pointer, then the driver (a player instance) from that, and then the Name element of that driver

Quote from: Kusanagi on Feb 13, 2016, 09:00 PMYes It Would

Did you even read the question?

.

#3
It's still a function. It doesn't have a particular name. But if you're asking if this behavior in programming has a name then yes, it does. It's called 'chaining'. Like a chain. Get it?

It has it's advantages because you end up using the values right from the stack (in squirrel) and not have to allocate memory for variables to store them. Which could result in about 0.001% performance boost for the average scripter (aka. irrelevant).

The other benefit is the clean code (to some) which can all go in one line. But some might argue that it's actually less readable. At least people unfamiliar with the implementation will argue that.

But what about disadvantages? Are there any? Yes there are! And some major ones! The disadvantage is that no validation is done on the returned value on which you perform the chained call.

What if the player is not in a vehicle? Then .Vehicle returns null. And immediately after you try to access the .Driver member on a null value. What do you think will happen? Think carefully.

EDIT: Sorry, two posts were made while writing this. One of which answered your question.
.

FarisDon

#4
Quote from: S.L.C on Feb 13, 2016, 09:04 PMIt's still a function. It doesn't have a particular name. But if you're asking if this behavior in programming has a name then yes, it does. It's called 'chaining'. Like a chain. Get it?

It has it's advantages because you end up using the values right from the stack (in squirrel) and not have to allocate memory for variables to store them. Which could result in about 0.001% performance boost for the average scripter (aka. irrelevant).

The other benefit is the clean code (to some) which can all go in one line. But some might argue that it's actually less readable. At least people unfamiliar with the implementation will argue that.

But what about disadvantages? Are there any? Yes there are! And some major ones! The disadvantage is that no validation is done on the returned value on which you perform the chained call.

What if the player is not in a vehicle? Then .Vehicle returns null. And immediately after you try to access the .Driver member on a null value. What do you think will happen? Think carefully.

EDIT: Sorry, two posts were made while writing this. One of which answered your question.
About the disadvantages, I would say that it's obvious that if i'm getting the driver, i'll make the function to check that if player is in vehicle, thou it was just an example.Locked anyway.
Quote from: Kusanagi on Feb 13, 2016, 09:00 PMYes It Would

Edit: Tested

player.Vehicle.Driver.Name
Kusanagi
player..Vehicle.Driver
Kusanagi

For you, will just say its player.Vehicle.DriverAnd Murdock plus, S.L.c thanks.