Swift does have an unconventional approach to function keys though, wherein you can specify an "external" label and an "internal" label:
func greeting(for person: String) -> String {
"Hello, " + person + "!" // the argument is "person" inside the function body...
}
print(greeting(for: "Dave")) // ... but it's "for" when calling the function
I'm not sure if I like it or hate it, but it is cool. const hello = ({ for: person }) => `Hello ${person}`
hello({ for: "Dorian" })
'Hello Dorian'e.g.
const user = {id: "123"};
const { id } = user; // This extracts the `id` field
const { id: userId } = user; // This also extracts the `id` field, but renames it to userId
console.log(userId)I’m glad they found a nice way to do it in Swift.
// in greeting.h
void greeting(char* for);
// in greeting.c
void greeting(char* person) { ... }
An example I like to use to show when and how I used it. I have been playing with Metal. If I write a function called translate, I will have it's external parameter as 'by' with the internal parameter being 'vector'. As a simple example:
func translate(_ origin: simd_float3, by vector: simd_float3) -> simd_float3 {
// do some stuff
}
let newVector = translate(originalVector, by: translatingVector)It's a tool to help better manage complexity, and that naturally invites more complexity as well.
adding additional names does not add additional complexity. complexity arises in interactions between components.
For instance ruby helps to have shorter, less verbose code, but with more hidden components. Rails rose from there, tooling tends to support that style. I've seen java devs moving to ruby and naturally writing less verbose code.
In contract Java tooling makes it a lot more manageable to write 40 character long classes, deeper dependency trees and injections and potentially auto-generate half of the needed methods. The cost is low, and there's less incentive to fight that trend when tools help you abstract part of it.
You're right that total complexity across the system fundamentally doesn't change (it's up to the devs and the problems at hand). Local complexity in each part of the system can vary, but the whole will probably always be least as complex as it needs to be.
http://avisynth.nl/index.php/Grammar#Functions.2C_Filters_an...