[KLUG Members] PHP vs ASP
Buist Justin
members@kalamazoolinux.org
Wed, 13 Nov 2002 09:20:24 -0500
In most languages a multi-part conditional will only evaluate as much as it needs to to determine if the entire expression will be true. For instance, in C:
if (func_a() || func_b()) {
/* stuff */
}
if func_a() returns true func_b() will never be run, because it's an 'or' statement it doesn't matter what the result of func_b() is if func_a() is true. Another example:
if (a != NULL && memcpy(a, b, 1024) > 0) {
/* do stuff */
}
With most languages, if 'a' is NULL the memcpy() would never run. However, with a non-short-circuiting language the memcpy() will always run, which means to be safe you'd have to use:
if (a != NULL) {
if (memcpy(a, b, 1024) > 0) {
/* do stuff */
}
}
It doesn't seem like such a big deal at first, until you've grown accustomed to short-circuit logic and depend on it. Looping on multiple conditions can become a real pain too.
FYI: ColdFusion (at least prior to MX -- I haven't used that yet) is another web scripting language that won't short-circuit, making for some pretty ugly code.
Justin Buist
> -----Original Message-----
> From: Peter Buxton [mailto:peter@killdevil.org]
> Sent: Tuesday, November 12, 2002 10:43 PM
> To: members@kalamazoolinux.org
> Subject: Re: [KLUG Members] PHP vs ASP
>
>
> On Mon, Nov 11, 2002 at 03:00:18PM -0500, Buist Justin wrote:
>
> > c) Short-circuited conditionals.
> > This is a major pet-peeve of mine. Vbscript won't short-circuit a
> > conditional which prevents me from writing stuff like:
> >
> > Do Until (rs.EOF() AND rs.Fields("ProductID").Value <>
> lngLastProductID )
> > ' ... stuff
> > Loop
>
> Ummm... short circuit a conditional???
>
> --
> for gpg key: http://killdevil.org/~peter
> [The Basement Tapes were] like the Watergate tapes... Bob
> would say, 'We should destroy this.' -- Robbie Robertson
> _______________________________________________
> Members mailing list
> Members@kalamazoolinux.org
>
>