> -----Original Message----- > From: Larry Garfield [mailto:larry@xxxxxxxxxxxxxxxx] > Sent: Thursday, December 09, 2010 5:35 PM > To: php-general@xxxxxxxxxxxxx > Subject: Re: ORM doctrine > > On Thursday, December 09, 2010 12:45:38 pm David Harkness wrote: > > On Wed, Dec 8, 2010 at 11:11 PM, Daevid Vincent <daevid@xxxxxxxxxx> > wrote: > > > Avoid these ORM things like the plague! . . . Not to mention all > > > that fancy "ORM" doesn't come without a price. It costs in terms of > > > speed, as well as training. > > > > If you value CPU time over developer time, by all means avoid ORM > > frameworks (and *all* frameworks). The point of a common framework is > > to trade a small bit of performance for a large amount of developer > > time. If you will only use the framework once, the payoff will be much > > less. The goal is to choose frameworks that you can leverage again and > again. > > > > As for training, you will be able to hire another developer that knows > > Doctrine. It will be impossible to find a developer *anywhere* that > > understands your home-grown framework without training. Nor will you > > get help with bugs in your framework or be able to discuss better ways > > to use it on forums. > > > > That being said, there are times when it's better to write your own > > code. I will do this if the options out there don't suit my needs or > > if they seem under-supported. For example, while we use PHPUnit and > > Zend MVC in our apps, I wrote my own TestCase subclasses instead of > > using Zend's. I had to write documentation for the other developers, > > and I must maintain it as needs change. It was not a decision I took lightly. > > > > David > > ORMs are fundamentally fighting the wrong battle. They have their use, but > in general they are architecturally not something you want to build your > entire system on. > > See: > http://www.garfieldtech.com/blog/orm-vs-query-builders > http://blogs.tedneward.com/2006/06/26/The+Vietnam+Of+Computer+Scie > nce.aspx > > --Larry Garfield > When I did some projects in Java+Hibernate a while back, it was very helpful when dealing with the basics at first. As for developer time, it didn't improve much as it took more time for me to understand Hibernate then just doing the standard DB abstraction + business object. Also, I later came to realize that setting up the class model for Hibernate to work is about the same time spent just doing abstraction + BO. Result? More time loss due to learning Hibernate and decrease performance due Hibernate's use of reflection. However, I still am interested in ORM to see if there's been improvement. Here's a classic case example: create table `category` ( `id` int not null auto_increment primary key, `parent_id` int not null default 0, `name` varchar(75) not null, Key `parent_id` (`parent_id`)); class Category { private $id; // int private $parentId; // int private $name; // string private $subcategories; // array // class get/set/misc. functions public function hasSubcategory($id) { return !empty($this->subcategories[$id]); } public function hasSubcategories() { return is_array($this->subcategories) && !empty($this->subcategories); } public function getSubcategories() { return $this->subcategories; } } I needed to get all categories and the result should reflect the visual tree structure of the categories. With ORM (such as Hibernate), I could only get back array($categoryObj) - PHP List<> equivalent. Which then forces me to write extra code just to get a category which could be anywhere within the tree structure. So I resort back to the standard DB abstraction + BO, giving this result: array ( $categoryObj->getId() => $categoryObject ) for all the categories where each category's subcategories list is array ( $categoryObj->getId() => $categoryObject ) from a simple query 'select * from category'. No loops just to find out if a category, anywhere within the tree structure, has a subcategory: $categories[$categoryObj->getId()]->hasSubcategory($subcategoryObj->getId) or complex code to display the entire tree structure: output($categories[0]->getsubcategories()) where output() is function output($categoriesList) { echo '<ul>'; foreach ($categoriesList as $category) { // process each category; echo '<li>'.$category->getName(); if ($category->hasSubcategories) output($category->getSubcategories()); echo '</li>'; } echo '</ul>'; } A long time ago when I started coding PHP, the available IDEs didn't have the capability to generate get/set methods from the properties of the class like for Java. Thus, I made a utility, based on PHP of course, that will do just that [1] which greatly reduces my developer time. I also have a 'mapper' that's an extension of my DB abstraction wrapper having this simple code for the above example: $this->connect(); $this->query($sqlString); while($row = $this->fetch()) { // map the row } $this->close(); Should the need ever arise, the abstraction wrapper I have will also permit me to open more than 1 DB connection without breaking the existing code while the code will still look similar to the above example. The above sample code a slightly simpler than what I have, which ran against a more sophisticated test case DB structure. Without caching, the final display results in less than 1/2 sec to fetch from DB and display in HTML, both in the header horizontal navigation bar and side bar tree for testing, having over 3000 i18n categories with 7 levels deep. Displaying the 'norm' falls within tens of milliseconds range. Regards, Tommy PS: The tool has been slightly improved upon. [1] http://pastebin.com/vMnFhpyf -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php