(no title)
disillusionist | 10 months ago
One nice unexpected side effect is that I end up with more consistency in variable naming when using a param object in order to benefit from object definition shortcuts.
ie I will usually write something like
const firstName = getFirstName(); doTheThing({ firstName });
rather than const fName = getFirstName(); doTheThing({ firstName: fName });
hyperhello|10 months ago
string combineName(string first, string last);
Okay, I assume the result is the full name, but I don't really know that like I would if the return had a name in the header. (The function can be getFullName, yes, but that's so simple it doesn't matter).
disillusionist|10 months ago
geakstr|10 months ago
avandekleut|10 months ago
Then pair it with destructuring assignment!
`const { fullName } = getName({ firstName, lastName )}`
wvenable|10 months ago
A more complex example will probably return a more complex type that is more self-documenting. If the type is a single scalar value then I don't see the value of adding another name here.
mpweiher|10 months ago
In fact, just forget that it is a function that does something. Treat it as the thing it returns.
string fullName( string firstName, string lastName )
carlos-menezes|10 months ago
avandekleut|10 months ago
disillusionist|10 months ago