anupom
RT @dhh “Unlocking A Device By Performing Gestures On An Unlock Image” -- one of the patents Apple is suing HTC over. So pathetic :(

Today in the official CakePHP google group I proclaimed with poise that having PHP helpers for outputting JS (like CakePHP’s JS and Ajax helpers) is a very bad idea. And then someone from the group asked me if I have any argument to defend that. Here are the points that I posted there:

  • It minimizes the code but maximizes the chance of error
  • It really becomes hard to debug
  • We should write unobtrusive Javascript.
  • In almost 99% cases we need to write custom JS logics. Unfortunately we can’t write it using PHP helpers.
  • Most of the PHP devs know or should know how to write Javascript, at least what those helpers can do - it's easy man!
  • JS itself is not that hard that, any PHP dev should be able learn it quickly.
  • JS libraries are very easy to learn as well.
  • It becomes hard to manage/modify or extend.
  • If you really want to use cool JS stuffs and you think you cant - then I would recommend you to hire a JS Ninja or become one. It will be far better than writing PHP to output JS.
  • JS libraries are there to minimize your effort, maximize reusability.... Why do we need to use PHP?
  • Less control, less flexibility..... and we are getting almost nothing good in return.
  • Moreover, it can make newbies confused, they can think that this is the right way of doing JS and waste their precious time learning it and trying solving problems using it. It is better to put in that time to learn JS itself.

Is there anyone out there who can justify using PHP to output Javacript? I did not find any real benefit of that, and to me it’s really really a weird idea! CakePHP should abandon their Ajax helper and some part of their JS helper. The only benefit that I can see of having those helpers is we can then call CakePHP an ‘Ajax framework’! Well to me it sucks even more, it sucks big time!

Habari
You are logged in as Anonymous. Want to Log out?

Reader Commentary

4 peoples have commented so far.

Tapos Pal

Sunday, November 2nd, 2008 at 5:57pm
Tapos Pal's Gravatar
 

I agree with u.
One more thing, I want to add here that Now web application has changed. Now a days, JS become one of the most important part of Web 2.0 applications. These needs can't be fulfilled by JS/AJAX PHP helper.

Thanks

 

Rafael Bandeira

Friday, December 5th, 2008 at 10:16am
Rafael Bandeira's Gravatar
 

I entirely agree with you, I always thought it.
But Cake does have a point to use it, RAD. In the end you can use it to automate some things on UI. And it's not just Cake, Rails has it, ASP has it...
I think that the idea ends up being not to have to learn any other language/tool, and be capable to control everything from one place. The idea is not bad... Although I doubt it would fit my purposes with any possible implementation.

 

nhm tanveer hossain khan (hasan)

Monday, January 19th, 2009 at 12:41pm
nhm tanveer hossain khan (hasan)'s Gravatar
 

hi,
you are absolutely right, i guess what rafael is trying to point is about DSL (domain specific language).
i asked myself same question why shouldn't i use helper when i can do cool stuffs with them.

well i guess the point of view rails or similar frameworks had is obviously not stopping you from learning javascript rather to facilitate you by providing helper functions for your commonly used javascript functions.

let me explain a bit, -

form action="" >....so many fields

 

Anupom

Wednesday, February 11th, 2009 at 6:02pm
Anupom's Gravatar
 

Hmmm.. yeah Rails, ASP and JSF.. and what not.. I liked Rafael's point that it actually facilitates RAD. But as like, for CSS/XHTML, we can either use Dreamweaver or handcode'em all. I don't know I still find handcoded ones better :)

If Cake or Rails plan is to incorporate DSL then I must say - "a long way to go".. I will be using plain JS till then :)

I am not against meta-programming or any of these sort. but to me mixing up Javascript with PHP/Ruby is a bit premature, over generalization and pretty limiting.

There are many JS library plugins available for me to accomplish common tasks that are like plug and play, it's that easy!

Thanks!

 

Leave a comment