Aaron,
On 31-Mar-09, at 12:18 PM, Aaron Brown wrote:
Colin Clark wrote:
* Fluid.js: fluid.findKeyInObject()
This is a framework utility that performs reverse lookups in an
object:
pass in a value, and you'll get its associated key. This name always
confuses me about the order and nature of the arguments.
I'm new enough to fluid that I don't have an informed suggestion for
most of the name changes, but this one is pretty generic.
How about "fluid.getKeyByValue('some value')"
I think using the term "object" in the method call is unnecessary
since
key-value pairings only happen in specific kinds of objects in the
first
place. Fluid may have another naming convention for "get..." "set..."
functions, so fill in whatever term you'd normally use. The original
"find..." may also imply to the developer that it's not always a cheap
operation to perform - it requires an iterative scan over the hash to
find the result - so that prefix may be worth keeping.
By the way: Does this function return an array if multiple keys hold
the
same value? If so, perhaps it should be "getKeysByValue", or even two
separate functions, one that returns the first match and one that
returns all.
All good questions. JavaScript is a bit different in that key/value
pairs aren't limited to objects like hash tables or maps; all objects,
by nature, can hold key value/pairs. Given this, I agree with you that
the extra term "object" is unnecessary, since everything in the
language is an object.
The "find" prefix was, as you point out, originally intended to imply
to developers that it's not necessarily a cheap lookup to perform. We
decided to leave it off for brevity, but we'll need to mention in the
API documentation that it is indeed implemented as a linear scan over
all keys in the object.
We don't currently support returning an array if multiple keys hold
the same value at the moment. It may be a good feature to add. At the
moment, we stop as soon as we find the first hit.
Thanks again for your feedback and involvement. Naming is always hard,
and it's great to get ideas from the community,
Colin
---
Colin Clark
Technical Lead, Fluid Project
Adaptive Technology Resource Centre, University of Toronto
http://fluidproject.org
_______________________________________________________
fluid-work mailing list - [email protected]
To unsubscribe, change settings or access archives,
see http://fluidproject.org/mailman/listinfo/fluid-work