?

Log in

No account? Create an account

Previous Entry | Next Entry

Have I mentioned how I hate the inflexability of PHP recently? :P

Comments

( 9 comments — Leave a comment )
vanbeast
Jul. 7th, 2005 04:25 am (UTC)
raiiiiiiiiiiiils
groundup
Jul. 7th, 2005 07:46 am (UTC)
inflexible? explain on.
brocklisoup
Jul. 7th, 2005 01:27 pm (UTC)
Oh?
The one thing I always loved about PHP was it's flexibility. Perhaps you are stupid? I think mayhaps.
daveman692
Jul. 7th, 2005 05:12 pm (UTC)
Re: Oh?
No, not stupid. ;) Just now a Perl programmer.

Can't do things like the following in PHP:
my $db_handle = function that gets a db handle;
return undef unless $db_handle;


Have to write that as:
$db_handle = function that gets a db handle;
if (!$db_handle) {
    return false;
}


It is true you don't need the {}, but that would just be bad style now wouldn't it. ;)

Post conditionals are awesome in condensing code and improving readability, along with the unless statement. While "if not" is readable, "unless" is just so much more logical.

PHP doesn't differentiate between arrays and hashes, nor allows you to really deal with references. By combining the two it creates lazy programmers who don't understand the difference.

Dealing with class variables is ugly and confusing if you are reading someone's code.
Perl
package David;

use fields (
               'foo',
               'bar',
           );

sub new {
    my David $self = shift;
    my %opts = @_;

    $self->{'foo'} = $opts{'arg1'}; # remember the ' are optional
    $self->{bar}   = $opts{arg2};

    $self->woah($self->{bar});
    $self->who; # or
    $self->who();

    return $self;
}

sub woah {
    my David $self = shift;
    my $arg = shift;

    print $arg."Hey!";
}

sub who {
    my David $self = shift;

    print "Who are you?";
}


PHP way
class David {

    var $foo;
    var $bar;

    function David($arg1, $arg2) {
	$this->foo = $arg1;
        $this->bar = $arg2;

	$this->woah($bar);
        $this->who();
    }

    function woah($arg) {
        print $arg."Hey!";
    }

    function who() {
        print "Who are you?";
    }
}


Why does PHP only differentiate between a variable and function if you have ()?

I'm sure there are more, but now I'm in a meeting.
brocklisoup
Jul. 7th, 2005 05:20 pm (UTC)
Re: Oh?
PHP doesn't differentiate between arrays and hashes, nor allows you to really deal with references. By combining the two it creates lazy programmers who don't understand the difference.

Wait, I thought we were arguing flexibility. All of your points just support my argument. This has always been one of my favorite things about PHP - a single variable can hold pretty much anything you want it to: an array of objects, arrays and objects, or just more arrays of whatever. It's come in handy a few times when I want to use a single variable to pass a few scalar values and two hashes.

And don't even TRY the "confusing if you are reading someone's code" to defend Perl. You can't possibly look at more than a half-dozen Perl scripts and maintain that thinking.
daveman692
Jul. 7th, 2005 05:37 pm (UTC)
Re: Oh?
There is a difference between flexibility and shooting yourself in the foot.

So often I see things like:
// Execute the command
eval($GET['command']);
brocklisoup
Jul. 7th, 2005 05:39 pm (UTC)
Re: Oh?
You can do the same thing in Perl, though. You've long since left the flexibility argument - that's just plain stupid. You don't need a flexible language to cause trouble.
idonotlikepeas
Jul. 7th, 2005 04:46 pm (UTC)
I dunno, I think it's pretty flexible. It certainly finds a lot of ways to screw you.
daveman692
Jul. 7th, 2005 04:57 pm (UTC)
Some of the stuff I see people write makes me think they should commit hari-kari.
( 9 comments — Leave a comment )