3 ms·
I realize this is a nitpick, but the use of "is" after the various types is very counter intuitive. Suppose I'm thinking, "hmm, is this text?" or "is this a nu
by superqd 13y ago
I realize this is a nitpick, but the use of "is" after the various types is very counter intuitive.
Suppose I'm thinking, "hmm, is this text?" or "is this a number?"
To do this with the API you have looks like this:
a.text.is(myVariable); // to check if myVariable is text
a.num.is(myVariable); // to check if myVariable is a number
But just reading the code makes is backwards with respect to the phrase it represents (my bias). A more intuitive API call might be:
a.is.text(myVariable); // reads like the phrase
a.is.num(myVariable); // reads like the phrase
Even better might be:
is(myVariable).text(); // nearly self documenting this way
is(myVariable).num(); // ditto
Just some thoughts. Reading the API calls the way they are keeps sounding wrong in my head (clearly a bias).
- marknadal 13y agoYou can always do "a.text(myVariable).is()". I like your last version though, it seems clean. Your first variation was confusing for me, though. I was trying to keep all type operators neatly packaged in their respective type, though - isn't that cleaner than having dangling types?
- superqd 13y agoIt was confusing for me because it's using English words, but reading the code is the opposite of how you'd say it in English. I wouldn't ask/think "text myVariable is" (some languages would, I know), which is how "a.text(myVariable).is()" reads. Rather, I would say, "is myVariable text", which would correspond to "is(myVariable).text()", which reads that way in English (I know, a bias).
- noiv 13y agoI would buy is(myVariable).text within a second. Why calling two functions?
- marknadal 13y agoThis is a good idea too! Here we go, I made it a tiny module: https://gist.github.com/amark/6298069 https://gist.github.com/amark/6298069 include as a dependency then use as "a.is(myVariable).text"!
- noiv 13y agoGreat, that's very readable. Now someone needs to allow .text? to indicate the predicate without 'invalid token ?' :)
- superqd 13y agoyeah, that's good too.