|
Posted by David Haynes on 03/30/06 13:43
Treefrog wrote:
> Hi All,
>
> For a while now I've been wishing PHP had (at least the option to
> enable) strict types. It would help a massive amount in BIG
> applications, and maybe start to taper the millions of lines of crap
> code that's out there.
>
> PHP is a great language, but the masses of incompetant coders out there
> do absolutely nothing to help the language grow. I know we all have to
> start somewhere, so please don't think I'm being eliteist, because I'm
> not, but something has to be done to try to fix the mess out there.
>
> Surely the contractors on here have witnessed this, or is it just me?
>
> What is everyone else's opinion?
>
> Cheers,
>
> T'rog
>
Well, you could do it in PHP5 by wrapping all the basic types in classes
like java does for a lot of things. Then each type class would have its
own toXXX converters to handle the casts.
This is an example of 'fixed with another level of abstraction' and I
wonder at the utility of it all. PHP - like shell - is often attractive
to coders *because* it is loosely typed.
I'm not sure how many coders would find PHP as attractive if they had to
follow stricter object type coding. For example:
$a = 'This is a string';
$b = ' This is another string ';
$c = 3;
$d = $a.$b.$c;
would become something like:
$a = new String('This is a string');
$b = new String(' This is another string ');
$c = new Int(3);
$d = $a->concat($b->concat($c->toString()));
Type-safe - sure! More meaningful? I would argue that all the method
calls get in the way of the meaning of the code.
Wasn't there a phplint project to help do some high level analysis of code?
-david-
Navigation:
[Reply to this message]
|