[Phphtmllib-devel] A Critique
Status: Beta
Brought to you by:
hemna
From: David M. <da...@re...> - 2002-06-07 14:04:01
|
Hi all, I fear that I might come across as putting down phpHtmlLib, so please try and trust that that is not my intention. I love the concept of phpHtmlLib, that of abstracting the generation of HTML code. But after working with it for 2 days, I've gone back to printing out raw html for now. In using phpHtmlLib, I've found that the abstractions can be more fiddly to drive than raw html generation itself. At first, I felt really enthusiastic, and started converting a web-based project management application over to phpHtmlLib. My app generates some intricate HTML - tables nested 3 deep, rows and columns full of links which vary according to php script invocation flags and database content. More, link and non-link column styles - colours, italics, bold etc - also vary according to script arguments and database content. I gave up trying to convert the app. Instead, I started writing a completely new script, borrowing slightly from the logic of the raw one. But on writing the phpHtmlLib code, I found myself having to create tons of temporary variables to keep track of things. It all started to feel like programming in assembler. The abstraction mechanisms of phpHtmlLib came at a price - a whole lot of concrete tracking of details, and a whole lot of 'noise' in the script, which completely destroyed its readibility. The code ended up far more concrete than before. [It's a shame we don't have 3D displays. Then, logic indenting could go left-right, and tag indenting could go front-back. Or perhaps someone with too much time on their hands could write a LISP major mode script for phpHtmlLib to represent different levels of tags as different colours'] But seriously, it would be unfair for me to just rant on without offering some kind of ideas for how this could be fixed. Well, here goes... 1) Create a 'cursor' object, so that every time a tag object gets created, the cursor gets set to that object. Then, one could do something like 'add("A line of text")', and know the text will be written to the right place, without having to keep track of what the current tag is. 2) Complementary to (1) - a function allowing an arbitrary 'pop' back to any level of the stack. For example, if one is currently writing an <a> within a <div> within a <td> within a <tr> within a <table> within a <td> within a <tr>, one could pop the 'cursor' back to the outer level '<tr>' tag. 3) Make reference the standard default type of 'push'. For situations where someone really wants to do the 'copying'-style push, provide a tag object copying function (or method) which completely copies a tag object and all its children. With methods such as 'push_row()', the lack of a reference push is a big drawback. 4) Allow for easy creation of template classes. For example, it would be lovely to have a class which writes 10-point bold green centred links within a table column, without having to create n levels of tags each time. I'll sleep on it tonight. I feel very tempted to have a go at creating things like this myself, but I don't want to jump in without thinking at depth how it could be done well. Your thoughts? Cheers David |