 | News Feed |
 | Jobs Feed |
Sections
|
| feed this: |  |
Sameer Borate's Blog: Refactoring 3 Replace Temp with Query
by Chris Cornutt June 08, 2009 @ 11:18:47
Continuing on in his refactoring series (part 1 & part 2) Sameer has posted part three - a method of replacing temporary variables with calls to other methods.
Temporary variables are a integral part of any code. But a splattering of the same all over can make your code hard to understand or modify. Replace temp with query is a refactoring method where you replace temp variable expressions with methods. This method is often also required before you use the Extract Method refactoring.
In his example, he takes a variable inside a current method (base_price) and replaces it with a method call by the same name resulting in a more reusable format other methods can call rather than just computing the value themselves.
voice your opinion now!
method variable temporary refactor
Mike Naberezny's Blog: PHP Temporary Streams
by Chris Cornutt October 20, 2008 @ 07:52:59
Following up on this post from David Sklar, Mike Naberezny has come up with a few methods of his own to come up with his "thousand string concatenations".
It's been a while since David Sklar called out to let a thousand string concatenations bloom. That discussion produced some entertaining suggestions for putting strings together such as using preg_replace and calling out to MySQL with SELECT CONCAT.
Mike goes with a bit different media of choice - the filesystem functions and streams. One example opens a file, writes to the file then rewinds back to the beginning of the stream. He modified this to make it slightly more useful (writing to memory not the file system) and shows how it could be used to make a temporary stream for testing purposes.
voice your opinion now!
temporary stream concatenation zendlog filesystem
Christopher Jones' Blog: Temporary LOBS in PHP's OCI8 Extension. Instant Client.
by Chris Cornutt January 21, 2008 @ 12:05:00
Christopher Jones talks today on his blog about a bug he's just corrected and integrated into the release of the Oracle Instant Client that lets PHP correctly take advantage of the temporary LOBS functionality.
When PHP is done with the temporary LOB, it needs to tell Oracle to destroy it. If this isn't done, then the temporary LOB will hang around using DB space until the connection is closed. I just merged a fix worked on by Krishna Mohan and myself for bug 43497.
Example code is included showing two instances of its use - a normal use that frees the memory correctly and the other showing how to create the temporary lob to hold the data as needed.
voice your opinion now!
temporary lob patch oci8 extension instant client memory leak
Arnold Daniels' Blog: Perl like temporary variables in PHP
by Chris Cornutt November 02, 2007 @ 09:38:00
Arnold Daniels points out a quick method for creating what he calls "perl-like temporary variables" in the global scope of a script:
When writing code in the global scope, I often have a problem where I'm overwriting a variable. This happens even more often when I work on code of somebody else. Usually has the variable which does the overwriting is usually just a temporary variable.
His code is a simple few lines that shows how it could be used when trying to write information out to a file handle. Some of the comments on the post criticize his use of the global scope but Arnold comes back with his reasoning - mostly that there is already code in the global scope and that adding something else is only adding to it, not making things worse.
voice your opinion now!
temporary variable perl global scope temporary variable perl global scope
Webdigity.com: Caching your pages with PHP
by Chris Cornutt July 16, 2007 @ 18:55:00
On the Webdigity.com forums, there's this new tutorial posted showing how to create a simple caching system with PHP for your site (using cached files).
A problem that this process creates is the server overhead. Every time we execute a query in the database, the instance of our script will call the DBMS, and then the DBMS will send the results of the query. This is time consuming, and especially for sites with heavy traffic is a real big problem.
There are two ways to solve this if you want to make your site faster. First is optimizing the queries Visit through proxy, but we will not talk about this at the present article. The second and most valuable is using some kind of custom caching technique.
Their code, contained in an easy-to-use class, makes it simple to cache the contents of a page just by setting the stop to start the caching from (and where to end).
voice your opinion now!
caching page class file custom temporary caching page class file custom temporary
PHP-Coding-Practices.com: Composing Methods Introduce Explaining Variable
by Chris Cornutt July 02, 2007 @ 07:53:00
From the PHP-Coding_Practices.com site, Tim Koschuetzki has posted an interesting suggestion for developers working with long expressions to make thing simpler - substituting temporary variables for portions of the expression.
Introduce Explaining Variable is particularly useful with long if-statements. You can take each condition, introduce an explaining variable and the conditional logic will read very well.
Another occasion is a long algorithm where each step in the calculation can be explained with a well-named temporary variable.
The method is basically the following - declare the temporary variable with part of the expression, replace where needed in the expression, repeat for other parts of the expression. In his example code, he demonstrates its use, pulling out portions of an equation to calculate an item's price to make it much more readable.
voice your opinion now!
method variable temporary compose substitution method variable temporary compose substitution
|
Community Events
Don't see your event here? Let us know!
|