[REBOL] Re: idioms to reduce logic clutter ?
From: al:bri:xtra at: 13-Oct-2002 10:42
Jason wrote:
> ;> ; TEST FOR PASSWORD
> ;>
> upass: copy ""
> loginstatus: false
>
> either error? try [
> ;condition
> upass: cgi-obj/userpass
> ][
> ;error
> if = upass "" [
> print rejoin [
> {<b>Bad login!</b>}
> {no user password provided }
> {<a href="upload.html">}{try again}{</a>}
> {<br>}
> ]
> ]
> quit
> if <> upass "" [
> print rejoin [
> {funny password provided. Please }
> {<a href="upload.html">}{try again}{</a>}
> {<br>}
> ]
> ]
Notice the duplication here:
> {<a href="upload.html">}{try again}{</a>}
> {<br>}
I'd make this into a small function which takes a error message.
> ][
> ; ok user has submitted a name and password
> ; check to see if they match
> upass: cgi-obj/userpass
> either = upass logindict/:uname
> [loginstatus: true]
> [loginstatus: false]
> if not loginstatus [
The above is better written as:
if not loginstatus: upass = logindict/:uname [ ; etcetera
> ;trouble in paradise - help them out..
> print rejoin [
> {<br>Username and password do not match. <br>Please }
> {<a href="upload.html">}{try again}{</a>}
> {<form method="POST" action="echo-login.r"
enctype="multipart/form-data">
> <i>Forgot your login or need to register ? <br>
> Please enter your email address here: </i>
> <input type="text" name="email_address" value=""/>
> <input type="submit" value="send login by email"/>
> </form>}
> ]
> quit
> ]
> ]
Just a few suggestions.
Andrew Martin
ICQ: 26227169 http://valley.150m.com/