Dear PHP, I’m leaving and yes, she’s sexier
2011/08/12 27 Comments
Dear PHP,
I know this letter won’t come as much of a surprise to you. We’ve been growing apart for a while now but today we officially part ways.
It wasn’t easy to write this. You and I have a lot of history. Hard to believe it was over 10 years ago when you welcomed me into your arms. You were young, sexy, and a breath of fresh air compared to my ex, Perl (shudder – lets not go there). It didn’t take long for our relationship to start paying the bills. In fact, every job I’ve had in the last decade had you on a pedestal.
We had plenty of good times. Remember how we survived a front-page CNN link and pulled in $500k in 14 days? And all the dynamic PDF creation over the years still brings a smile on my face.
But we had our rough times too. I could go the rest of my life without ever hearing the words ‘register globals‘ again. And you know quite well that I still bear the scars from creating SOAP clients with you. While neither of us has been truly faithful (what ever happened to V6 and UTF-8?), we’ve always been able to work out our differences up to now.
But starting tomorrow, for the first time in 10 years, my ‘day job’ won’t include you. I’m leaving you for node.js. We were introduced by our mutual friend, JQuery. At first I thought she was just the latest flavor of the month; popular among the guys on the mailing lists but now I’ve fallen victim to her async charm and really think we have a future together.
When you and I started having fun on the couch a year ago, I thought maybe our relationship would just keep going. But then node and I spent some time on that couch and – oh, what she can do with JSON makes my toes curl. To be perfectly honest, you just can’t compete with her. She’s all that you used to be – young, sexy, and fast. I’m sure some of your other boyfriends will probably argue with me about it but I’ve been smitten. While they’re fighting with you over namespacing, she and I will be branching in non-blocking ways and spawning like crazy.
I’m not saying we’ll never see each other again – heck, you’re even serving this blog. But I’m moving on and I hope you will too. If you want to see what node.js and I are up to, stop by some time. Maybe we can even help you keep an eye on all those fatal exceptions of yours.
Sincerely,
Shawn
* shudder, not shutter. Your vocabulary sucks
Doh! Thanks, mom. I fixed it.
Actually, that is a spelling issue versus a vocabulary issue. Using terms like “sucks” is a vocabulary issue.
There should be a period at the end of your second sentence. Your punctuation sucks.
Also, Blog-Comment Nazis suck. But not wind tunnels — they blow.
Hey man, i had great time reading this! LOL!
Congratsss!
I had more fun writing it than you did reading it, believe me! Thanks.
Perl > JS. :-P
Seriously, Perl has some very useful features like “local”, and literal lists. (I cringe all the times when I type function.apply(this,arguments). JS also wastes memory by making every array a hash *plus* array ops.
Though I may look into CoffeeScript; that at least would give a Perl-ish conciseness of syntax to JS.
I’ve also seen and heard good things about CoffeeScript but the thought of having to go through a ‘compile’-like step feels like wearing a neck tie again.
For the server side there’s the coffee executable. For the web, I’ll bet there’s something out there, in progress, or easy to rig up that sits in the web server, compiles CS on the fly, and caches it à la Perl Template Toolkit.
Check out this guys, http://boxjs.com. Boxjs will compile CoffeeScript files, compress and minify them!
I had the same thoughts, but it easy to use the coffee comand line utility to setup a –watch to compile your code real time as you save.
My opinion is that CoffeeScript is like training wheels. They can get you started, but later on they just get in the way. Learn the language. I also share this opinion on ORMs.
Arrays aren’t hashes but rather contiguous value storage in all modern engines that I know of, unless you stick non-numeric properties on them. Maybe you’re thinking of Lua?
What are you doing with “local” that’s better than “var”? ES5 has bind, if you want to change the default “this”, but I’m not sure what you’re doing with apply, or what the pattern would be in perl; my perl is pretty rusty. People use literal arrays quite liberally in JS, but maybe you mean something other than that when you describe literal lists. Maybe destructuring?
In JS, arrays are instances of the Array subclass of Object. Object instances implement hash tables. The fact that you can assign non-numeric indexes to JavaScript “arrays” illustrates my point. Perl arrays are true arrays.
“local” in Perl does something different from “var”: it takes a value scoped outside the current block (Perl is block-scoped rather than function-scoped.) and “localizes” the global variable, including inside whatever blocks/functions are contained within the block with the “local” statement. You’re probably thinking of “my” as the Perl equivalent of JS “var”.
JS only has what Perl calls array *references*. In Perl, you can do this:
my @foo = (1,2,3);
my @var = ( @foo, 4, 5, 6 ); #same as (1,2,3,4,5,6)
To do the same in JS, you have to do this:
var foo = [1,2,3];
var bar = foo.slice(0).concat(4,5,6);
Oh, and the other REAALLY big annoyance in JS is the lack of a heredoc. In Perl, I can do this:
my $long_string = <<END;
Oh, I will just write
and write
and write
lah de dee!!!
END
…but JS has no way of doing that.
Finally, the lack of variable interpolation in strings makes code needlessly prolix. Witness:
my $name = 'Felipe';
my $status = 'cool';
my $sentence = "Hello, my name is $name, and I am $status.";
…which, of course, in JS, we construct thusly:
var name = "Felipe";
var status = "cool";
var sentence = "Hello, my name is "+name+", and I am "+status+".";
Yech.
I’ve come to see “this” as more of a kludge than anything. Perl has this right, IMO: the “context” argument is more cleanly implemented as just the first argument to the function.
But, since you ask, I regularly use .apply(this,arguments) in classical inheritance models.
var Subclass = function() {};
YAHOO.lang.extend( Subclass, Base );
Subclass.prototype.foo = function() {
Subclass.superclass.foo.apply(this,arguments);
…whatever else I intend for the subclass’s foo() to do
};
Of course, the fact that I can’t treat “arguments” as an array doesn’t help much, and I really hate typing Array.prototype.slice.apply(arguments).
That said, JS >>>>> PHP. Yech.
No, in modern JS engines Array storage is different from Object storage. That Array.prototype delegates to Object.prototype doesn’t mean that the instance objects have the same storage. (I’ve been working on JS implementations since 1997, and did the array storage optimization in FF3.)
Tracemonkey and related (FF):
http://mxr.mozilla.org/mozilla-central/source/js/src/jsarray.cpp#42
V8:
http://codesearch.google.com/#wZuuyuB8jKQ/chromium/src/v8/src/objects.h&exact_package=chromiumos&q=package:chromium%20class:JSArray&type=cs&l=6728
SquirrelFish:
http://codesearch.google.com/#3V6MWLMMTXE/Source/JavaScriptCore/runtime/JSArray.h&q=package:webkit%20class:JSArray&type=cs&l=32
(If those V8 and SF links don’t come through, search for JSArray in their respective source trees.)
(If you want a way to see the difference yourself, you can compare the performance of indexed property access on objects and arrays in your favourite browser: http://jsperf.com/object-vs-array-indexed
On my Firefox nightly on OS X, array slot access is about 15x faster.)
Ah, great to know about this optimization – thanks!
As of monday I too will be leaving my full time job as a PHP developer to work on our node.js startup
Good luck endeavours in JS
God bless your new business, Alex. Go head and put a link to your project here when it’s ready. I love seeing the stuff folks are coming up with in node.js.
We are currently in private alpha but will be moving towards a more open alpha soon. We have just been funded by an accelerator program (so my next three months are all node all the time) and we hope to start working at a much faster rate
You can visit our site here:
http://wavo.me/
We do video, image, and music aggregation through recommendations from your social networks and provide an online library and playlists of your favorite media
Also we are working on a rapid development framework for node (on which Wavo is entirely built) it is very experimental now, but after the current re-write-in-progress it should be much more stable and in a state to try out:
https://github.com/glesperance/node-rocket/
Seriously? I want a Node.js job. All I do every evening is node.js. Someone hook me up! I want to leave PHP too!
I thought it’s yet another PHP -> Ruby article which makes me sick :) but PHP -> Node.js sounds much better :)
I had fun of reading this)
Haha, well written – but I feel that one day, you will want your ex. back, she will take you back, but you will regret all the fun times you missed by leaving her for so long.
Doubt it…
Really? Because there are so many people who “come back” to php? All those tech luminaries who love PHP … oh wait, there are none.
It’s a novice tool, and the people who leave don’t often come back. Unless it’s for a job of course. There is still the business case (tons of cheap hack programmers) for php.