Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Coding Conventions/Styles/Practices

Status
Not open for further replies.

lefteyecc

Programmer
Feb 22, 2005
25
US
I have a question for you guys. This is a PHP forum so I figure most of you know the answer to this or the recommendation to his.

Ok so getting tot he point I wanna know which way of programming php is better. Is it better to use php to generate your pages like using printf() and those functions or is it easier and more practical to use HTML with PHP included for modularity(dynamic pages, and such). I use the former which is that I use printf and echo to print my html to the screen. I find my pages to be cleaner and easier to edit.So which way do you use?
 
sleipnir214 did some testing which proved that printing or echoing all html and having only one opening and closing <?php ?> bracket renders quicker than the constant context-switching code. I have followed that recommendation and find it an useful one. I guess my vote is for php code throughout.
 
Yea I agree I have tried both php code throughout and context-switching and phpcode throughout is alot faster and actually looks cleaner in MO.
 
Cool guys that's good to know. Considering I have a C+ background I fint it easier for HTML to be uotputted by PHP and yes it does look cleaner. It also makes it easier to debug your code. Well here's to hoping this information nenefits someone int he future. Thanks for the responses guys.
 
I was having the same problem as lefteyecc, but I also have the issue of working with a designer who has no knowledge of PHP. Basically what I do is have the designer create a template page, and views of the subsequent pages. I then use those pages and insert my own 'markup' (not php). Then through php I open the template pages and insert the appropriate html which has been output by my scripts.

I started this method a few months ago, and now have a very light-weight template engine. It also provides the added bonus of being able to open the template pages in an app. such as Dreamweaver and altering the html easily.

I'm sure this is not as fast as some other methods, but the bonuses for me are too great to give up.
 
Cool we have another way of generating pages. Does anyone know of a study or proll or something liek that that benchmarks the performance of PHP pages depending on the codeing style used?
 
Just throwing in my 5 cents...
If you use php to generate html, you also get the added bonus of the php-session being active in the entire page. I'm not sure how important it is to everyone, but it is very much so for me, as I'm working with databases.

Nobody enjoys shooting penguins, but if you have to shoot penguins, you might as well enjoy it.
 
lefteyecc:
thread434-843309 has the results of my own testing.

Even if my testing had shown that context-switching was faster, I would still use the all-PHP style of writing PHP code. I find code written that way much more readable, which means the code is more maintainable.


Want the best answers? Ask the best questions!

TANSTAAFL!!
 
Here comes the 'template' sermon:
We develop PHP applications for distributed environment, where there are multiple customers/departments using the same applications but need differend 'skins'. We also have the necessity to have PHP and HTML, i.e. functionality and presentation completely separated as two different groups of people take care of the respictive parts.
Using a PHP based template system with HTML templates that are editable with a WYSIWIG editor eliminate the need to alter code when presentation changes.
With an appropriate server setup, the Zend Optimizer, and efficient coding we practically have no discernable difference in performance. However, to admint, we have a server farm that handles requests assigned by a front end gateway that distributes the load to the four web server machines which are well equipped SUN systems.
 
Ok I have been looking into templates recently. I understand the benefits but honestly for msall projects what would be the nemefits?. I honestly consider the html generated by php way to be the cleanest and fastest. My scripts are easy to understand...to me at least...and get the job done effortlessly. I would also liketo know if any of you know of any websites that have template tutorials.

I know of but I doubt it relates to the FastTemplate included with PHP.
 
In terms of 'cleanliness' I can't imagine anything cleaner than pure code. Using an existing template class cuts down the effort for the script to a minimum and saves headaches with any changes in presentation.
Even in small projects I see a benefit by using context specific tools. A WYSIWYG editor for HTML that validates structure, a text editor for PHP. Functional code, no echo, no print statements, just assignment of content to variables of a template object.
If you were looking into commercial context this model also makes absolute sense. Give the customer your Zend Encoder treated code but leave them with the ability to change the presentation.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top