Comments on: Some PHP, Generated with Python http://www.sitepoint.com/blogs/2005/01/06/some-php-generated-with-python/ News, opinion, and fresh thinking for web developers and designers. The official podcast of sitepoint.com. Tue, 02 Dec 2008 07:26:59 +0000 http://wordpress.org/?v=2.5 By: mymame http://www.sitepoint.com/blogs/2005/01/06/some-php-generated-with-python/#comment-11853 mymame Tue, 13 Dec 2005 10:53:38 +0000 856709535#comment-11853 <strong>i am using flexy and when piece of html code is sent to template from controller, the html tags such as are getting parsed to < and &rt; respectively. How to send the code as it it?</strong> i am using flexy and when piece of html code is sent to template from controller, the html tags such as are getting parsed to < and &rt; respectively. How to send the code as it it?

]]>
By: Alan Knowles http://www.sitepoint.com/blogs/2005/01/06/some-php-generated-with-python/#comment-1699 Alan Knowles Wed, 31 Dec 1969 19:00:00 +0000 856709535#comment-1699 <p>Alot of this is built into the Flexy template engine - It parses out strings at compile time, stores them so you can write a translation tool (example is included in the package) - and uses pear's translation2 package to translate the strings to create language specific compiled templates.</p> <p>You can also place translation markers in the HTML to replace specific HTML blocks with tranlated versions (espessically usefull when the grammer mix of variables, text and HTML differes in different languages). It also has the long term benefit of encouraging you to remove all the langage specific code from the application and put all output words etc. into the template.</p> <p>Of course this is still wonderfully undocumented - but has been tested on some very high traffic sites, in a few european and a few double byte languages.<br /> </p> Alot of this is built into the Flexy template engine - It parses out strings at compile time, stores them so you can write a translation tool (example is included in the package) - and uses pear’s translation2 package to translate the strings to create language specific compiled templates.

You can also place translation markers in the HTML to replace specific HTML blocks with tranlated versions (espessically usefull when the grammer mix of variables, text and HTML differes in different languages). It also has the long term benefit of encouraging you to remove all the langage specific code from the application and put all output words etc. into the template.

Of course this is still wonderfully undocumented - but has been tested on some very high traffic sites, in a few european and a few double byte languages.

]]>
By: Ren http://www.sitepoint.com/blogs/2005/01/06/some-php-generated-with-python/#comment-1700 Ren Wed, 31 Dec 1969 19:00:00 +0000 856709535#comment-1700 <p><br /> I've been tempted to experiement in using double xslt transforms for producing interm templates. <br /> I guess this would be good usage of it, if it turned out a useful method.</p> <p>First tranformation would be a language independant template & language xml to produce a language specific template which then cached and then feed content xml to the final result.</p> <p>Writing a xslt which produces an xslt maybe bit too much hassle. Possibly could automate (with a few more transforms) this somewhat thou.<br /> </p> I’ve been tempted to experiement in using double xslt transforms for producing interm templates.
I guess this would be good usage of it, if it turned out a useful method.

First tranformation would be a language independant template & language xml to produce a language specific template which then cached and then feed content xml to the final result.

Writing a xslt which produces an xslt maybe bit too much hassle. Possibly could automate (with a few more transforms) this somewhat thou.

]]>
By: Selkirk http://www.sitepoint.com/blogs/2005/01/06/some-php-generated-with-python/#comment-1701 Selkirk Wed, 31 Dec 1969 19:00:00 +0000 856709535#comment-1701 <p>I really like the phrase "Just in Time Code Generation."</p> I really like the phrase “Just in Time Code Generation.”

]]>
By: patrikG http://www.sitepoint.com/blogs/2005/01/06/some-php-generated-with-python/#comment-1702 patrikG Wed, 31 Dec 1969 19:00:00 +0000 856709535#comment-1702 <p>Excellent blog entry, Harry. Been thinking about Python and where it makes sense to use it for quite a while now. I've been thinking about localization from within MVC, but was somewhat horrified by the number of views necessary. It has boiled down to me using a template engine again (which I don't generally like, as PHP is/was a templating language). Python, yet again, seems to offer a great solution. Time for me to have a much closer look at it.</p> Excellent blog entry, Harry. Been thinking about Python and where it makes sense to use it for quite a while now. I’ve been thinking about localization from within MVC, but was somewhat horrified by the number of views necessary. It has boiled down to me using a template engine again (which I don’t generally like, as PHP is/was a templating language). Python, yet again, seems to offer a great solution. Time for me to have a much closer look at it.

]]>
By: culley http://www.sitepoint.com/blogs/2005/01/06/some-php-generated-with-python/#comment-1703 culley Wed, 31 Dec 1969 19:00:00 +0000 856709535#comment-1703 <p>I think if you are really going to internationalize an application you need to make peace with a template engine. </p> <p>I am a little surprised that the php community hasn't glommed on to clearsilver templates (http://www.clearsilver.net/) with the php bindings (http://www.geodata.soton.ac.uk/software/php_clearsilver/). Clearsilver forces a clean separation between business logic from presentation logic. You can localize an application by simply switching the hdf data files. Bloglines.com is using this technology for their recent internationalization efforts.</p> <p>Everyone has their own preferences for template engines but many huge applications (bloglines, google groups 2, yahoo groups, Plaxo) are using clearsilver. The ability to swap out the back end programming language and leave your templates entact is convenient.</p> <p>culley</p> I think if you are really going to internationalize an application you need to make peace with a template engine.

I am a little surprised that the php community hasn’t glommed on to clearsilver templates (http://www.clearsilver.net/) with the php bindings (http://www.geodata.soton.ac.uk/software/php_clearsilver/). Clearsilver forces a clean separation between business logic from presentation logic. You can localize an application by simply switching the hdf data files. Bloglines.com is using this technology for their recent internationalization efforts.

Everyone has their own preferences for template engines but many huge applications (bloglines, google groups 2, yahoo groups, Plaxo) are using clearsilver. The ability to swap out the back end programming language and leave your templates entact is convenient.

culley

]]>
By: HarryF http://www.sitepoint.com/blogs/2005/01/06/some-php-generated-with-python/#comment-1704 HarryF Wed, 31 Dec 1969 19:00:00 +0000 856709535#comment-1704 <p><blockquote><p><br /> I've been tempted to experiement in using double xslt transforms for producing interm templates.<br /> </p></blockquote></p> <p>Could be <a href="http://www-106.ibm.com/developerworks/xml/library/x-matters14.html">this </a> makes interesting reading. <a href="http://www.lastcraft.com/blog/">Markus</a> says good things about the relationship between XSLT and Haskell.</p> <p><blockquote><p><br /> I am a little surprised that the php community hasn't glommed on to clearsilver templates<br /> </p></blockquote></p> <p>Thanks for the link. Now glommed.</p> <p><blockquote><p><br /> I really like the phrase "Just in Time Code Generation."<br /> </p></blockquote></p> <p>Thanks - hadn't occurred to me while writing - wonder if it makes the same league as <a href="http://www.procata.com/blog/archives/2004/05/05/api-design/">Moore's Law</a>? Could also make a nice subheading in a book on PHP project management, under "Meeting Client Expectations"...</p>

I’ve been tempted to experiement in using double xslt transforms for producing interm templates.

Could be this makes interesting reading. Markus says good things about the relationship between XSLT and Haskell.

I am a little surprised that the php community hasn’t glommed on to clearsilver templates

Thanks for the link. Now glommed.

I really like the phrase “Just in Time Code Generation.”

Thanks - hadn’t occurred to me while writing - wonder if it makes the same league as Moore’s Law? Could also make a nice subheading in a book on PHP project management, under “Meeting Client Expectations”…

]]>
By: mlemos http://www.sitepoint.com/blogs/2005/01/06/some-php-generated-with-python/#comment-1705 mlemos Wed, 31 Dec 1969 19:00:00 +0000 856709535#comment-1705 <p>I find it odd, to say the least, suggesting the use another language to generate PHP. It sounds as if PHP can only be used to generate HTML language pages, but not source code in other languages. It is all text after all.</p> <p>PHP generating PHP code is an old story. If you just think of Smarty and most other template compiler engines, you realize that using PHP to generate PHP code has been done for many years now.</p> <p>Smarty concept of compiling templates into executable PHP code was started in <a href="http://news.php.net/php.template/186">this thread of list php-template</a>. If you prefer newsgroup access you may find the thread here:</p> <p><a href="news://news.php.net:119/4598.84T2941T13386538mlemos@acm.org">news://news.php.net:119/4598.84T2941T13386538mlemos@acm.org</a></p> <p>The idea of antecipating template processing to a compile time stage and generate executable PHP code was taken from one of the modules of the <a href="http://www.meta-language.net/">MetaL</a> engine.</p> <p>Smarty generated code is not as efficient as the code generated by the MetaL engine template module but that is another story.</p> <p>Anyway, after Smarty many template compiler engines appeared imitating Smarty's approach, but all were written in PHP.</p> <p>As a side note, regarding the use of the MetaL engine for generating PHP code, <a href="http://www.meta-language.net/metastorage.html">Metastorage</a> is the largest PHP code generator application that I have written based on MetaL.</p> <p>Despite it comprises now about 44,000 lines of code, Metastorage usage is simple, throughly documented, and the gains in productivity and code efficiency and overwhelming because the developer does not have to spend an iternity on tedious jobs like writing repetitive code, testing and debuging manually. </p> <p>I have recently launched the <a href="http://www.phpclasses.org/">PHP Classes support forums</a> using Metastorage to generate classes that act as interfaces to store the forum, threads, messages, subscriptions objects in a persistent storage container (read the MySQL database of the site). I am very happy with the gains in efficiency.</p> <p>Back to the subject, besides template compilers, there are many types of code generators written in PHP. Besides the generators of PHP code listed in CodeGeneration.net, which are not all written in PHP, you may find here <a href="http://www.phpclasses.org/browse/class/90.html">several classes written in PHP to generate PHP code</a> for several purposes.</p> <p>The bottom line is: if you open your eyes and realize that PHP can also be used to generate PHP code, you do not have to learn yet another language and probably write PHP generators more proefficiently.</p> I find it odd, to say the least, suggesting the use another language to generate PHP. It sounds as if PHP can only be used to generate HTML language pages, but not source code in other languages. It is all text after all.

PHP generating PHP code is an old story. If you just think of Smarty and most other template compiler engines, you realize that using PHP to generate PHP code has been done for many years now.

Smarty concept of compiling templates into executable PHP code was started in this thread of list php-template. If you prefer newsgroup access you may find the thread here:

news://news.php.net:119/4598.84T2941T13386538mlemos@acm.org

The idea of antecipating template processing to a compile time stage and generate executable PHP code was taken from one of the modules of the MetaL engine.

Smarty generated code is not as efficient as the code generated by the MetaL engine template module but that is another story.

Anyway, after Smarty many template compiler engines appeared imitating Smarty’s approach, but all were written in PHP.

As a side note, regarding the use of the MetaL engine for generating PHP code, Metastorage is the largest PHP code generator application that I have written based on MetaL.

Despite it comprises now about 44,000 lines of code, Metastorage usage is simple, throughly documented, and the gains in productivity and code efficiency and overwhelming because the developer does not have to spend an iternity on tedious jobs like writing repetitive code, testing and debuging manually.

I have recently launched the PHP Classes support forums using Metastorage to generate classes that act as interfaces to store the forum, threads, messages, subscriptions objects in a persistent storage container (read the MySQL database of the site). I am very happy with the gains in efficiency.

Back to the subject, besides template compilers, there are many types of code generators written in PHP. Besides the generators of PHP code listed in CodeGeneration.net, which are not all written in PHP, you may find here several classes written in PHP to generate PHP code for several purposes.

The bottom line is: if you open your eyes and realize that PHP can also be used to generate PHP code, you do not have to learn yet another language and probably write PHP generators more proefficiently.

]]>
By: akie http://www.sitepoint.com/blogs/2005/01/06/some-php-generated-with-python/#comment-1706 akie Wed, 31 Dec 1969 19:00:00 +0000 856709535#comment-1706 <p>I agree with <b>mlemos</b>. Why Python? PHP has enough power to accomplish such tasks.</p> <p>One quote from you article, Harry :-)<br /> <blockquote><p><br /> Before I go any further I should mention that, as you're probably aware, PHP is not the only choice for writing command line scripts. Both Perl and Python, to name just two, are widely used for writing command line applications and, in many cases, make better a choice than PHP. They provide a mature set of tools for common problems and, typically, better performance.</p></blockquote></p> <p><blockquote><p>So, why use PHP? An obvious -- and very good -- reason may simply be that you know PHP better than the alternatives. Less obvious is that, if you're developing a Web application in PHP, writing supporting scripts in another language can lead to extra headaches -- even if you're confident in both. There's both the human aspect of having to switch programming "mind sets", and the overhead of having to support two platforms and the potential missed opportunities for re-use; data access logic may need to be implemented twice, for example. <br /> http://www.sitepoint.com/article/php-command-line-1</p></blockquote></p> <p><blockquote><p><br /> </p></blockquote></p> I agree with mlemos. Why Python? PHP has enough power to accomplish such tasks.

One quote from you article, Harry :-)

Before I go any further I should mention that, as you’re probably aware, PHP is not the only choice for writing command line scripts. Both Perl and Python, to name just two, are widely used for writing command line applications and, in many cases, make better a choice than PHP. They provide a mature set of tools for common problems and, typically, better performance.

So, why use PHP? An obvious — and very good — reason may simply be that you know PHP better than the alternatives. Less obvious is that, if you’re developing a Web application in PHP, writing supporting scripts in another language can lead to extra headaches — even if you’re confident in both. There’s both the human aspect of having to switch programming “mind sets”, and the overhead of having to support two platforms and the potential missed opportunities for re-use; data access logic may need to be implemented twice, for example.
http://www.sitepoint.com/article/php-command-line-1

]]>
By: lastcraft http://www.sitepoint.com/blogs/2005/01/06/some-php-generated-with-python/#comment-1707 lastcraft Wed, 31 Dec 1969 19:00:00 +0000 856709535#comment-1707 <p>Hi.</p> <p>I actually prefer to write generators in a different langauge if I can. Otherwise escaping special characters which are also special in it's own syntax can become a real nightmare.</p> <p>The Empty use of "@" not clashing with PHP is a good example.</p> <p>Adds to deployment hassles though, and your developers have to be "multilingual" in the programming language sense. Take your pick.</p> <p>yours, Marcus</p> Hi.

I actually prefer to write generators in a different langauge if I can. Otherwise escaping special characters which are also special in it’s own syntax can become a real nightmare.

The Empty use of “@” not clashing with PHP is a good example.

Adds to deployment hassles though, and your developers have to be “multilingual” in the programming language sense. Take your pick.

yours, Marcus

]]>