A keyword argument

I want to believe keyword arguments are an extravagance. They're unnecessary complexity, I tell myself. They complicate function call. The most naïve implementation is inefficient, and the most efficient requires multiple entry points. Why bother, for a feature that's hardly ever used?

But I do use them. When I have a rarely used optional argument, I write it with a keyword, when I'm writing in pseudocode or in a language that supports them. When I don't have keywords, I resort to including the keyword in the function name, like (sort-by score < nodes) for (sort < nodes :key score). That's nice and simple, but it's easy to get confused about the argument order. Maybe a reliable convention would help: head-marked keyword arguments always go first, or always last.

Or maybe I should stop trying to fight the pseudocode.

No comments:

Post a Comment

It's OK to comment on old posts.