So, some folks scoffed a bit at my praise of PHP but for small scale engineering I think it's decent. There are flaws: it's not really promoting a test-driven culture, it might not scale well, since it's basically doing the compile step all the time... still, I'm digging it.
One decision it undoubtedly got better than JavaScript: being a duck-typed language, and coming from a scripting culture, global variables are the norm. $foo here, $bar there, and (as reflect its Perl roots) variables tend to be initialized to sensible defaults, and things 'just work'. The clever bit is this: function variables DO default to local, and if you want to share in a global variable (in my case, for system-wide directory locations) you simply declare the variable "global", meaning you DO want the shared version. That seems far less error prone than JavaScript "forget that var, to put it in the local scope? Too bad, sucker! That's a global!"
There might be some subtleties of closures I'm glossing over, but in practice, it seems like a smart thing.
No comments:
Post a Comment