Monday 30 November 2015

Why have keyword names for multiparameter message sends?

In Objective C, Swift and Rust, the parameter names in a function call are called keyword names. They trace their roots back to the Smalltalk language, where they are keyword names in message sends.
Classes and objects are often re-used from somewhere else, or form part of very large complex systems. They will often not have active maintenance attention for long periods at a time.
Improving the clarity and legibility of the code is very important in these situations, as code often ends up as the only documentation, especially when developers are under deadline pressure, or simply dislike writing comments.  (q.v. Comments are always wrong (link) 
A descriptive keyword name allows maintainers to quickly see what the purpose of each argument in a function call, and which order they appear in, by simply glancing at the function call itself, rather than having to delve deep into the function code itself. It makes explicit the implied meaning of the parameters.
The latest language to adopt keyword names for parameters in function calls is Rust (link) - described as "a systems programming language that runs blazingly fast, prevents segfaults, and guarantees thread safety."  High uptime systems require greater code quality. Keyword names allow development and maintenance teams much more opportunity to avoid and to catch errors from sending the wrong parameter, or calling parameters out of order.
Keyword names can be wordy or terse, but Smalltalkers prefer wordy and descriptive to terse and meaningless. They can afford to be, because their IDE will do the bulk of such typing for them.

No comments:

Post a Comment