Re: seperating php code from html?
| From: | Brent Baisley | Date: | Mon, 14 Apr 2003 14:51:03 +0000 |
| Subject: | Re: seperating php code from html? | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-143779@lists.php.net to get a copy of this message | ||
I try to go for complete separation of my logic from my presentation, even though I am the one doing both. The technique I use is to insert my own custom data tags inside my html code: {::DataTag::}. I then use output buffering to load the files into variables for manipulation. Mainly using str_replace() to replace the custom data tags with the actual data.
This makes it real easy to move things around without having to change a bit of my code. It also opens things up for allowing a user to customize their views. For instance, in a list view the user could specify what columns they want shown and in what order.
First and foremost I code to make things easy to maintain. Who cares how fast it is if you can't fix it or add new features in a timely manner. If you really want speed you should be writing it in assembly, which would take you considerably longer. Write it so that others can read it. I've had to revisit code that I wrote years ago, which I wrote for speed, and I had no idea what I was doing. In this case, I was the "other" person trying to read my own code.
If your function is fairly simple and is unlikely to change, then I would optimize it. But keep in mind any speed gains you may get and consider whether it is worth the time for the speed boost you would get. The functions you should try to optimize are the ones that are called the most.
Time to market is usually the overriding factor, which is why people use scripting languages instead of assembly, or C.
On Sunday, April 13, 2003, at 11:52 PM, Prince wrote:
i heard that it was better if when writing php to keep as much of the php code away from the html source as possible... or at least have as little html code in the php scripts as possible.. but either way it goes was just told to keep the 2 apart from each other as much as possible.. so given that fact 1. is that a true statement i should try to follow? or doesnt it really matter 2. is it ok to write code that would maybe take up 15 lines or so and turn it into 1 or 2 lines? 3. is code better written where the person who wrote it and everyone else can read it or should it be written for speed .. and last 4. when writing a class like a db class is it normal to be able to use 1 line of code after writing it instead of 6 before it was writen.. (guess this sort of fits in with the first thing but just making sure)... -- Brent Baisley Systems Architect Landover Associates, Inc. Search & Advisory Services for Advanced Technology Environments p: 212.759.6400/800.759.0577