[erlang-questions] How do I elegantly check many conditions?
Fri Mar 20 19:32:26 CET 2009
Just wanted to add that I'm against of using funs in this case if you
can avoid it - just to keep module syntax as clean as possible.
comment to code in prev. message - you should wrap validator invocation
in try/catch and catch validator crashes - sometimes it's not necessary
to give a explanation to the user and general error message will be ok.
In this cases you can validator just fail, if it cannot validate the data
check_passwords(Fields, _) ->
Fields#fields.password = Fields#fields.password_confirm.
It will crash on match, if user entered different values in the fields.
With a little magic you create nested command chains, 'if' statements in
command chains, 'case' and so on.
If some validation procedures take a long time (for example require
network calls and so on) - you can add syntax to specify which commands
in chain is possible to run in parallel. If one of them fail (or
succeed) you can immediately kill another validation processes and
return a processing result.
Such programming style gives you a _GREAT_ level of flexibility to _what
login _ are you programming. In other this approach is very consistent
and have very readable syntax.
So :) Go and create your small interpreter in Erlang - it's fun and it
tel +37493 419763 (mobile - leave voice mail message)
e mailto:nm@REDACTED mailto:gasparch@REDACTED
More information about the erlang-questions