Diego Perini wrote: >Scott Sauyet wrote: >> npup wrote: >>> I wrote a little utility to help out with checking status of objects. >>> More specifically, checking their conformance with a "signature" that >>> you provide along with the check. >> [ ... ] >> But I'm not thrilled with the API. The first thing that concerns me >> is the static call to Acts.As.info() which significantly constrains >> how I could choose to use it: if I want to store the results of a >> call, I have to make a call to .info before making another call to the >> test method. There's something wrong with that. My first thought is >> to reverse the sense of the call, so that false means that there is no >> mismatch and a results object details the issues found. But I can't >> think of a good name for that function, which makes me suspect that >> it's not as intuitive an abstraction as "ActsAs". Besides, it's just >> so negative! :-) > > Just a minimal name suggestion, could "reflect" work instead of "ActsAs" ? > > Hope I have correctly interpreted the sense/intent the name must give :)
I think "reflects" (not "reflect" -- don't you love English where adding an "s" makes nouns plural and verbs singular?!) has a similar sense as "ActsAs". I was suggesting something different, namely that the inverted sense might be nicer to use in coding. I still don't have a better name than "mismatches", which is fairly ugly. But it could be used like this: if (mismatches(spec, obj) { return; } // proceed knowing that the object matches the spec or like this: var mismatch = mismatches(spec, obj) if (mismatch) { throw new Error(mismatch); } // proceed knowing that the object matches the spec I'm just a bit uncomfortable with the negative sense of this. What I didn't like about npup's original is that this was handled with two separate calls: if (Acts.As(spec, obj) { // proceed knowing that the object matches the spec } else { throw new Error(Acts.As.info()); } This wouldn't allow, for instance, the following: if (Acts.As(spec1, obj1) { if (Acts.As(spec2, obj2) { // proceed knowing that all objects matches their specs } else { throw new Error(Acts.As.info()); } } else { throw new Error(Acts.As.info()); // fails to report accurately } You could of course work something out, but it strikes me as difficult, which is why I suggested reversing the sense. var mismatch1 = mismatches(spec1, obj1); if (mismatches1) { throw new Error(mismatch1); } var mismatch2 = mismatches(spec2, obj2); if (mismatch2) { throw new Error(mismatch2); } // proceed knowing that all objects matches their specs I'm not at all convinced by this, but I think it's worth considering. -- Scott -- To view archived discussions from the original JSMentors Mailman list: http://www.mail-archive.com/jsmentors@jsmentors.com/ To search via a non-Google archive, visit here: http://www.mail-archive.com/jsmentors@googlegroups.com/ To unsubscribe from this group, send email to jsmentors+unsubscr...@googlegroups.com