Perfection and code readability

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
Heavy
Forum Contributor
Posts: 478
Joined: Sun Sep 22, 2002 7:36 am
Location: Viksjöfors, Hälsingland, Sweden
Contact:

Perfection and code readability

Post by Heavy »

I decided to check out phpBB under the hood.

Now, I am Amazed about how cleanly it is written. I always wondered why my own projects end up looking bloated...

I guess the greatest reason to that is that I use to output HTML with PHP in the same php-file where the server automation is performed.

Well, phpBB (including this forum) is not. phpBB is class oriented and the actual presentation is done like this:

Code: Select all

<?php

//blablabla

//
// Generate the page
//
$template->pparse('body');

include($phpbb_root_path . 'includes/page_tail.'.$phpEx);

//blablabla

?>
... 8O ...

So... They are actually parsing a template using PHP... 8O

That is so rigid, it must have taken much effort to design the model from wich they worked it out.

Code is separate from design.
Automation is never bloated with HTML rubbish.


What about performance?

The PHP files can be cached using PHP Accelerator, but are the template files cached in any way? I guess not. People always tell me it is faster to query a DB for some text than opening a file and retrieving the data from there. :? Maybe I should do some benchmarking myself before saying it is so...

I guess templates can be read once and inserted into the DB with a special admin "scan for templates" command and thus increasing performance.

I don't have a well defined question about this, but I would like to start a thread about perfection of php usage.
evilcoder
Forum Contributor
Posts: 345
Joined: Tue Dec 17, 2002 5:37 am
Location: Sydney, Australia

Post by evilcoder »

I'm working on an OO Authentication Gateway at the moment, and without classes and functions, it would be a nightmare.

I guess the thing you have to weigh up is:

Do you want to writing the same piece of code over and over?

Thats why OOP makes things easier, it prevents you from having to do that. for example you can make a class for database connection and use it on as many databases as you like. But all the values assigned to it can be changed by making a new instance of the original class.

As for performance, you have to justify using OOP. I can because i use alot of the same code, over, and over again.
User avatar
Heavy
Forum Contributor
Posts: 478
Joined: Sun Sep 22, 2002 7:36 am
Location: Viksjöfors, Hälsingland, Sweden
Contact:

Post by Heavy »

I know there are great books to read about OOP.
Anyone that knows of a guide, howto, lesson or tutorial on the Internet that discusses OO implementation in a web-application (preferrably utilizing PHP)?
evilcoder
Forum Contributor
Posts: 345
Joined: Tue Dec 17, 2002 5:37 am
Location: Sydney, Australia

Post by evilcoder »

http://www.spoono.com/tutorials/php/aoo/

Great tutorial on OO and Classes.
User avatar
Heavy
Forum Contributor
Posts: 478
Joined: Sun Sep 22, 2002 7:36 am
Location: Viksjöfors, Hälsingland, Sweden
Contact:

Post by Heavy »

Thanks. It looked pretty good. But I discovered an error in the example of dummy4 and dummy5. I posted a comment about it, so it might be fixed if you try to find the error too.
evilcoder
Forum Contributor
Posts: 345
Joined: Tue Dec 17, 2002 5:37 am
Location: Sydney, Australia

Post by evilcoder »

i didnt learn from there, i just learnt by myself. Just had that in my link favourites. :)
User avatar
Heavy
Forum Contributor
Posts: 478
Joined: Sun Sep 22, 2002 7:36 am
Location: Viksjöfors, Hälsingland, Sweden
Contact:

Post by Heavy »

Dont go there
I checked out one more example about alternating row colors, and even that one had significant errors... :evil:
Post Reply