For anyone looking to do something similar (i.e. using exception control 
flow for handling request errors & validation), I found the 
slingshot<https://github.com/scgilardi/slingshot> library 
invaluable for enhanced try and throw  leveraging Clojure. Going with 
'native' try/throw was becoming nightmarish very quickly.

Thank you all for your input on this.

Julien

On Thursday, March 21, 2013 3:27:07 AM UTC-4, Marko Topolnik wrote:
>
> On Wednesday, March 20, 2013 11:29:55 PM UTC+1, James Reeves wrote:
>
>> On 20 March 2013 16:41, Marko Topolnik <marko.t...@gmail.com> wrote:
>>
>>> On Wednesday, March 20, 2013 4:34:32 PM UTC+1, James Reeves wrote:
>>>
>>>>
>>>> If validation happens "all around", that implies there is no one 
>>>> function that can test whether a value of data is valid for a given data 
>>>> store. This strikes me as a somewhat shaky foundation for a system.
>>>>
>>>
>>> The idea is that all validation functions share the same contract to 
>>> call the appropriate *add-failure* function that registers the 
>>> validation result.
>>>
>>
>> I don't see why that would be necessary. Why not put all the validation 
>> logic in one place?
>>
>
> Indeed, why not. If the requirements allow it, it is definitely preferred.
>  
>
>>  
>>
>>>  There may be instances where it makes sense to use exceptions as a 
>>>> control flow mechanism, but I wonder whether it wouldn't be better to use 
>>>> something like CPS in those instances.
>>>>
>>>
>>> I can't picture how such a mechanism would work, and what benefit it 
>>> would bring over the exceptions mechanism. CPS in Clojure means 
>>> trampolining, which is quite an unwieldy, and I'd say "cheap" tack-on. A 
>>> validating function would then be supposed to return a common, 
>>> globally-defined "continuation", in fact just a simple function, that would 
>>> redirect the flow towards the validation failure-handling case.
>>>
>>
>> I wasn't thinking of validation when I suggested CPS, because I don't see 
>> a need for any unusual control flow when validating data.
>>
>
> That's enterely use case-dependent. In some project validation was 
> specified as fail-fast, and it happened in the middle of business logic 
> because the validation status couldn't be determined without computing some 
> interim results. Throwing an exception from a function three-four levels 
> down was the perfect choice in that case.
>
> -marko 
>

-- 
-- 
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
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to