2008-05-05

The pros from Dover

Is this sounding like one long rant about php?

I wonder why...

Today's rant is about the quality of PHP documentation. I've taken to using the official PHP documentation on the official website. Fairly often I am disappointed because there are missing parts: the developers wrote some code quickly and didn't bother to document. Odd for an official site, but okay.

So right now I am looking for info on doing HTTP digest authentication in php. There is a page about it that provides some examples that simply don't work. The regex for parsing Authorization headers is defective and none of the solutions people have offered up in the comments have helped me at all...

Fine.

The funny thing is that everyone insists on using regexes. I like regexes just fine, and with Perl I used to consider myself reasonably good with them. Anyhow, the consensus seemed to be that you needed a good regex. After screwing around for awhile, I was about to write my own solution using explode and substr and a lot of strpos(). But it was getting late...

So, after wasting an evening thinking that there was something I wasn't getting, I decide to look around for a library. There isn't much that jumps out at me right away, but I end up finding Auth HTTP which extends the Auth class.

I don't want to install Auth (trying to go light) but I download Auth HTTP to look at how they parse the Authorization header. First of all, I am impressed by how clean the code is. Then I find my function, and guess what: explode, substr, strpos.

2008-04-27

For instance (more about functions as arguments)

So, passing functions as arguments by turning them into strings, that's fine I suppose for traditional functions. But what about object methods? How am I supposed to transform $obj->do_something() into a string that I can feed to another function? That is what I would like to know.

php5 makes php bearable

Just to show what an amazingly open mind I have, I just wanted to add that after moving to php5 and trying to be as object-oriented as I can, I have started to find that programming in php can be less painful than I originally thought.

I am starting to get used to some of the overall quirkiness of the language. I even forgive it for having so ding many functions, since Common Lisp has quite a few as well.

Overall, I find that there is a lack of coherence in the way the function are implemented. I still have to look everything up all the time, but that is probably just me. However I expect a function to work, php usually does the opposite. But hey, they wrote the language, so they can do what they want. More substantially, I find completely counterintuitive and backwards the way that you pass functions as string arguments. At least in Perl, even though all arguments are passed as values, you are passing a reference, not just a string name. It just feels wrong, I'm telling you! I'd be willing to make function objects and pass them instead, but you still would have to feed those objects with strings naming functions... so back to square zero.

2008-04-13

From 4 to 5

Well, I get to play with php5 instead of php4. This is huge news for me, as I intend to use stored procedures in MySQL, which is all but impossible with php4.

I'm taking advantage of this change to really make this new project object-oriented. I'm not much of an OOP fanatic myself, but I do see some advantages here, especially since it is so ding hard to write anonymous functions and to pass them around. (At least that is my impression.) php5 seems set up in a way that encourages you to pass objects around instead, so I will adjust.

2008-03-24

Testing... Testing...

Now that I have started using a test suite -- this one, in fact -- my life has improved. At least I can see why PHP is not doing what I want it to.

There is something very satisfying about testing as you go. It definitely improves the modularity of your code.

strlen!

So strlen is just way more intuitive than length()!

Obviously

Obviously, I'm using php4. Because I have to.

If I could use php5, I would.

If I could use (almost) anything besides, php, four or five, I would. Including languages I don't even know but would love to learn. Python, for example. That would be fun.

PHP rant : anonymous functions

Anonymous functions in PHP are a joke. Maybe not in their overall functionality but at least in their syntax, that is with create_function. I mean, really: the function is a string of code that somehow gets evaled into a function?

If you are going to have anonymous functions, it would be nice to be able to write them like functions.

Hey...

This is obviously my first post here. This blog is going to be about programming. Right now it is going to be about why I hate the php programming language. That is why I decided to create this blog today. I would have eventually done it anyway, but it would have been later. So there you are. I'm going to publish this and then go see what this thing looks like. Back with some rants quickly.