[Phphtmllib-devel] Usability issues
Status: Beta
Brought to you by:
hemna
From: David M. <da...@re...> - 2002-06-06 10:18:09
|
Hi, I've just tried out phpHtmlLib on a part of a web app I've written. As much as I hate to say this, after all the work you guys have put into it, I've found that the phpHtmlLib-ised code is twice as long and half as readable, compared to plain echo statements. Code snippets follow. Before phpHtmlLib: $ff = "<td><font size=1 face='arial,helvetica,sans-serif'>"; $ffr = "<td align=right>" . <font size=1 face='arial,helvetica,sans-serif'>"; $ffend = "</font></td>"; echo "<tr>"; echo "$ffr" . "Commands:</td>$ff"; writeLink("$urlPrefix&dbCommand=newTask", "Create New Task", "Create New", "", ""); echo "$ffend"; echo "</tr>"; phpHtmlLib-ised version which does exactly the same: $row1 = new TRtag(); $fflabel = new FONTtag(array('size'=>'1', 'face'=>'arial,helvetica,sans-serif')); $col1 = new TDtag(array('align'=>'right')); $fff = $fflabel; $fff->push("Commands:"); $col1->push($fff); $row1->push($col1); $col1 = new TDtag(array('align'=>'left')); $fff = $fflabel; $link1 = new Atag(array("href"=>"$urlPrefix&dbCommand=newTask", "title"=>"Create New Task")); $link1->push("Create New"); $fff->push($link1); $col1->push($fff); $row1->push($col1); print $row1->render(); To me, it's about as clear as mud compared to the raw version. I tried to make it more readable by creating tags on the fly, within constructors for enclosing tags. Thus the previous code looks more like: $row1 = new TRtag( "", new TDtag(array('align'=>'right'), new FONTtag(array('size'=>'1', 'face'=>'arial,helvetica,sans-serif'), "Commands:"))); $row1->push(new TDtag("", new FONTtag(array('size'=>'1', 'face'=>'arial,helvetica,sans-serif'), new Atag(array("href"=>"$urlPrefix&dbCommand=newTask", "title"=>"Create New Task"), "Create New")))); print $row1->render(); Pardon the shitty formatting - blame my email client. But alas, the readability has not improved. I might humbly suggest that phpHtmlLib would allow for more readable code if the constructors could take an arbitrary number of content arguments. Or, better, if there were global functions with the same name as the phpHtmlLib classes, which take an arbitrary number of arguments and return a new instance of a tag object. For example: $row1 = TRtag("", TDtag(array('align'=>'right'), FONTtag(array('size'=>'1','face'=>'arial etc'), "Commands:")), TDtag(array("", FONTtag(array('size'=>'1','face'=>'arial etc'), Atag(array('href'=>'somegoddamurl', 'title'=>'myshit'), "Create New")))); With code like *that*, I could scan over it with even the most tired eyes and still see clearly what's going on, without having to follow gazillions of different variables. Thoughts anyone? Cheers David |