[KLUG Members] PHP vs ASP

Buist Justin members@kalamazoolinux.org
Mon, 11 Nov 2002 15:00:18 -0500


I'm fairly experienced in both, and like debating language design, so I'll pop out my ideas here.  There's no particular order in how I'm going to drill down into each language, so bear with me.

a)  Variable scoping.
This doesn't seem like a big deal at all, but I don't think that -either- language does this well enough.  VBScript (what you call ASP :) is more traditional than PHP here.  You have globals and function-level variables, but something like this:

Function blah()
	Dim blnTemp, i
	For i = 1 to 10
		Dim blnTemp
		' do stuff
	Next
End Function


... will blow up. Valid C/C++/Perl constructs, but VBScript only gets as refined as functions.  Code "blocks" are in the same scope as their parent.

PHP's just goofy -- but in a somewhat good way.  You have global variables, but to access them have to pull them into scope with the 'global' keyword when in functions.  That's kind of nice, when you're working on a team of people who don't know -NOT- to pollute the global namespace, but when you're working on a team of sane individuals it's more of a nuisance.  To be honest, I couldn't tell you if PHP scopes things down to the block level, as it's been more than a few months since I really used it and it escapes me right now.

b)  Data types.
Both languages utilize un-typed variables.  One of them does it right (PHP), the other one makes me curse on a daily basis (VbScript).  You see, VBScript was meant to be nothing much more than glue to hold COM componenents written in either Visual Basic or Visual C++ together.  Anything remotely complex should be pulled out into a COM component where you can use a "real" language.  Because of this everything in VbScript is a "VARIANT" type which is really a big C union.  You get a "type" flag and a "data" set for each variable.  Why they took a tightly-typed language like C++ and made everything untyped is beyond me.  Nevertheless, you end up with Variants in VBScript but no low-level variant manipulation tools.  This can cause a whole slew of problems, and when one of these little oddities creeps into a project w/out somebody noticing it really gets on my nerves.  I have a slew of these stuck away in my head and would be glad to run through them with anybody interested :)

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

Sorry, but when we hit EOF we're still going to try and pull that ProductID from our recordset and the script's going to blow up in our face.  Big deal, you say... make boolean variable and loop off that, then test it's condition on each loop iteration.  No problem -- until the loop depends on something like 6 conditions and we've got this same code block scattered four times through a loop within a loop.  It's just not clean, and there's no good reason to NOT short-circuit your conditionals.   Anybody who relies on short-circuit type functionality, or it's lack of it, is experienced enough to know how to do it right.

d)  Development community.
I have no rational explanation for this, but the PHP online community is usually leaps an bounds better than your VBScript boards.  This is really nice, as you won't often find people posting bogus data to websites of horrid code.  I see -alot- of this with VbScript though.

e)  Database access.
Tie, almost.  PHP gives you the low-level DB access calls if you need them, but it's not a good idea to use them.  You'll shoot the "portability" of your project in the foot.  Better off going with ADODB which is based off MS's ADO that you'll use alot in VbScript.  PHP wins here though simply because it's underlying datatype doessn't do the brain-damaged things that VBScript does when you get back a NULL.

I was pretty geeked when I started using VBScript, at least for the first couple of weeks.  I'm thinking, "Hey... this isn't too bad, it might actually be pretty good."  Then, I got to know the langauge.  As I pushed the envelope a bit more (which isn't that far) the language coudldn't keep up with me and started behaving in ways that are just plain wrong.  Calling IsNumeric() on a variable which prints "19.95" to the screen (no quotes, just a literall one nine dot nine five) should NOT return false.  Has to do with things being VARIANTs again.  Apaprently something of the type "Decimal" isn't a number.  It's stuff like that that just kills me.

Justin Buist


> -----Original Message-----
> From: Russell Dillenburg [mailto:klug@russell.dillenburg.lan]
> Sent: Monday, November 11, 2002 2:05 PM
> To: Kalamazoo Linux Group
> Subject: [KLUG Members] PHP vs ASP
> 
> 
> 
> What are the advantages of using PHP over ASP?
> 
> P.S.
> By the way, I changed emails.  I used to be subscribed as 
> rdillenbu@yahoo.  
> I moved it to my mail server klug@russell.knightec.net.  
> Hopefully I have 
> my mail server set up right.  Yahoo only has that 6mb limit.
> 
> --
> Russell Dillenburg
> 
> _______________________________________________
> Members mailing list
> Members@kalamazoolinux.org
> 
>