single-source AJAX applications?

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

single-source AJAX applications?

Rasmus Schultz
Just a thought.

And this may be a bad idea, impossible, or even crazy :-)

Anyhow - haxe enables you to write the server-side and client-side code
for an application, in the same language, which is amazing. But so, how
about enhancing the language, so that an application could be written as
a single source? All of the client-side code and server-side code, in a
single program?

So then, compiling your single source would compile to, for example,
both a JavaScript and a PHP script - and the AJAX interactions required
to make the two work together would automatically be implemented...

For example, if I wrote an application that fetches a number of employee
records from a database, the SQL query would be implemented server-side,
and automatically exposed via some AJAX interface, probably JSON.

So you would need to be able to somehow specify whether a function (or
perhaps a class, I haven't thought this through) executes on the
client-side or on the server-side. So, when I do something like
Employees::getAll() on the clientside, invoking what is really a
server-side script, the client-side script would automatically branch
out and implement the remainder of my client-side function as a new
function, and invoke this in a callback, when the server-generated
response becomes available.

Essentially, you could then finally think of these two-headed beasts
(AJAX-based applications) as being a single application - which is
essentially just what they are... The interesting part of AJAX
applications is not figuring out how or when to send data back and forth
- if this part could be automated, it would give you the freedom to
focus on real business logic, not wasting time on lots of data-transport
and timing issues.

I've seen a JavaScript pre-compiler (don't remember it's name), that
lets you write javascript without worrying about these issues, so I know
for a fact that this part is possible; it would automatically branch
functions into new functions as required, resuming the second half of a
function after an AJAX call completes...

Part of this would already be possible with Haxe, as it is ... using
conditionals, and compiling the same source twice.

But anyhow. Any thoughts on this idea? Would it work? Why/not?

--

Rasmus Schultz
/Sr. Application Developer/
*Gorges Web Sites
Office:* (607) 273-3828 (ext. 20)
*Web:* http://www.GorgesWebSites.com <http://www.gorgeswebsites.com/>
*Email:* [hidden email] <mailto:[hidden email]>


--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: single-source AJAX applications?

Justin Donaldson
You can do this with conditional compilation:
http://haxe.org/ref/conditionals

Also, using the --next command in the haxe compiler will let you specify more than one target/source per compile.

Related to your example, I've been thinking about how to make client requests for arbitrary remote information as painless as possible.  For the client side web based VM's (javascript, flash), this will mean setting up some kind of proxy php script on the server that is hosting them.  The problem is that the SWF/JS file will not know the eventual location of the PHP proxy file that it is paired with (unless you hardcode it specifically.) 

One way around this would be to compile the PHP first, run it and save the result from phpinfo() or $_SERVER['HTTP_HOST'].  Then you could pass this information somehow to the compile command for the SWF.

Maybe some other people out there have thoughts/ideas about this...

Best,
-Justin



On Tue, Nov 4, 2008 at 2:25 PM, Rasmus Schultz <[hidden email]> wrote:
Just a thought.

And this may be a bad idea, impossible, or even crazy :-)

Anyhow - haxe enables you to write the server-side and client-side code for an application, in the same language, which is amazing. But so, how about enhancing the language, so that an application could be written as a single source? All of the client-side code and server-side code, in a single program?

So then, compiling your single source would compile to, for example, both a JavaScript and a PHP script - and the AJAX interactions required to make the two work together would automatically be implemented...

For example, if I wrote an application that fetches a number of employee records from a database, the SQL query would be implemented server-side, and automatically exposed via some AJAX interface, probably JSON.

So you would need to be able to somehow specify whether a function (or perhaps a class, I haven't thought this through) executes on the client-side or on the server-side. So, when I do something like Employees::getAll() on the clientside, invoking what is really a server-side script, the client-side script would automatically branch out and implement the remainder of my client-side function as a new function, and invoke this in a callback, when the server-generated response becomes available.

Essentially, you could then finally think of these two-headed beasts (AJAX-based applications) as being a single application - which is essentially just what they are... The interesting part of AJAX applications is not figuring out how or when to send data back and forth - if this part could be automated, it would give you the freedom to focus on real business logic, not wasting time on lots of data-transport and timing issues.

I've seen a JavaScript pre-compiler (don't remember it's name), that lets you write javascript without worrying about these issues, so I know for a fact that this part is possible; it would automatically branch functions into new functions as required, resuming the second half of a function after an AJAX call completes...

Part of this would already be possible with Haxe, as it is ... using conditionals, and compiling the same source twice.

But anyhow. Any thoughts on this idea? Would it work? Why/not?

--

Rasmus Schultz
/Sr. Application Developer/
*Gorges Web Sites
Office:* (607) 273-3828 (ext. 20)
*Web:* http://www.GorgesWebSites.com <http://www.gorgeswebsites.com/>
*Email:* [hidden email] <mailto:[hidden email]>


--
haXe - an open source web programming language
http://haxe.org



--
Justin Donaldson
PhD Candidate, Informatics
Indiana University
http://www.scwn.net

--
haXe - an open source web programming language
http://haxe.org