 | News Feed |
 | Jobs Feed |
Sections
|
| feed this: |  |
Web Species Blog: Lazy evaluation with PHP
by Chris Cornutt June 01, 2011 @ 08:41:01
Juozas Kaziukenas has a new post to his Web Species blog about using "lazy evaluation" in PHP - loading the resources you need for execution and evaluation only as you need them, not all up front.
Recently I needed to process a huge array of data and because of PHP's somewhat inefficient variables and especially arrays that was resulting in "out of memory" errors. However, I couldn't use any other tools than PHP so was forced to come up with a solution implementation in it. Here is how I solved it using principles from functional languages.
He gives an example using Haskell to generate a Fibonacci sequence using its built-in lazy evaluation abilities. Unfortunately, PHP doesn't have such a thing built in, so he tries the next best thing - Iterators. He caries the idea over to the database side too, recommending fetch() in a loop over fetchAll() and some effective joins.
voice your opinion now!
lazy evaluation haskell functional iterator
DevShed: Lazy and Eager Loading in PHP 5
by Chris Cornutt September 11, 2009 @ 12:49:30
On DevShed today there's the start of a new series looking at design patterns in PHP applications. In this first part of the series, they look at lazy and eager loading.
In the case of PHP 5, which is better suited for developing web-based programs, there are two complementary design patterns that can be of great help in building faster and more reliable applications. Of course, as this article's title suggests, I'm talking about the lazy and eager loading patterns. Despite their rather funny names, they are pretty easy to implement in PHP 5-controlled environments.
To illustrate, they've created a sample class that uses a few class properties and a __toString method to return the values.
voice your opinion now!
lazy eager loading tutorial designpattern
BuildInternet.com: Why PHP Frameworks Matter
by Chris Cornutt August 12, 2009 @ 11:09:50
From BuildInternet.com today there's a new article from Jason Gilmore looking at PHP frameworks and why they matter to both the developers and the community at large.
Having been a PHP programmer for more than a decade, I've come to realize that many of my fellow PHP programmers seem to have a misplaced notion of what being "lazy" is really all about. [...] Suddenly the Web developer was facing so much more than validating user input and connecting to a database [and] the need to be a lazy programmer was more important than ever.
He covers a lot of the basics of frameworks with a focus on the Zend Framework (because of familiarity) - configuration, data validation tools, database connections, display helpers and the inclusion of third-party plugins.
voice your opinion now!
framework important lazy overview
Giorgio Sironi's Blog: Doctrine 2 now has lazy loading
by Chris Cornutt August 07, 2009 @ 11:07:37
As is mentioned in this new post to Giorgio Sironi's blog, the latest version of Doctrine now includes lazy loading functionality.
Lazy loading is the capability of performing a expensive operation on demand, only when it reveals necessary from a client request. [...] In Doctrine 2 I made some architectural choices implementing the proxy approach, which substitute a subclassing object to every association which is not eager-loaded.
There's two main places you can see these differences - in the one/many to one associations dynamic proxies and collection interface.
voice your opinion now!
doctrine lazy load relationships
Giorgio Sironi's Blog: Lazy loading of objects from database
by Chris Cornutt July 21, 2009 @ 12:48:54
In recent post to his blog Giorgio Sironi takes a look at a handy feature that PHP makes it relatively simple to work with objects in your applications - lazy loading.
What is lazy loading? A practice in object/relational mapping which simulate the presence of the whole object graph in memory. There is some techniques for produce this illusion that I explain here. [...] The main problem is that we cannot load all the object graph, because it will not fit in the memory of the server and it will take much time to build, depending on the size of the database. Nor we can load an arbitrary subset of it.
His solution is to use the proxy design pattern to create an interface allowing only the first level of information to be loaded by default. After that, each of the sub-levels have what they need to load themselves and the data that might be needed inside.
voice your opinion now!
tutorial database object load lazy
Terry Chay's Blog: Autoloading and Lazy Loading
by Chris Cornutt April 27, 2009 @ 11:14:26
In this recent post to his blog Terry Chay points out one way he (and Tagged) used to help prevent things like "unknown class" errors in their code - lazy loading.
It's not that Andrei is wrong in his admonition. Far from it! For reasons that I don't quite care to know, there are caching and lookup optimizations that APC cannot do when it has to switch context to run __autoload.
They did see a performance boost from the code rewrite it took to make this happen but, since not everyone can take the time to optimize their code like this, he also suggests another way (as written up by Brian Shire). It uses two settings for APC in your php.ini file and the latest versions of PHP 5.3 & APC along with this patch to make them work.
voice your opinion now!
autoload lazy load apc cache performance increase
Padraic Brady's Blog: Unit Testing Multiple Assertions And Lazy/Shallow Testing Are Evil
by Chris Cornutt February 13, 2009 @ 09:31:33
In a new post today Padraic Brady takes a look at unit testing and two of the bad practices that can develop over time when writing your tests - overloading tests with assertions and lazy/shallow tests.
In short, every test you write requires that you setup the test environment, create a scenario for possible failure, add an assertion, and then ensure the source code makes that assertion pass. This requires code - sometimes a lot of code. So adding multiple assertions to each test minimizes the work needed to write tests, since using multiple assertions takes advantage of existing code to avoid writing new stuff to clutter your test classes. It can also help to tackle multiple but related results in the same test.
He gives brief examples of both instances and some of the problems associated with them. Multiple assertions, while nice for fine tuning the results of the testing, can also confuse since, if one assertion fails, the whole test fails too. The other end of the spectrum is a problem too - writing tests that don't do enough to really check the information passed in. These shallow tests can lead to issues down the line if unanticipated data might come along.
Really, its all about finding that "sweet spot" in developing tests - not too much, not too little - and keeping it simple while not missing out on assertions that need to be made.
voice your opinion now!
unittest phpunit lazy shallow multiple assertion example
Cormac's Blog: Lazy loading of object variables in php using __get()
by Chris Cornutt August 08, 2008 @ 14:22:51
Recently, Cormac posted this look at a method for lazy loading on variables in an object with the magic __get method.
I used the magic method __get() to load the images into the [Product] object when they were needed. __get() is called whenever something tries to access a variable that is not set or publically accessible, so basically I used that to load the images whenever some other piece of code tried to access Product::images.
He includes a quick bit of code that fires off an internal private method for the class that loads up the images. In his example, if they're already loaded, it never gets called.
voice your opinion now!
lazy loading get method image product
|
Community Events
Don't see your event here? Let us know!
|