When I took a break from php three months ago I’d been up to my shoulders in the technology for about five years – I remember my first interactions with the language were figuring out whether I need to use .php3 or .php4 or just .php file extensions. But that’s not very interesting.

A more interesting tale to tell is perhaps how for the last few months I was growing increasingly frustrated with my job, my work environment, my skills toolkit and simply the whole LAMP web development stack. It was time to take a break … it was a lot later that I discovered a cool TEDtalk on the topic, watch:

But anyway, onwards to what I’d learned.

Lessons that can only be learned by staying the fuck away

This week my PHP hiatus saw the beginning of its end, I had to get a freelancing job to pay bills and other such nuissance – since PHP and Javascript seem to be what I’m most popular for in the community that’s the easiest thing to get a job for. And to be honest, I’m not really fluent enough with anything else to do it for real money.

So earlier this week I had a meeting with the team lead of the project to give me a short tour of their, dare I say it, very well designed framework, and I realised how much extra work needs to be done by the framework just because PHP is such an incredibly lame language.

  1. PHP doesn’t have support for that thing where you can use objects right out of a function. So we need a getScalar, getString, getRows, getRow function instead of a lovely getValue, “”+getValue(), getRows() and getRows()[0] system. Why php, WHY don’t you support this?
  2. PHP also can’t do inline arrays, objects and tuples. This is great for passing data around in a descriptive way and PHP fails completely. Why can’t I do a return { x: 0, y: 100 }? Or something like that? It’s silly that I’d have to create a whole new Vector class that doesn’t do anything other than hold two values.
  3. Another thing PHP desperately needs are keyword arguments, or whatever they’re called. It should be possible to call a function that has default values and define specific arguments without having to define all the other arguments because the one I need to set happens to be last. Seriously, what if the defaults suddenly change? Do I go through all the code to pass the correct defaults for that one argument I actually need? This could be solved by passing an object around but what’s this? Objects are a pain to create? Right …

So I guess that makes for almost one thing I’ve learned per a month of abstinence. Not the best ratio by all means, but it’s silly to find that such a modern language used by so many people would be such an utter failure on many points others, not unlike Lisp, have solved half a century ago. What the flying fuck!?

Did I miss anything? What else does PHP do well and what does it do poorly?

Reblog this post [with Zemanta]
Share and Enjoy:
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • LinkedIn
  • StumbleUpon
  • TwitThis
  • DZone

Tags: , ,

If you liked this post you should follow me on Twitter,
or see the music I like on last.fm,
or perhaps leave a comment, I like comments,
or go do your job because I know you're slacking,
or go write a blog of your own,
or tweet about something interesting,
or go out and have some fresh air,
or find a girlfriend,
or a boyfriend,
or a manbearpig,
or for fuck's sake stop reading this already,
no?
This entry was posted on Friday, October 23rd, 2009 at 11:12 and is filed under Uncategorized. You can follow any responses to this entry through the RSS 2.0 feed. Both comments and pings are currently closed.

8 comments so far

 1 

I see you like javascript :)

There’s something you missed, but it’s more a wish than a real problem:

function something(string $a, int $b, array $c, (anything if not specified) $d)

It would be nice if it worked :)

Ma ne morš u slovenš?ini napisat da se morm jst kle zajebavat s svojo slabo angleš?ino ane.

October 23rd, 2009 at 17:47
 2 

Navadil sem se na netu po anglesk pisat :D

V glavnem to kar pravis, da sem spregledal je “keyword arguments”, tretja tocka.

Ostale tocke pa ne pokriva samo javascript, pokrivajo jih prakticno vsi razen PHP.

=== nearly equivalent translation for others ===

What you’re saying I missed is called “keyword arguments” and is covered under bullet point #3, and everything else isn’t just a feature of Javascript, but rather pretty much any language other than PHP that I’ve tried.

October 23rd, 2009 at 18:01
 3 

you need to clarify your point 1, because I’m not sure what you mean:
– “you can use objects right out of a function”. It’s already possible to do $obj->method()->anothermethod(); and I think with 5.3 it’s also possible to do new Object()->method(). Not sure, though.
– “” . $object calls __toString() on object
– and I think getRows()[0] is possible with 5.3, although I’m again not sure.

I may also be misunderstanding the second point, because I don’t really see an issue with “Why can’t I do a return { x: 0, y: 100 }? Or something like that?”, you can do “something like that” with array(‘x’ => 0, ‘y’ => 100), which can be passed as an argument and whatnot.

I’ve rarely used named arguments in Python, so I think it’s a decent shortcut, but not a big deal. I think I missed it only once or twice in PHP, and the first time I went with associative arrays to go around it, the second time I just used the ordinary named arguments, because it’s not really worth bothering. :)

The things I’ve missed the most are object literals (hopefully we’ll get these soon), anonymous functions (coming with 5.3 yay!), and namespaces (5.3). I don’t like long named classes, so namespaces are very good for organizing the code, and I really hate that I have to specify a function every time I want to have a callback. So, again, yay. :)

btw, livenetlife steals focus from input boxes. annoying.

October 24th, 2009 at 12:52
 4 

Seriously, the $obj->method()->method() is already possible? I didn’t know that, cool :D

As for the second poing, yeah you could do the associative array but just look at all the semantic fluff around that. WHY!? I’d much rather just define an array as [1,2,3] thankyouverymuch :)

Yep I’ve used associative arrays to get around named arguments, but, again, it just makes the code incredibly fugly.

Well I guess we agree on the need for object literals (although if it could be expanded to support arrays in such a manner it’d be even better) and … well as for everything else, guess I can’t wait for 5.3 then. Looks like it’s going to be a big step forward.

October 24th, 2009 at 13:00
 5 

> Seriously, the $obj->method()->method() is already possible? I didn’t know that, cool :D

Yes, since 5.0.0 (July 2004). :D

October 24th, 2009 at 14:59
 6 

God dammit I thought we ware running 5.3 on our servers, looks like we have 5.2
I will tell our admins to upgrade ASAP so you can play with the new features …

October 30th, 2009 at 10:25
 7 

Oh and PHP wizards have no intentions of implementing $obj->Method ()[0]

there is a thread in their bug tracker (under feature requests) and they said that they won’t do it. Don’t know why though …

October 30th, 2009 at 10:34
 8 

Ok admin told me that PHP 5.3 is not yet available for BSD which we use. It’s still being ported :S
Once it is we’ll upgrade at once …

October 30th, 2009 at 10:38