my view on ruby on rails
Moderator: General Moderators
- jimthunderbird
- Forum Contributor
- Posts: 147
- Joined: Tue Jul 04, 2006 3:59 am
- Location: San Francisco, CA
my view on ruby on rails
Hi All,
I've not been here for a while. Finally got some time off after converting a ruby on rails application to php (sounds strange since looks like everyone is going the rails way). Just want to share and discuss some of the issues I found during this process.
1. I do the conversion by writting a self-made MVC framework from scratch without using existing ones like CakePHP or PHP On Trax. The front-controller and scaffolding takes me sometime, I wrote a script outside of the application to do the scaffolding for me and later on things become easier.
I actually prefer the way Cakephp to do the scaffolding. One good thing about php is the easy set up. Unlike ROR, which might be easy when coding, but it takes a while to correctly make it up and running. In PHP, I just upload the Models, Views, Controllers then everything works.
2. I create a components directory storing different utility class and some business logic class, one good thing about PHP is the strong communicty behind it, I can easily find a lot of useful code snippets (Here I especially want to thank Feyd, who wrote the SHA256 Encription class for php4, it works like magic!) and wrap around a class structure.
But one thing I don't like PHP (probably wrong) is it does not have namespace, so I need to be careful about the class naming convention in order to avoid conflicts.
3. During the process, I wish to give credit to Ruby on Rails, it gave me a good guildline on the MVC design pattern, it helps me better understand
and better organize my code. As to the language, Ruby looks nice but php is not too bad, the line of code is little bit longer but not quite.
4. Here's one big thing I found and share, I think at some point, bypassing the active record ORM and directly work in sql is actually faster and will gain performance also. The application involves a lot of multi-table record retrievals, I found using direct portable sql(ANSI sql) give me more control on the data. Active Record does not give me too much power on this application.
Finally, when it comes to the question of whether I like ruby or php, I will say that I still prefer php, ruby is beatiful but I think the success of it is largely due to Rails. I strongly believe PHP community will roll out a equally good (if not better) compared to Rails.
I really wish to know the opinions from all of you. Thanks a lot.
With my best,
Jim
I've not been here for a while. Finally got some time off after converting a ruby on rails application to php (sounds strange since looks like everyone is going the rails way). Just want to share and discuss some of the issues I found during this process.
1. I do the conversion by writting a self-made MVC framework from scratch without using existing ones like CakePHP or PHP On Trax. The front-controller and scaffolding takes me sometime, I wrote a script outside of the application to do the scaffolding for me and later on things become easier.
I actually prefer the way Cakephp to do the scaffolding. One good thing about php is the easy set up. Unlike ROR, which might be easy when coding, but it takes a while to correctly make it up and running. In PHP, I just upload the Models, Views, Controllers then everything works.
2. I create a components directory storing different utility class and some business logic class, one good thing about PHP is the strong communicty behind it, I can easily find a lot of useful code snippets (Here I especially want to thank Feyd, who wrote the SHA256 Encription class for php4, it works like magic!) and wrap around a class structure.
But one thing I don't like PHP (probably wrong) is it does not have namespace, so I need to be careful about the class naming convention in order to avoid conflicts.
3. During the process, I wish to give credit to Ruby on Rails, it gave me a good guildline on the MVC design pattern, it helps me better understand
and better organize my code. As to the language, Ruby looks nice but php is not too bad, the line of code is little bit longer but not quite.
4. Here's one big thing I found and share, I think at some point, bypassing the active record ORM and directly work in sql is actually faster and will gain performance also. The application involves a lot of multi-table record retrievals, I found using direct portable sql(ANSI sql) give me more control on the data. Active Record does not give me too much power on this application.
Finally, when it comes to the question of whether I like ruby or php, I will say that I still prefer php, ruby is beatiful but I think the success of it is largely due to Rails. I strongly believe PHP community will roll out a equally good (if not better) compared to Rails.
I really wish to know the opinions from all of you. Thanks a lot.
With my best,
Jim
- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
- jimthunderbird
- Forum Contributor
- Posts: 147
- Joined: Tue Jul 04, 2006 3:59 am
- Location: San Francisco, CA
a brief structure of my MVC framework
Hi,
My MVC Framework contains a lot of files. But basically I organize it this way:
/index.php ---- front controller act as a dispatcher
/config.php --- configuration file
/models --- folder storing models
/views ---- folder storing views
/components --- folder storing some useful utility component and business logic component
/javascripts --- folder storing javascripts
/stylesheets --- folder storing stylesheets
/images --- folder storing images
/system/dbadmin --- I copy phpmyadmin files under this folder, it's more of a convenience place for me to reference the table
/system/appadmin --- Here I put a php script which allows me to do the scaffolding through a web form, also, it also helps me generate the deploy files in /system/deploy
/system/deploy --- folder contains the deploy files, just upload them to the server, modify the config.php then it's done
The application has user access control, each admin access or read-only access, thus I made a file bean.user.php, it includes all logic and access control for the user.
Here's are some other components under the components directory:
class.dbmanager.php --- a self-made database manager
class.inputfilter.php --- a component help defeating sql injection and xss attack
classgroup.sha256.php --- a group of class written by feyd handling the sha256 encription
class.uploader.php --- a component providing a good interface for file upload, either though http upload or ftp upload.
I create some general guildline during the development:
1. Whenever I create a AJAX request, I always use POST instead of GET, the request page is always the page itself.
This way a page will receive two types of post request, normal post(form submit) or AJAX post.
Each model is sort of a sub controller handling all of these POST request, then do a post signal mapping.
2. I bypassed a lot of active record stuffs, since I think each database table itself is self-explainatory.
"select * from items" is almost the same as $items->findAll(), I actually prefer the first way.
All way long I use XAMPP software installed on my windows laptop, after I'm done I just upload the files to the server that's it.
Above is a brief description on my framework.
With my best,
Jim
My MVC Framework contains a lot of files. But basically I organize it this way:
/index.php ---- front controller act as a dispatcher
/config.php --- configuration file
/models --- folder storing models
/views ---- folder storing views
/components --- folder storing some useful utility component and business logic component
/javascripts --- folder storing javascripts
/stylesheets --- folder storing stylesheets
/images --- folder storing images
/system/dbadmin --- I copy phpmyadmin files under this folder, it's more of a convenience place for me to reference the table
/system/appadmin --- Here I put a php script which allows me to do the scaffolding through a web form, also, it also helps me generate the deploy files in /system/deploy
/system/deploy --- folder contains the deploy files, just upload them to the server, modify the config.php then it's done
The application has user access control, each admin access or read-only access, thus I made a file bean.user.php, it includes all logic and access control for the user.
Here's are some other components under the components directory:
class.dbmanager.php --- a self-made database manager
class.inputfilter.php --- a component help defeating sql injection and xss attack
classgroup.sha256.php --- a group of class written by feyd handling the sha256 encription
class.uploader.php --- a component providing a good interface for file upload, either though http upload or ftp upload.
I create some general guildline during the development:
1. Whenever I create a AJAX request, I always use POST instead of GET, the request page is always the page itself.
This way a page will receive two types of post request, normal post(form submit) or AJAX post.
Each model is sort of a sub controller handling all of these POST request, then do a post signal mapping.
2. I bypassed a lot of active record stuffs, since I think each database table itself is self-explainatory.
"select * from items" is almost the same as $items->findAll(), I actually prefer the first way.
All way long I use XAMPP software installed on my windows laptop, after I'm done I just upload the files to the server that's it.
Above is a brief description on my framework.
With my best,
Jim
- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
- jimthunderbird
- Forum Contributor
- Posts: 147
- Joined: Tue Jul 04, 2006 3:59 am
- Location: San Francisco, CA
Hi,
Yes, I would like to release the codebase as "Yet another PHP Framework", but I think CakePHP is doing mostly the same as my codebase, and it has lot more features than mine. I would like to share or discuss with all phpers here on some of the code I wrote and see if I'm doing the best practice. I always want to learn.
Two days from now I will embark on another project and I'm preparing on it based on the clients requirement. I hope I will have some time off to put up some code here.
Thank you very much.
With my best,
Jim
Yes, I would like to release the codebase as "Yet another PHP Framework", but I think CakePHP is doing mostly the same as my codebase, and it has lot more features than mine. I would like to share or discuss with all phpers here on some of the code I wrote and see if I'm doing the best practice. I always want to learn.
Two days from now I will embark on another project and I'm preparing on it based on the clients requirement. I hope I will have some time off to put up some code here.
Thank you very much.
With my best,
Jim
- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
- jimthunderbird
- Forum Contributor
- Posts: 147
- Joined: Tue Jul 04, 2006 3:59 am
- Location: San Francisco, CA
MVC --- concept v.s implementation
Hi All,
I just put a little more time pondering my MVC codebase yesterday...
And then I meet this article about another PHP Framework named "CodeIgniter".
Some of the words caught my eye:
"First things first, there is no database abstraction in CodeIgniter. This means that models in CodeIgniter is more a concept than actual implementation. The models are there for you to implement yourself. CodeIgniter only prepares the separation of files. As for CakePHP, you can’t have an application without models. The models are tied directly to the database. "
I think my framework should be more compared with CodeIgniter than Cake since I'm doing sort of the same thing.
And then, here comes a question:
When it comes to Ruby, people seems instantly comes to another name "Ruby on Rails".
While when it comes to PHP, people will come with a dozen other names, "CakePHP", "CodeIgnitor", "Zend", "Symphony","PHP on Trax".... (names going on and on)
Do you think we should combine the best features of all these framework and make an unified framework so in the future when people mentioned PHP, it will instantly come with that framework's name? If we do so, will it make PHP more popular or it will stifle it?
Thanks for your answer.
With my best,
Jim
I just put a little more time pondering my MVC codebase yesterday...
And then I meet this article about another PHP Framework named "CodeIgniter".
Some of the words caught my eye:
"First things first, there is no database abstraction in CodeIgniter. This means that models in CodeIgniter is more a concept than actual implementation. The models are there for you to implement yourself. CodeIgniter only prepares the separation of files. As for CakePHP, you can’t have an application without models. The models are tied directly to the database. "
I think my framework should be more compared with CodeIgniter than Cake since I'm doing sort of the same thing.
And then, here comes a question:
When it comes to Ruby, people seems instantly comes to another name "Ruby on Rails".
While when it comes to PHP, people will come with a dozen other names, "CakePHP", "CodeIgnitor", "Zend", "Symphony","PHP on Trax".... (names going on and on)
Do you think we should combine the best features of all these framework and make an unified framework so in the future when people mentioned PHP, it will instantly come with that framework's name? If we do so, will it make PHP more popular or it will stifle it?
Thanks for your answer.
With my best,
Jim
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
Re: MVC --- concept v.s implementation
Thats a tough one. It is basically a decision on how much control and decision making your framework you want. CakePHP for instance makes pretty much all your decisions for you, but is not nearly as extensible as Zend Framework. Use the right tools for the right job is what I say.jimthunderbird wrote:Do you think we should combine the best features of all these framework and make an unified framework so in the future when people mentioned PHP, it will instantly come with that framework's name? If we do so, will it make PHP more popular or it will stifle it?
Thanks for your answer.
With my best,
Jim
- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
PHP got where it is today by being horrible to purists. And you have to hand it to the PHP Group -- they have remained true through years of other languages disparaging them.
The answer, of course, is that if there was only one kind of programmer and one kind of problem ... then your suggestion would be brilliant. Rails does the opposite, and they admit it. They demand a certain style and are only interested in programmers who think things like converting singular names to plural is so cool as to be necessary.
You list six excellent frameworks that have been used by thousands of programmers to help them build sites.
The answer, of course, is that if there was only one kind of programmer and one kind of problem ... then your suggestion would be brilliant. Rails does the opposite, and they admit it. They demand a certain style and are only interested in programmers who think things like converting singular names to plural is so cool as to be necessary.
You list six excellent frameworks that have been used by thousands of programmers to help them build sites.
(#10850)
- Kieran Huggins
- DevNet Master
- Posts: 3635
- Joined: Wed Dec 06, 2006 4:14 pm
- Location: Toronto, Canada
- Contact:
While each framework has it's pros and cons, the reason one framework hasn't dominated PHP (IMO) is because the language itself doesn't really *fit* with one particular way of doing things.
Ruby is, by it's nature, a very object based language, with all sorts of abstraction and modeling to the core. Rails is the natural expression of this philosophy.
I'm not trying to play PHP down, but it has evolved over the years from one methodology to another, and the baggage is apparent. It's still an excellent language (naturally), but there is no "PHP way" to do things because of it's history.
Strength? Weakness? That's for you to decide.
Ruby is, by it's nature, a very object based language, with all sorts of abstraction and modeling to the core. Rails is the natural expression of this philosophy.
I'm not trying to play PHP down, but it has evolved over the years from one methodology to another, and the baggage is apparent. It's still an excellent language (naturally), but there is no "PHP way" to do things because of it's history.
Strength? Weakness? That's for you to decide.
- jimthunderbird
- Forum Contributor
- Posts: 147
- Joined: Tue Jul 04, 2006 3:59 am
- Location: San Francisco, CA
"7 reasons I switched back to PHP after 2 years on Rail
Hi All,
I just found an interesting article and I think I'm not alone on my Ruby On Rails --> PHP path.
It's an article by Derek Sivers "7 reasons I switched back to PHP after 2 years on Rails".
http://www.oreillynet.com/ruby/blog/200 ... o_p_1.html
Here's what he presents on the 7 reasons:
#1 - “IS THERE ANYTHING RAILS/RUBY CAN DO THAT PHP CAN’T DO? … (thinking)… NO.”
#2 - OUR ENTIRE COMPANY’S STUFF WAS IN PHP: DON’T UNDERESTIMATE INTEGRATION
#3 - DON’T WANT WHAT I DON’T NEED
#4 - IT’S SMALL AND FAST
#5 - IT’S BUILT TO MY TASTES
#6 - I LOVE SQL
#7 - PROGRAMMING LANGUAGES ARE LIKE GIRLFRIENDS: THE NEW ONE IS BETTER BECAUSE *YOU* ARE BETTER
I feel exactly the same way !
With my best,
Jim
I just found an interesting article and I think I'm not alone on my Ruby On Rails --> PHP path.
It's an article by Derek Sivers "7 reasons I switched back to PHP after 2 years on Rails".
http://www.oreillynet.com/ruby/blog/200 ... o_p_1.html
Here's what he presents on the 7 reasons:
#1 - “IS THERE ANYTHING RAILS/RUBY CAN DO THAT PHP CAN’T DO? … (thinking)… NO.”
#2 - OUR ENTIRE COMPANY’S STUFF WAS IN PHP: DON’T UNDERESTIMATE INTEGRATION
#3 - DON’T WANT WHAT I DON’T NEED
#4 - IT’S SMALL AND FAST
#5 - IT’S BUILT TO MY TASTES
#6 - I LOVE SQL
#7 - PROGRAMMING LANGUAGES ARE LIKE GIRLFRIENDS: THE NEW ONE IS BETTER BECAUSE *YOU* ARE BETTER
I feel exactly the same way !
With my best,
Jim