Re: [Phphtmllib-devel] Usability issues
Status: Beta
Brought to you by:
hemna
From: Walter A. B. I. <wab...@bu...> - 2002-06-06 17:44:10
|
Howdy again, So I didn't think about this when I sent my previous email, but you can't have a function that is named the same as a class. So the functions as you listed them as wrappers won't really work. I think we could possibly just build more of the html_* functions ? Walt On Thu, 2002-06-06 at 04:09, David McNab wrote: > Hi, > > Following up from previous email, I've come up with a solution - a set > of function wrappers that constructs tag objects and populates them on > the fly with an arbitrary number of elements. > > For example: > > function TRtag($attribs) > { > $tag = new TRtag($attribs); > $n = func_num_args(); > for ($i = 1; $i < $n; $i++) > $tag->push(func_get_arg($i)); > return $tag; > } > > That way, I'm able to take advantages of the strengths of phpHtmlLib and > generate some quite readable code. > > Example from previous messages then converts to: > > $cmdstyle = array('size'=>'1', > 'face'=>'arial,helvetica,sans-serif'); > $row1 = TRtag("", > TDtag(array('align'=>'right'), > FONTtag($cmdstyle, > "Commands:")), > TDtag("", > FONTtag($cmdstyle, > Atag(array("href"=>"$urlPrefix&dbCommand=newTask", > "title"=>"Create New Task"), > "Create New")))); > print $row1->render(); > > That's a whole lot more readable (well, to me anyway). > > I forgot to say - thanks guys for developing phpHtmlLib - it really is > an excellent tool. Great building-block towards HTML abstraction in PHP. > > Cheers > David > > > On Thu, 2002-06-06 at 22:17, David McNab wrote: > > 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 > > > > > > > > _______________________________________________________________ > > > > Don't miss the 2002 Sprint PCS Application Developer's Conference > > August 25-28 in Las Vegas -- http://devcon.sprintpcs.com/adp/index.cfm > > > > _______________________________________________ > > Phphtmllib-devel mailing list > > Php...@li... > > https://lists.sourceforge.net/lists/listinfo/phphtmllib-devel > > > > _______________________________________________________________ > > Don't miss the 2002 Sprint PCS Application Developer's Conference > August 25-28 in Las Vegas -- http://devcon.sprintpcs.com/adp/index.cfm > > _______________________________________________ > Phphtmllib-devel mailing list > Php...@li... > https://lists.sourceforge.net/lists/listinfo/phphtmllib-devel |