Twitter user Data handling

I seem right now to be embroiled in a debate with another programmer on this project who thinks that views have no merits. He proposes a system that PHP looks something like this:

$draw = new Draw;
$nav = $draw->wideHeaderBox().
$draw->left().
    $draw->image().
        Image::get($image,60,array('id'=>'header_image')).
    $draw->imageEnd().
$draw->leftEnd().
$draw->left(10).
    '
'. self::defaultSectionText(). '
'. $draw->leftEnd().

and so on (this is in the controller btw). Now his arguments for this actually make some sense, he claims that if there is a redesign all we need to do is change the HTML in one place and it changes everywhere automatically. For some reason however, this method still rubs me the wrong way, is there any merit to views over this method? I mean besides not having to retype HTML by hand.

2 ANSWERS

16 febrero, 2017 a las 10:06 am admin

HTML time-savers are useful, but they’re only useful when they’re intuitive and easy-to-understand. Having to instantiate a new Draw just doesn’t sound very natural. Furthermore, wideHeaderBox and left will only have significance to someone who intimately knows the system. And what if there is a redesign, like your co-worker muses? What if the wideHeaderBox becomes very narrow? Will you change the markup (and styles, presumable) generated by the PHP method but leave a very inaccurate method name to call the code?

If you guys just have to use HTML generation, you should use it interspersed in view files, and you should use it where it’s really necessary/useful, such as something like this:

HTML::link("Wikipedia", "http://en.wikipedia.org");
HTML::bulleted_list(array(
    HTML::list_item("Dogs"),
    HTML::list_item("Cats"),
    HTML::list_item("Armadillos")
));

In the above example, the method names actually make sense to people who aren’t familiar with your system. They’ll also make more sense to you guys when you go back into a seldom-visited file and wonder what the heck you were doing.

Viendo 1 respuesta (de un total de 1)

You must be logged in to reply to this topic.