Compiler and PHP questions

Joe Armstrong (AL/EAB) <>
Tue Nov 29 15:18:12 CET 2005



> -----Original Message-----
> From: 
> [mailto:]On Behalf Of Marc 
> van Woerkom
> Sent: den 29 november 2005 13:45
> To: 
> Subject: Re: Compiler and PHP questions
> 
> 
> >1) Does anybody have or is anybody working on a parser 
> >for php written in erlang - please contact me
> >    if this is the case.
> 
> I would love to know about this too, as I use PHP for my 
> present day job. :)
> 
> BTW Perl 6 seems to get implemented in Haskell first:
> 
>    http://www.perl.com/pub/a/2005/03/03/pugs_interview.html
> 
> 
> > <h1>title</h1>
> > <p>hello <? getDb "name") ?> how are you
> 
> Putting code fragments into HTML is not a good style for 
> developing (larger) web applications.

   Oh - why not? - here are two alternatives:

Template A

	<h1>hello</h1>
	<p>My name is ${name} is live in ...

Then you say (essentially)

	Let name = get_db("name", UserId) in
	template A

or

template B

	<h1>hello</h1>
	<p> my name is <? get_db("name", UseriD) ?>

The problem with A IS that have to do all computations *outside* the template.

A lot of my template involve messing around with pixel sizes. So if the width
of an image is X pixels I need a left-margin of X-2 pixels etc.

In style A I would have to say

	let x = 600 (say)
	    x1 = 600 - 2,
	 in
	    template1

Where template 1 has variables x and x1

If I use function calls I can minimise the number of arguments and do computations on them

	template2
	
	<style>
	div.h1 { left-magin: <? out(X-2) ?> }
	   ...
	</style>

etc.

When I counted the number of arguments flowing into the template I needed far fewer
when I can embed function calls in the template, than without.

Actually to save arguments I will support both styles :-)

But I do not see why it is not good style. Good style to me
would be to minimise the number of arguments that have to flow
into a template and strictly specify their types


> 
> This has to do with the typical team structure / division 
> of labour for web teams:
> - the web developers do the pure php/perl/.. script code
> - the screen designers rule the template files
> - the backend folks deliver methods to feed/query the 
> backend databases

Wow - web teams - whatever will they think of next - 
> 
> For php we use the smarty template engine.
> 
> A template is instantiated and fed with variable data by 
> the web application.
> The template file contains mainly html/css/javascript and

So why is it bad style to have inline code in one language in the template
but OK to have inline code in a different language (ie javascript) in the template?

> has just extra support for conditional code activiation, 
> data access (just to the provided variable data) and 
> simple repetition control, all in a HTML like syntax.
> 

Yuck - IMHO If you're going to have a language have a language but not
some weirdo ad hock collection of features with HTML syntax.


> A web developer delivers just a plain template file as 
> result of his work, a template file that just renders the 
> web page in minimal stylish fashion, with all access to 
> the internal vars provided.

But I'll guess they have to invent extra variables, 
and things that should be local function calls become external code.

	Me I'd write:

	<p> factorial <? N ?> is <? fac(N) ?>

	And do the computation in-place

	With a template I'd need an extra variable

	<p> factorial ${n} is ${facn}

	and the code to do the computation would not be near the place where it is used
(a sure source of error) 


> 
> This is then fed to the screen designers who use their 
> javascript and DHTML magic to pimp it up.

	Too low level. The javascript and DHTL should be generated on the fly from  higher order
functions. I've played with javascript a bit. My web pages just do eval(Str) and Str I create
on-the-fly.

> 
> Regards,
> Marc
> 

/Joe



More information about the erlang-questions mailing list