Pyjamas : Python -> JS

16 views
Skip to first unread message

Kless

unread,
Dec 5, 2008, 6:15:27 AM12/5/08
to pylons-discuss
I've looking for any bridge between python and JS to building easily
the user interfaces (client side). --I dislike JS, and it's heavy to
have to know and deal with HTML, CSS JS and the API of any JS
framework--

Ago time I had seen Pyjamas [1], "a stand-alone python to javascript
compiler, an AJAX framework / library and a Widget set API." It
already has been released a stable version (0.4)

I found a great article [2] about it and in general about programming
on client side. What do think about pyjamas? I think that would be
fantastic developing all web application into a same language, in
addition it could speed up enought the time on developing.

I would to know if Pyjamas could be easily integrated on Pylons.


[1] http://pyjamas.sourceforge.net/
[2] http://advogato.org/article/993.html

John_Nowlan

unread,
Dec 5, 2008, 11:44:05 AM12/5/08
to pylons-discuss

Jorge Vargas

unread,
Dec 5, 2008, 12:05:54 PM12/5/08
to pylons-...@googlegroups.com
On Fri, Dec 5, 2008 at 5:15 AM, Kless <jona...@googlemail.com> wrote:
>
> I've looking for any bridge between python and JS to building easily
> the user interfaces (client side). --I dislike JS, and it's heavy to
> have to know and deal with HTML, CSS JS and the API of any JS
> framework--
>
> Ago time I had seen Pyjamas [1], "a stand-alone python to javascript
> compiler, an AJAX framework / library and a Widget set API." It
> already has been released a stable version (0.4)
>
Even though I agree with you on principle, JS sucks (runtimes not the
language) and having to sync your code across 4-5 files sucks. I don't
think this is the right solution, code generation is at best ugly, at
worst totally useless.

That said it's a valid alternative and some applications may benefit from it.

Eric Ongerth

unread,
Dec 5, 2008, 10:22:23 PM12/5/08
to pylons-discuss
I have heard that the more you try to make Javascript behave like
Python, the more you end up hating Javascript -- but that says nothing
about Javascript itself. Javascript is really a different language,
with different strengths. Perhaps the best plan is to use Javascript
for its strongest points (for example instant-turnkey use of JSON,
totally anonymous objects, function mutability, etc.) and do your more
Pythonic tasks in Python. Pylons makes it quite easy to leave as much
of your logic as you wish in your controllers and keep your client-
side view code very very thin. Especially if you use a lightweight,
concise JS framework like jQuery to help keep things readable and
organized.

That still leaves the case of the programmer who says, "I want to keep
as much logic as possible on the client side to ease my server load,
but I hate Javascript". In that case I don't have any good advice.

Intuition suggests to me that by the time you finish developing a user
interface in python compiled to javascript, this strategy could
backfire when it comes to the effort required for maintaining it, and/
or the potential for keeping it as lightweight as possible. I could
certainly be wrong, having never put Pyjamas to the test.

Don't get me wrong; I think Pyjamas is a great idea, and if someone
weren't developing it, then someone else would have needed to invent
it too. However, I want to quote the following from the pyjamas
website:

<quote>
Why should I use it?

You can write web applications in python - a readable programming
language - instead of in HTML and Javascript, both of which become
quickly unreadable for even medium-sized applications. Your
application's design can benefit from encapsulating high level
concepts into classes and modules (instead of trying to fit as much
HTML as you can stand into one page); you can reuse - and import -
classes and modules.
</quote>

The claim that Javascript "become[s] quickly unreadable for even
medium-sized applications" really reflects only on the individual
programmer/developer and not on the language, honestly. Javascript
does not deserve to be compared to (e.g.) php, an unruly beast that
literally encourages a mess. Javascript is, at worst, neutral with
respect to organization; at best it embodies the heights of
abstraction, encapsulation, and readability. It's all up to you.

But if you don't like Javascript, you have plenty of company.
Including myself somewhat recently before I studied it more thoroughly
and started trying harder with it ;-)

Good luck in any event.

Wichert Akkerman

unread,
Dec 6, 2008, 4:39:00 AM12/6/08
to pylons-...@googlegroups.com
Previously Eric Ongerth wrote:
> I have heard that the more you try to make Javascript behave like
> Python, the more you end up hating Javascript -- but that says nothing
> about Javascript itself. Javascript is really a different language,
> with different strengths. Perhaps the best plan is to use Javascript
> for its strongest points (for example instant-turnkey use of JSON,
> totally anonymous objects, function mutability, etc.) and do your more
> Pythonic tasks in Python. Pylons makes it quite easy to leave as much
> of your logic as you wish in your controllers and keep your client-
> side view code very very thin. Especially if you use a lightweight,
> concise JS framework like jQuery to help keep things readable and
> organized.
>
> That still leaves the case of the programmer who says, "I want to keep
> as much logic as possible on the client side to ease my server load,
> but I hate Javascript". In that case I don't have any good advice.

Choose a new carreer :)

> The claim that Javascript "become[s] quickly unreadable for even
> medium-sized applications" really reflects only on the individual
> programmer/developer and not on the language, honestly. Javascript
> does not deserve to be compared to (e.g.) php, an unruly beast that
> literally encourages a mess. Javascript is, at worst, neutral with
> respect to organization; at best it embodies the heights of
> abstraction, encapsulation, and readability. It's all up to you.

A problem with javascript is that most people using it never get beyond
writing tiny bits of code to perform a single effect on a page. With new
frameworks making that even simpler that is even more true now than it
was a few years ago. But once you get beyond that you will indeed see
that javascript is a very nice and fun language.

Wichert.

--
Wichert Akkerman <wic...@wiggy.net> It is simple to make things.
http://www.wiggy.net/ It is hard to make things simple.

Kless

unread,
Dec 6, 2008, 5:14:57 AM12/6/08
to pylons-discuss
On 6 dic, 03:22, Eric Ongerth <ericonge...@gmail.com> wrote:
> But if you don't like Javascript, you have plenty of company.
> Including myself somewhat recently before I studied it more thoroughly
> and started trying harder with it ;-)
>
Well, I hope that any day Lua can be embedded in the browser. I'm not
the only person that think about it, and nobody should doubt about its
better performance [1].

By the way, there is an interesting project that will allow Firefox
extensions to be developed using Lua code rather than JavaScript [2].
It's possible that this been a single step to get it.


[1] http://www.cycling74.com/forums/index.php?t=tree&th=28641&rid=0

[2] http://code.google.com/p/mshine/
http://mshine.luaforge.net/

Wichert Akkerman

unread,
Dec 6, 2008, 5:21:06 AM12/6/08
to pylons-...@googlegroups.com
Previously Kless wrote:
> On 6 dic, 03:22, Eric Ongerth <ericonge...@gmail.com> wrote:
> > But if you don't like Javascript, you have plenty of company.
> > Including myself somewhat recently before I studied it more thoroughly
> > and started trying harder with it ;-)
> >
> Well, I hope that any day Lua can be embedded in the browser. I'm not
> the only person that think about it, and nobody should doubt about its
> better performance [1].

Unfortunately in the world of browsers you can not use something until
enough browsers support it. That is why we are still bound by the
capabilities of IE6 even now.

Jorge Vargas

unread,
Dec 6, 2008, 8:36:05 AM12/6/08
to pylons-...@googlegroups.com
On Sat, Dec 6, 2008 at 3:39 AM, Wichert Akkerman <wic...@wiggy.net> wrote:
>
> Previously Eric Ongerth wrote:
>> I have heard that the more you try to make Javascript behave like
>> Python, the more you end up hating Javascript -- but that says nothing
>> about Javascript itself. Javascript is really a different language,
>> with different strengths. Perhaps the best plan is to use Javascript
>> for its strongest points (for example instant-turnkey use of JSON,
>> totally anonymous objects, function mutability, etc.) and do your more
>> Pythonic tasks in Python. Pylons makes it quite easy to leave as much
>> of your logic as you wish in your controllers and keep your client-
>> side view code very very thin. Especially if you use a lightweight,
>> concise JS framework like jQuery to help keep things readable and
>> organized.
>>
>> That still leaves the case of the programmer who says, "I want to keep
>> as much logic as possible on the client side to ease my server load,
>> but I hate Javascript". In that case I don't have any good advice.
>
> Choose a new carreer :)
>
indeed

>> The claim that Javascript "become[s] quickly unreadable for even
>> medium-sized applications" really reflects only on the individual
>> programmer/developer and not on the language, honestly. Javascript
>> does not deserve to be compared to (e.g.) php, an unruly beast that
>> literally encourages a mess. Javascript is, at worst, neutral with
>> respect to organization; at best it embodies the heights of
>> abstraction, encapsulation, and readability. It's all up to you.
>
> A problem with javascript is that most people using it never get beyond
> writing tiny bits of code to perform a single effect on a page. With new
> frameworks making that even simpler that is even more true now than it
> was a few years ago. But once you get beyond that you will indeed see
> that javascript is a very nice and fun language.
>

I actually disagree there, javascript (IE the spec and all non-browser
interpreters) is a very nice language, just as nice as python and
sometimes a bit better with some of it's tricks. But the problem is
when it comes to implementations all those libraries are there because
it's totally horrible to get all the tiny details fixed. The other big
problem with JS is that it's bound to the browser therefore the dom
therefore you have to have wrappers around everything to make it work.
So basically most people are afraid of it, rather than amused.

That said I really think a JS wrapper in JS is better than a JS
wrapper in python or whatever language for that matter. Any DSL which
is pretty much what all the libraries have become is way better than
having a half baked parser/compiler/runtime to generate code from
language A into language B

Lawrence Oluyede

unread,
Dec 6, 2008, 8:48:21 AM12/6/08
to pylons-...@googlegroups.com
On Sat, Dec 6, 2008 at 2:36 PM, Jorge Vargas <jorge....@gmail.com> wrote:
> That said I really think a JS wrapper in JS is better than a JS
> wrapper in python or whatever language for that matter. Any DSL which
> is pretty much what all the libraries have become is way better than
> having a half baked parser/compiler/runtime to generate code from
> language A into language B

I strongly agree. This is one huge case of leaky abstractions in my opinion.
By the way, John Resig (jQuery's author) has a take on this:
<http://ejohn.org/blog/javascript-language-abstractions/>


--
Lawrence, www.neropercaso.it - oluyede.org
"It is difficult to get a man to understand
something when his salary depends on not
understanding it" - Upton Sinclair

Jens Hoffrichter

unread,
Dec 7, 2008, 1:34:26 AM12/7/08
to pylons-...@googlegroups.com
Hello all,

2008/12/6 Lawrence Oluyede <l.ol...@gmail.com>:


>
> On Sat, Dec 6, 2008 at 2:36 PM, Jorge Vargas <jorge....@gmail.com> wrote:
>> That said I really think a JS wrapper in JS is better than a JS
>> wrapper in python or whatever language for that matter. Any DSL which
>> is pretty much what all the libraries have become is way better than
>> having a half baked parser/compiler/runtime to generate code from
>> language A into language B
>
> I strongly agree. This is one huge case of leaky abstractions in my opinion.
> By the way, John Resig (jQuery's author) has a take on this:
> <http://ejohn.org/blog/javascript-language-abstractions/>

Thanks for that interesting link, it was a read which triggered some thoughts.

I've seen the latest pyjamas announcement on freshmeat, looked at it
and thought: Oh, this looks nice, maybe give it a try.

Up to now, I haven't come around to do so, but I definitely will at
least take a bit of time and look what it can to and can't.

The thing which really triggered my thoughts was a statement in one of
the comments:

"How would an Assembler or C developer have looked at code generators
10 - 20 years ago?"

And that is a comparison that feels somehow fitting. Yes, of course
are solutions you write in ASM or C 10-20 times faster than anything
written in an interpreted language. Yes, they are smaller and more
elegant. But why are the demands of the market for ASM or C developers
decreasing now, and if you look at job adverts, most jobs are for a
higher level language...

Because it is just a lot more productive writing code in Python or
Ruby or even Java, than doing it in plain C or even Assembler. Yes,
with some good libraries, you can speed up the development process in
C quite a bit, but it still isn't as fast as going with a language
like Python in the first place (at least that is what my experience
suggests).

Still, there are things which are absolutely viable to implement in C,
and either use them as a library, or just glue them together in a
higher language....

And if you translate that onto a JS code generator, I think that that
might be a route we possibly will see: Prototype and develop your
stuff in one of the higher level abstraction tools (like GWT or
pyjamas), and only handtune or handwrite the real critial stuff in
direct JS.

It might work *shrug*

But, as I said, I haven't yet really played around with any of those
toolkits, but I definitely want to give it a try :)

Jens

Lawrence Oluyede

unread,
Dec 7, 2008, 9:19:51 AM12/7/08
to pylons-...@googlegroups.com
On Sun, Dec 7, 2008 at 7:34 AM, Jens Hoffrichter
<jens.hof...@gmail.com> wrote:
> Because it is just a lot more productive writing code in Python or
> Ruby or even Java, than doing it in plain C or even Assembler. Yes,
> with some good libraries, you can speed up the development process in
> C quite a bit, but it still isn't as fast as going with a language
> like Python in the first place (at least that is what my experience
> suggests).

This make really sense but applied from a lower level language to a
higher level one. You don't write a Haskell code generator in Erlang
because you feel more comfortable using the Erlang toolset and VM. You
write in Haskell because you need/like Haskell. Despite some people
think
JavaScript is not a bad language, is the world around it that is not
as good as we'd like it to be.
But JavaScript is the heart of the scripting of many browsers and it's
a dynamic language at the same level as Python, Ruby or whatever. I
think that the best way to learn and develop in JavaScript is to learn
it, master it, read about it, experiment with it, get a library for it
and so on. You notice how many times I used *it* and not "something
else" :D ?

Pyjamas (and GWT) is a fine idea but in my opinion has been conceived
for the wrong reasons.

Reply all
Reply to author
Forward
0 new messages