On Sat, Apr 9, 2011 at 10:12 PM, James Reeves <jree...@weavejester.com> wrote:
> On 9 April 2011 10:07, Ken Wesson <kwess...@gmail.com> wrote:
>>> That particular example ties a predicate to a particular error
>>> message. Error messages should be independent of predicates, otherwise
>>> they can't be localized or changed to fit a specific situation.
>>
>> It can always be an integer or a keyword (or a string!) used to look
>> up the localized or situation-specific message in a map.
>
> It's still not as flexible, because different keywords with the same
> validation may require different error messages.

(def age-invalid-en
  {:low "age must be at least 1"
   :high "nobody is THAT old!"
   :blank "age is required"
   :non-integer "age must be a whole number"})

(def qty-invalid-en
  {:low "quantity must be at least 1"
   :high "maximum 10 per customer per order"
   :non-integer "quantity must be a whole number"})

(if-let [err (age-invalid-en (not-int-in-range? age 1 120))]
  (println err)
  (if-let [err (qty-invalid-en (not-int-in-range? qty 1 10))]
    (println err)
    (process-order age qty)))

>>> This would lead to a lot of validations with "not" in front of them.
>>> i.e not-email-address?, not-integer?, etc.
>>
>> So?
>
> It's redundant, doesn't read as well, and reverses people's usual
> conceptions about validations.

I don't agree. Everything that is not forbidden is allowed. Specific
chunks of the input-space are "wrong" for specific reasons; what's
valid it what's left after whittling all of those away.

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Reply via email to