Hacker News new | comments | show | ask | jobs | submit login
Inner-platform effect (wikipedia.org)
42 points by Hexstream 2846 days ago | hide | past | web | 24 comments | favorite



I do not feel that it is fair to dismiss php as merely a "template engine". It probably outgrew such a small scope of use around 3x. On a more philosophical level: the reason programmers long to create/control/extend the platform on which they exist is because they are programmers. I think once you reach this point you should go for it but also be prepared to move onto a programmable programming language.


I read it as referring to a templating engine such as Smarty (for PHP).

I've never really understood the need to abstract things in this way even for novice front-end developers since it's the concept that is important not the syntax.

e.g. I don't see any real difference in using a) <?php foreach($key as $val): ?> or b) {foreach from=$myArray item=foo}

To me the Smarty abstraction is pointless.


As a highly satisfied user of the smarty templating system, I want to refer you to this (from http://www.smarty.net/whyuse.php):

) Designers can't break application code. They can mess with the templates all they want, but the code stays intact. The code will be tighter, more secure and easier to maintain.

) Errors in the templates are confined to the Smartys error handling routines, making them as simple and intuitive as possible for the designer.

) With presentation on its own layer, designers can modify or completely redesign it from scratch, all without intervention from the programmer.

) Programmers aren't messing with templates. They can go about maintaining the application code, changing the way content is acquired, making new business rules, etc. without disturbing the presentation layer.

) Templates are a close representation of what the final output will be, which is an intuitive approach. Designers don't care how the content got to the template. If you have extraneous data in the template such as an SQL statement, this opens the risk of breaking application code by accidental deletion or alteration by the designer.

) You are not opening your server to the execution of arbitrary PHP code. Smarty has many security features built in so designers won't breach security, whether intentional or accidental. They can only do what they are confined to in the templates.


When you end up with flow-control, and other such complicated constructs, inside your templates, either the designers are already smart enough to "modify or completely redesign it from scratch, all without intervention from the programmer", or the programmer will need to be "messing with templates" anyway, to help the designers fix their logic errors, which no amount of abstraction will help overcome.

The problems solved by Smarty could be solved simply with a single try-catch block around the rendering-kickoff logic (that forwards to a nice 500 error page if something happens), and a convention to not do any business-layer stuff within the templates. [Also, source control + a dev/testing server to deploy on so "break[ing] application code" isn't a concern, but this should really, really not need to be mentioned.] This is exactly what I've done on any [non-framework] PHP project I've touched, and no one has ever complained that it was hard to edit the views.


All valid points, which I agree may be helpful for some although, again they only serve as abstractions.

) Errors in the templates are confined to the Smartys error handling routines, making them as simple and intuitive as possible for the designer.

- Ok, but this is an abstracted error message, when the designer could simply learn to work with PHP error messages.

) Programmers aren't messing with templates. They can go about maintaining the application code, changing the way content is acquired, making new business rules, etc. without disturbing the presentation layer.

- If you are using an MVC design pattern programmers will rarely need to mess with templates anyway.

) You are not opening your server to the execution of arbitrary PHP code. Smarty has many security features built in so designers won't breach security, whether intentional or accidental. They can only do what they are confined to in the templates.

- I thought it was possible to execute abritrary PHP code by using the {php} template tags?

I suppose at the end of the day you use what feels most natural for you and what your designers find easiest (or are familiar with). It's totally up to personal preference. For me it has always felt like too much of an abstraction to be worth utilising.


I have a different complaint: I think it makes sense to have a template system for PHP because PHP is such a poor template system. :)


I generally like PHP but am not a very advanced user, so I'm interested: what shortcomings do you see?


There are two major problems for me: one is that markup filled with "<?=$varname;?>" is harder to parse than markup filled with "{varname}"; for a designer, those extra characters are totally extraneous, and they're not even balanced the way all other kinds of special markup are in HTML or XML.

Secondly, there's nothing in PHP that guides one away from packing more and more functionality into the template instead of the template's caller; it's easy to find snippets of PHP that do something "cool" online, and it's hard to explain to your designer why they shouldn't use them.

So, too verbose and less maintainable, is what it boils down to.


I'm not sure why you believe that it is necessary to do stuff like <?=$varname;?>. Certainly, a competent PHP programmer can use file operations and str_replace to do templating; it's pretty much what I do right now. The template for a dog-related site I'm working on looks like this:

<div class="dog" id="dog_{{__id__}}">

   <h1 class="name">{{__name__}}</h1>

   <p class="sex">{{__sex__}}</p>

   <p class="breed">{{__breed__}}</p>

   <p class="images">{{__pictures__}}</p>

   <div class="description">{{__description__}}</div>
</div>

(The formatting appears to be lost; accept my apologies)

That said, I am also working on fixing a restaurant site that a friend programmed, and it is littered with the type of disgusting syntax you mention. It's the difference between a designer who does snippets of PHP and a programmer.


You're not arguing against me, but with me. ;)

The article suggested that it was obviously a bad idea to write a templating engine in PHP, since PHP is already in the category of "templating engine". As you point out, it's easy to implement a template system in PHP that's better to use than raw PHP would be.


Thanks! I won't start using Smarty because of that, but those sound like valid reasons for bigger projects.



eru, your answer is too generic - I could have googled that myself. I'm interested specifically in the shortcomings of PHP as a templating system.


OK. E.g. PHP does not check whether your templates are valid HTML (or even just half-way sane tag soup) at all.

And you need to put a $ in front of every variable. Seems like someone did not know how to write a parser..


Do other template engines, e.g. Smarty, check HTML validity? I tried looking at the docs and it wasn't apparent.


I would guess the PLT webserver can do so. At least it will statically avoid unclosed tags, since it's based on s-expressions.

http://docs.plt-scheme.org/web-server/run_ss.html#%28part._i...


Now go to google.com and view source, you'll see it couldn't have been output by the PLT webserver. :-)


Yes. However they optimize for speed and have the resources to test their pages in every browser.


I think once you reach this point you should go for it but also be prepared to move onto a programmable programming language.

There are large numbers of programmers who have moved on to "programmable" programming languages. (Languages where meta-programming is comfortable and very useful.) It's no longer a fringe thing. Either you use this wording tongue-in-cheek, or you haven't gotten that far yet.


[deleted]


I didn't read it as outer good, inner bad. In the C/machine code case, C builds a set of abstractions on top of the unabstracted machine code. If you write some language in C that emulates the original machine code, then you have the problem stated in the article; you're writing an abstraction which undoes the work of a previous abstraction. This is what's bad and why you should go back to the outer platform.


In the database world, developers are sometimes tempted to bypass the RDBMS, for example by storing everything in one big table with two columns labeled key and value.

Ironic, if you look at the Wikipedia schema. (At least last time I looked, which I admit was a few years ago.)


Would it be irony for a random HN user to post about an antipattern that happened to be reflected in the underlying HN implementation?


Good point, except the the irony is the reverse of that.

I think that many observers would say that the Wikipedia system works quite well considering they are one of the most widely used sites on the Internet. Since this article is published on Wikipedia, it would seem an ironic disproof of the article's contents that the publishing platform uses the very strategy that is claimed to be an anti-pattern.

I would go a step further and suggest that the technique listed uses the relational database such so that in the end it is more like a columnar database, although I have to think about that further before I feel more sure.


On the other hand, perhaps Wikipedia proves the point, and perhaps it could be argued that something other than a SQL DBMS would be more appropriate. I think the more rabid of the noSQLites would go that way.

Personally I prefer to be more descriptive than prescriptive and judge them on their success under extreme duress.




Guidelines | FAQ | Support | API | Security | Lists | Bookmarklet | DMCA | Apply to YC | Contact

Search: