Beta
×

Welcome to the Slashdot Beta site -- learn more here. Use the link in the footer or click here to return to the Classic version of Slashdot.

Thank you!

Before you choose to head back to the Classic look of the site, we'd appreciate it if you share your thoughts on the Beta; your feedback is what drives our ongoing development.

Beta is different and we value you taking the time to try it out. Please take a look at the changes we've made in Beta and  learn more about it. Thanks for reading, and for making the site better!

Python Converted To JavaScript, Executed In-Browser

Soulskill posted more than 5 years ago | from the hey-why-not dept.

Programming 176

lkcl writes "Two independent projects, Skulpt and Pyjamas, are working to bring Python to the web browser (and the JavaScript command-line) the hard way: as JavaScript. Skulpt already has a cool Python prompt demo on its homepage; Pyjamas has a gwtcanvas demo port and a GChart 2.6 demo port. Using the 64-bit version of Google v8 and PyV8, Pyjamas has just recently and successfully run its Python regression tests, converted to JavaScript, at the command-line. (Note: don't try any of the above SVG demos with FF2 or IE6; they will suck.)"

Sorry! There are no comments related to the filter you selected.

python sucks (-1, Flamebait)

Anonymous Coward | more than 5 years ago | (#29476223)

To quote Austin Powers: "Why won't you die?"

PHP rulez.

Re:python sucks (1)

digitalunity (19107) | more than 5 years ago | (#29476241)

Fortran is better. You're doing it wrong.

Re:python sucks (5, Funny)

master5o1 (1068594) | more than 5 years ago | (#29476283)

Because it's done like this:
<?php
die(Python);
?>

Re:python sucks (0)

Anonymous Coward | more than 5 years ago | (#29476443)

var mydingaling = document.createElement('select');
mydingaling.setAttribute('multple','multiple');
mydingaling.options.add( document.createElement('option').text = 'i want to play with my dingaling';

Doesn't javascript allow you to the majority of what was set forth as canonical in Lisp?

In related news.... (5, Funny)

mrops (927562) | more than 5 years ago | (#29476647)

...they used a Perl script to convert Python to Javascript.

Re:python sucks (1)

Jane_Dozey (759010) | more than 5 years ago | (#29476725)

Pfft! Python makes it easy:

import suicide-python

Re:python sucks (1)

Hurricane78 (562437) | more than 5 years ago | (#29476963)

Which, according to the "great" auto-conversion of PHP would print the string "Python" before exiting, because it converts unknown constant names to strings. If you put a "define("Python",0xFA1);" in above the die(), it will print the integer "4001" and return it as an errorlevel. If you instead use "define("Python",0xFA1.L);", it will just print "4001L" and not return it as an errorlevel.

That is, why "easier" is not always easier, but sometimes actually harder. The reason why we can't stand Clippy. The reason some can't stand many Microsoft or Apple products at all. (And many other "so easy an idiot could do it (but actually only an idiot still can do it!)" products. It'shalf the reason people have problems with computers nowadays.
And why the resulting idiocy of auto-typecasting is one of the biggest failures in programming language design ever. ^^

P.S.: Haskell FTW! ;)

Re:python sucks (1)

Blakey Rat (99501) | more than 5 years ago | (#29477035)

Jesus Christ, man. It was a joke!

@import sense_of_humor;

And Microsoft removed Clippy like a fucking DECADE ago, get over it already.

Re:python sucks (0)

Anonymous Coward | more than 5 years ago | (#29476311)

To quote Austin Powers: "Why won't you die?" PHP rulez.

To paraphrase Fyodor Mikhailovich Dostoevsky: "Why should such a troll live?"

Oh whatever.

Re:python sucks (1)

chrysalis (50680) | more than 5 years ago | (#29476451)

Ahaha you're so funny.

Now, GOTO \your_namespace because $this->is_off_topic(TRUE == "FALSE");

Re:python sucks (1)

Ant P. (974313) | more than 5 years ago | (#29476457)

AAAHHHHHHH! It burns!

Re:python sucks (3, Interesting)

the_humeister (922869) | more than 5 years ago | (#29476579)

I prefer a javascript assembler [ajaxian.com]

Re:python sucks (4, Interesting)

the_humeister (922869) | more than 5 years ago | (#29476779)

Found something better: 6502 assembler! [6502asm.com]

Re:python sucks (1)

bennomatic (691188) | more than 5 years ago | (#29478107)

Nice.

Re:python sucks (1)

John Betonschaar (178617) | more than 5 years ago | (#29478201)

That's pretty cool actually :-D

Re:python sucks (1)

Hal_Porter (817932) | more than 5 years ago | (#29477327)

It has been first converted to Javascript, then executed.

Cruel and unusual perhaps, but it is certainly dead now.

Re:python sucks (0)

Anonymous Coward | more than 5 years ago | (#29477815)

Python was created based on the philosophy:
  "Well, the only reason people don't like Lisp is because of all the parenthesis"
and, for good measure:
  "And Lisp-people don't like curly-braces, so let's not use them, either"

second post (-1, Troll)

Anonymous Coward | more than 5 years ago | (#29476243)

all you python fanboys can eat out my asshole.

Python=great, SVG=great, better examples soon ? (-1, Redundant)

Anonymous Coward | more than 5 years ago | (#29476253)

I'll look into it later, maybe donate better examples.

AS IF (1, Informative)

Anonymous Coward | more than 5 years ago | (#29476291)

Using python to GENERATE JavaScript, not python converted

Why, God, why???? (-1, Flamebait)

Anonymous Coward | more than 5 years ago | (#29476301)

What a waste of time and energy. The only thing worse than Python is, well, Javascript.

Kudos for turning shit to sludge.

Re:Why, God, why???? (2, Insightful)

mcvos (645701) | more than 5 years ago | (#29476351)

What a waste of time and energy. The only thing worse than Python is, well, Javascript.

That is exactly the whole point that you're so obviously missing here: nobody sane should have to write Javascript, and yet it's the only thing that's supported by browsers. So converting code from other languages to Javascript is the only sensible solution at the moment. (For the longer term, it'd be nice if they replaced Javascript with something halfway sane.)

Re:Why, God, why???? (4, Interesting)

bcboy (4794) | more than 5 years ago | (#29476839)

I felt the same way until I watched Douglas Crockford's videos on javascript. If you hate javascript, you're doing it wrong. I now prefer it to the other languages being discussed here.

Re:Why, God, why???? (5, Insightful)

timeOday (582209) | more than 5 years ago | (#29476441)

The only thing worse than Python is, well, Javascript.

I'd be interested to hear what you like better, and why? Personally I'm still sad that Java (not Javascript) didn't win on the Web - a cross-platform, general purpose language that is at least a reasonable choice for most anything. To make programming faster, you can always use higher-level libraries or code-building environments on top of it, or compile some other syntax to java bytecode.

Now instead the Web is a big mish-mash of fundamentally incompatible technologies. And if anybody does pull off the one-runtime-for-anything vision, it looks like it will be Microsoft.

Re:Why, God, why???? (2, Interesting)

onefriedrice (1171917) | more than 5 years ago | (#29477029)

Well, haXe [haxe.org] is a Java-like language which compiles to Javascript among other languages. It's definitely general purpose enough to use in the client as well as the back-end, and it has nice libraries which make communication between them easy. It happens to compile to Flash, too. I'd imagine that any reasonably complex project could be built just about entirely in haXe.

Re:Why, God, why???? (1)

MobyDisk (75490) | more than 5 years ago | (#29478341)

What this tells us is that we didn't need a standard web-language. We needed a standard web virtual machine. I guess, the JRE and Flash really are those things. Javascript really isn't.

Re:Why, God, why???? (1)

FlyingBishop (1293238) | more than 5 years ago | (#29477383)

Coincidentally, that's exactly why Microsoft has the least secure operating system on the planet.

Motherfucking snakes in a motherfucking browser? (-1, Offtopic)

Anonymous Coward | more than 5 years ago | (#29476307)

I've had it!

Pointless (1)

Mystra_x64 (1108487) | more than 5 years ago | (#29476319)

Seems pretty pointless. Either learn a language or drop it.

I'd prefer native Ruby in browser though.

Re:Pointless (3, Informative)

chrysalis (50680) | more than 5 years ago | (#29476431)

There is already a Ruby VM that runs in a browser: Hotruby : http://hotruby.yukoba.jp/ [yukoba.jp]

John Resig even blogged about it ages ago: http://ejohn.org/blog/ruby-vm-in-javascript/ [ejohn.org]

Also, JS.class, while not a Ruby VM, is pretty cool and actually useful: http://blog.jcoglan.com/2009/06/08/jsclass-21-an-improved-pacakge-manager-proper-hashes-and-lots-of-ruby-19-goodness/ [jcoglan.com] - http://ajaxian.com/archives/jsclass-21-released [ajaxian.com]

Re:Pointless (1)

Mystra_x64 (1108487) | more than 5 years ago | (#29476973)

I maybe slept under a rock or something... I'll look there, thanks.

Re:Pointless (0)

Anonymous Coward | more than 5 years ago | (#29477231)

As if browsing wasn't already slow enough.

Re:Pointless (1)

Mystra_x64 (1108487) | more than 5 years ago | (#29477451)

I don't even turn Javascript on, so it *is* fast. Besides Ruby 1.9 is way faster than 1.8.

GWT for Python? (2, Interesting)

mcvos (645701) | more than 5 years ago | (#29476331)

It's not entirely clear to me what Skulpt is exactly, but Pyjamas is apparently GWT ported to Python, which sounds like a really cool idea. Now if somebody did the same thing with Ruby and Scala, I'd be really happy.

Javascript is just way too stupid to program manually, but currently we're in the odd situation where we're writing server stuff in Ruby, and browser stuff in Java. That's just wrong.

Re:GWT for Python? (3, Informative)

lkcl (517947) | more than 5 years ago | (#29476427)

you're looking for RubyJS [rubyforge.org] . sadly, funding has not been forthcoming in order to carry RubyJS forward. the compiler is excellent; the insights into the technical issues behind dynamic language translation were very useful (even to python translator developers) - but martin ran out of time/money/enthusiasm due to the lack of interest shown, so he only got as far as creating HTML and Button for RWT (Ruby Web Toolkit).

Re:GWT for Python? (1, Informative)

Anonymous Coward | more than 5 years ago | (#29476555)

Exactly how is JS "way too stupid" to program manually? JS suffers from the problem that everyone thinks they're a rockstar at it, and that it's a language doomed to onmouseover="this.style.backgroundColor='#FF0000'". It's not, and there is amazingly complex stuff out there written in JS. It has features languages like PHP can't even dream of.
It has been abused for years, and as such ignorant people have the opinion that it's just a toy language, when really it's incredibly powerful. You don't need a framework or a translator to write JS, same as you don't need one to write C. Learn the language, and you'll see it's not hard to program complicated stuff in it.

Look at Ext.js, Processing.js, and YUI, and tell me JS is "just way too stupid to program manually".

Re:GWT for Python? (1)

John Betonschaar (178617) | more than 5 years ago | (#29478305)

It has been abused for years, and as such ignorant people have the opinion that it's just a toy language, when really it's incredibly powerful.

Maybe the fact that it's so easily abused, used as a toy language out of ignorance, and that the stuff written in it is mostly badly-written crap that doesn't use it's incredibly powerful features already shows why you might say it's way too stupid to program manually.

Re:GWT for Python? (2, Interesting)

loufoque (1400831) | more than 5 years ago | (#29476695)

Javascript is just way too stupid to program manually

Not more than Ruby or Python.
Don't confuse languages with libraries.

Re:GWT for Python? (1, Insightful)

Xtravar (725372) | more than 5 years ago | (#29477761)

Eh, a language is only as good as its standard library. I don't like telling people to download/build/install a number of other libraries of specific versions just to run/build my stupid application.

It's just a fact of life. For personal applications (where it's hard enough to get people to use your app anyway) and work applications (where licensing causes multiple headaches on this front).

And no, I don't use Ruby, Python, or Javascript so I can't comment on any of their libraries.

Nice to have (0)

Anonymous Coward | more than 5 years ago | (#29476365)

I write python webapps and sometimes there are things I'd love to do in the browser but can't. For example using pypdf or reportlab browser-side would be really useful .

How about a Javascript - to - python convertor? (2, Insightful)

ggpauly (263626) | more than 5 years ago | (#29476375)

In most ways (no explicit integer type being an exception) Javascript is a remarkable and beautiful language [crockford.com] . It has libraries available on a server near you through Dojo, among others. Javascript is one of the best things about browsers.

What browsers need is a workable CSS and DOM interface (although the DOM interface has improved in recent years). But these are not issues with Javascript per se. Cleaning up the browser programming environment is not about getting rid of Javascript.

From TFA: """
anyway, just thought there might be people who would be intrigued (or
horrified enough to care what's being done in the name of computer
science) by either of these projects.
"""

Not horrified, but I wonder if W3C politics is creating unforeseen consequences.

Re:How about a Javascript - to - python convertor? (0)

Anonymous Coward | more than 5 years ago | (#29476479)

In most ways (no explicit integer type being an exception) Javascript is a remarkable and beautiful language.

Sort of. It actually sucks, just look at the gigantic EMCA specification and all the convoluted crap in Javascript. The semantics are nice though. The thing is, Lua [lua.org] also has these beautiful semantics and is actually quite similar to Javascript. EXCEPT, Lua actually is beautiful. Very tiny, easy to embed, easy to extends, fast, powerful, simple specification. All that and it does practically the same thing as Javascript. Lua is what Javascript should have been.

Re:How about a Javascript - to - python convertor? (4, Insightful)

s4m7 (519684) | more than 5 years ago | (#29476521)

Cleaning up the browser programming environment is not about getting rid of Javascript.

Maybe not, but javascript is not a good language, it's a bad language with some good features. The awful scoping mechanism is evidence of this enough. The intrinsic objects are too limited to be useful, so much so that now there are more than 4 different common framework projects to handle all the inconsistency in implementation and they're all incompatible with each other. anonymous functions are great but they make debugging a giant pain the arse.

i would like to see a viable alternative language to javascript, just for variety's sake. It's just had layers of crap pasted on top of it since 1995 or whatever and it'd be nice to see a new approach that fits what people actually use it for these days.

Re:How about a Javascript - to - python convertor? (4, Informative)

ggpauly (263626) | more than 5 years ago | (#29476947)

The link to Douglas Crockford's site in the parent was to an article entitled "The World's Most Misunderstood Programming Language".

The awful scoping mechanism

From the brief survey of Javascript [crockford.com] on Crockford's site:
"""
When used inside of a function, var defines variables with function-scope. The vars are not accessible from outside of the function. There is no other granularity of scope in JavaScript. In particular, there is no block-scope.
"""
iow, use the var keyword. Programmers who do not know this ONE RULE (TM) are bitten by mysterious insects. Use a lint program if needed.

Functions are objects in Javascript, so this effectively allows, in either functional or object styles of programming, programmers to freely and simply define their variable scoping.

Procedural programmers used to simple block scoping (Hi COBOL fans!) may need to find a mechanism to cope with this. But I'd suggest using OO techniques if your program is complex enough that this is a problem. Javascript allows simple, non-demanding OO. If you like your OO authoritarian then Google has a Java-to-javascript translator.

intrinsic objects are too limited to be useful, so much so that now there are more than 4 different common framework projects

Python has one official library (and many 'unofficial' modules too), without which Python would be very limited. Javascript has many unofficial libraries. Welcome to the free world.

btw, I use Python, and I get Twisted Python at least to some extent. Twisted's deferred abstraction is mimicked in Dojo Javascript. I use Python on the server and Javascript + Dojo on the browser. Python has less warts and more modules. Javascript has astounding power in simplicity, as in the scoping rule.

Re:How about a Javascript - to - python convertor? (1)

omuls are tasty (1321759) | more than 5 years ago | (#29477157)

On the surface, JS is a really nice language, but it really has a fair share of warts which will bite you. And yes, I'm aware that Javascript is neither DOM nor CSS. For those interested, Bob Ippolito (the author of MochiKit) wrote the best "Javascript sucks" [pythonmac.org] article I've ever read.

Re:How about a Javascript - to - python convertor? (1)

s4m7 (519684) | more than 5 years ago | (#29477747)

yes I know about the var keyword and use it quite religiously. However let me give a specific example of how crappy the JS scope rules are.

I can globally scope a variable in JS, let's call it foo. If I am a sloppy programmer and write a function accessing a variable named foo without var'ing it within that function, it will access the global var unless foo is an argument for my function.

oh crap but it's worse because my functions are objects. So i can have a function foo() and a variable foo as properties of the same class and just have to be careful which one i mean in which context. And then, I can always assign the function foo() to the variable foo, and if i still have it declared globally, i have to make sure and use the right context.

speaking of context, take a look at any of the frameworks that try to make use of JS's OO nature, and the many and various tricks they use to make sure that 'this' actually refers to the parent object and not another unrelated object, or the specific member-function context since objects are functions. Most of it quickly becomes unreadable garbage.

Welcome to the free world.

yes yes, python has libraries too, and they have this fantastic feature called namespace. check it out sometime. If you have two or more third-party libraries loaded in python it's extremely unlikely that they conflict, because of namespaces. in JS, unless you enable compatibility mode with jQuery, you're up a creek, as you're just going to get whichever meaning of whichever function is defined last in parse order. it's insanity.

Re:How about a Javascript - to - python convertor? (0)

Anonymous Coward | more than 5 years ago | (#29478087)

Python has the same "function-only" scope, and no one calls that broken. The fact that javascript's *default* scope is global is seriously wrong though. Javascript is also not without other nasty warts, but very few languages are free of warts, and the ones in JS are hardly show-stoppers.

My main problem is the platform: all the good JS implementations are still jailed in the browser, with little or no access to useful platform technologies like IPC, serious file I/O, or GUI toolkits. That's really been what keeps me from taking up Javascript -- not everything is a web app. I'm aware of things like Rhino, but v8 and tracemonkey run circles around it. If I'm going to target the JVM, I may as well use Groovy or Clojure.

Re:How about a Javascript - to - python convertor? (1, Insightful)

Anonymous Coward | more than 5 years ago | (#29476955)

This is something i can agree with.

So much of JavaScript is really good, but actually programming it is hellish.
The interfaces between it and HTML/CSS are sub-standard. (IMO)

I wouldn't want an alternative, i would just like it to be fixed.
But getting web browser vendors behind it is the hardest part, especially when it comes to everyone's favorite company, Microsoft. (although admittedly recently they have been pretty decent, which i am really happy about)

I wouldn't mind if it evolved some more functionality present in Java, we are getting closer with things like LocalStorage and newer features which makes me really excited.

Re:How about a Javascript - to - python convertor? (2, Insightful)

BitZtream (692029) | more than 5 years ago | (#29477619)

i would like to see a viable alternative language to javascript, just for variety's sake. It's just had layers of crap pasted on top of it since 1995 or whatever and it'd be nice to see a new approach that fits what people actually use it for these days.

Why? So in 2025 you can sit around talking about the new language thats fills its roll perfectly but isn't to your liking and wasn't the perfect vision you thought it would be 15 years ago? Javascript has barely changed in the last 15 years. The environment that javascript deals with has changed a lot, but the language, not so much. Any language (or more appropriately put, any environment) that has 15 years of patches for an environment that changes rapidly is going to look and feel the same, regardless of if it starts off with your precious languages or not.

Here is reality for you developers of the world, if you think your language is better than all the rest, or some other language should go away, then you are a shitty programmer. The language does not make the programmer, the programmer does. If you find a language/environment difficult to use, you are the shitty part of the equation. Languages are just that, languages. They describe things. You are the one that has to figure out how to describe what you want, if you can't do that, the language or environment isn't the problem, you are.

Stop blaming JS for you being a shitty developer who can only parrot things out in whatever language you learned from your CS professor.

Re:How about a Javascript - to - python convertor? (2, Insightful)

s4m7 (519684) | more than 5 years ago | (#29477831)

wow, cs rage much?

I am perfectly capable of programming in JS. I've written a number of extremely useful classes in the language and I don't care for your tone.

if you think your language is better than all the rest, or some other language should go away, then you are a shitty programmer.

well, hello mr. strawman. I never declared that I wish javascript would go away, and I don't suggest any "better" language should take its place... I merely asked for an alternative that reflects how it is used in a modern sense more accurately.

Why? [...]Javascript has barely changed in the last 15 years.

Thank you for answering your own question. js wasn't a good language in the first place and 15 years of cobbling have only gone on to expose and underscore its various weaknesses. JS can do quite a bit, and it's undoubtedly useful. that doesn't change the fact that it's fundamentally a poor structure for doing what people do with it now: namely DOM scripting and asynchronous requests. I don't disagree that in 15 years whatever we develop today probably won't be a good fit for what we're doing with it then: this however is no excuse for a complete lack of progress.

If you find a language/environment difficult to use, you are the shitty part of the equation.

well that's an extremely lazy way of looking at things. Yes languages are just that, languages, and since there's no excuse for being a "bad programmer" and expecting your tools and vocabulary to be up to the task you're attempting to address, we should all still be programming in assembler using punchcards by your logic. God forbid we make use of decades worth of brilliant thought on the topic of how programming languages ought to be structured and keep things moving forward.

Re:How about a Javascript - to - python convertor? (2, Interesting)

lkcl (517947) | more than 5 years ago | (#29476927)

What browsers need is a workable CSS and DOM interface (although the DOM interface has improved in recent years).

yes - it's these DOM interfaces that i used for the pure-python port of pyjamas. the first one (webkit) i literally had to create, myself (it took 8 weeks). the second one, xulrunner, used a component created by the OLPC team, called hulahop; the third one, for windows only, uses python COM (the comtypes library) and python ctypes.

But these are not issues with Javascript per se. Cleaning up the browser programming environment is not about getting rid of Javascript.

From TFA: """
anyway, just thought there might be people who would be intrigued (or
horrified enough to care what's being done in the name of computer
science) by either of these projects.
"""

Not horrified, but I wonder if W3C politics is creating unforeseen consequences.

it has to be said that the attitude of the webkit developers (one in particular who can be easily identified) has been incredibly bad, towards the free software glib/gobject bindings i created for webkit's DOM model [github.org] . nobody should have to put up with the kind of disrespectful treatment i was subjected to, and other contributors whom i've encouraged and trained to help out have been so intimidated by the webkit developers that they are unwilling to even make themselves known to the webkit team, in case they get treated the same way.

it's a long story, and the webkit team will get burned for it, one way or another.

What browsers need... (1)

master_p (608214) | more than 5 years ago | (#29477311)

...is to be buried deep down under ground and never see the face of the Earth again.

What I mean is that we don't need browsers, we need a code/data distribution system that lazily downloads application components/data.

Re:How about a Javascript - to - python convertor? (1)

Unoti (731964) | more than 5 years ago | (#29477509)

What browsers need is a workable CSS and DOM interface (although the DOM interface has improved in recent years).

Jquery [jquery.com] makes working with the DOM incredibly easy. It completely changed and radically simplified nearly all of the Javascript that I write. If you haven't explored it, you should.

Really interesting (1)

celibate for life (1639541) | more than 5 years ago | (#29476403)

Specially given it's Python, I'm really sympathetic towards Python. OTOH, all that "rich" content for webpages fetish bothers me a little. I tend to think of webpages as magazines or newspapers, I prefer text and static images only.

Now I've heard everything (0, Troll)

Ancient_Hacker (751168) | more than 5 years ago | (#29476413)

Just when you thought things could not get any crazier, there's this story. Let's hope it's an early April Fool.

There's no way one could simulate more than about 12% of Python's complex OO semantics in JavaScript.
Python itself already has a hard and slow slog trying to perform all its tricks.

To add yet another layer of translation or simulation sounds like a lose-lose proposition. Slower and hopelessly inexact.

Not to mention many of the more useful Python modules have a considerable C component, making them completely unusable as JavaScript.

( Yes, I know, in theory JavaScript is Turing-complete, so you can do anything in it, given a universe full of CPU's ).

Re:Now I've heard everything (4, Informative)

lkcl (517947) | more than 5 years ago | (#29476501)

Just when you thought things could not get any crazier, there's this story. Let's hope it's an early April Fool.

nope. it's not. and i didn't mention in the article that pyjamas-desktop can run the python as a desktop app, either. including the GWT Canvas ported code, under the MSHTML engine. after all, the IE/MSHTML gwtcanvas is just creating VML nodes, so perhaps it shouldn't come as a surprise that it works, but it's still pretty cool all the same.

There's no way one could simulate more than about 12% of Python's complex OO semantics in JavaScript.

wrong. sorry. javascript is a drastically underestimated language. dreadful to work with if you don't know what you're doing, but incredibly powerful at the same time.

a javascript implementation of "type" - not the 1-arg version but the full 3-arg version - was initially implemented in 85 lines of javascript (it's a bit more, now).

we use that functionality to dynamically create, classes, supporting multiple inheritance and more.

pyjamas has also implemented decorators _and_ properties; kees is currently working on "yield" after skulpt's developers started working on it. not "yield by cheating and using FF built-in support for yield", but "yield" as in doing it the hard way, by analysing the state of the function and adjusting / jumping to the correct point in the function on each loop.

you really should take a look at the regression tests [pyjs.org]

Python itself already has a hard and slow slog trying to perform all its tricks.

To add yet another layer of translation or simulation sounds like a lose-lose proposition. Slower and hopelessly inexact.

slower, yes - "hopelessly" inexact: no. for GUI purposes, _if_ you've designed the application correctly (i.e. along MVC / client-server lines), then the "-O" option which switches off all the python "strict" compatibility, is perfectly sufficient.

so, "letting things fall through" to javascript, and allowing int(width) + "px" to succeed, and [1,2,3] + [4] to fail, is "good enough for most purposes".

Not to mention many of the more useful Python modules have a considerable C component, making them completely unusable as JavaScript.

wrong again. sorry. two reasons. three.

1) pygtkweb showed that it is perfectly possible to make a seamless / transparent JSONRPC service that ships function call arguments over to a server, for execution server-side, starting from e.g. "import md5"

2) pyjamas' implementations of datetime, md5, urllib, time and a few others is growing as users contribute to them. thus, the pyjamas GUI library fits the *users* needs, on an ongoing basis.

3) if you _really_ can't do without the full semantics of python, but want the benefits of full HTML, CSS, NPAPI plugins etc., use one of the pyjamas-desktop ports. there's MSHTML, XULRunner and PyWebkitGTK to choose from.

Re:Now I've heard everything (0)

Anonymous Coward | more than 5 years ago | (#29476709)

so, "letting things fall through" to javascript, and allowing int(width) + "px" to succeed, and [1,2,3] + [4] to fail, is "good enough for most purposes".

Have you tried using a separate add() like method in which you can check for Array, int etc? Or does that hurt performance too much? This is an interesting difference between Pyjamas and Skulpt: Skulpt uses special methods like Python's __add__, so it can be more compliant (operator overloading etc.) but it's slower than directly calling JS' add-operator...

Re:Now I've heard everything (1)

lkcl (517947) | more than 5 years ago | (#29476801)

Have you tried using a separate add() like method in which you can check for Array, int etc?

yes, that's in the --strict option. pyjamas actually comprises _two_ compilers, strictly speaking: one is "fast but more like javascript"; the other is "slower but more like python".

Or does that hurt performance too much?

i was surprised to find that it doesn't. (not as much as say creating an anonymous function on-the-fly in order to provide the full and correct semantics of getattr on class member functions)

Slooooooooowwww! (0)

Anonymous Coward | more than 5 years ago | (#29476437)

Haha.. That was my first thought anyway. I guess it's confirmed:

the initial experiment some months ago, with pyjamas 0.5, produced a python ACcellerator with a 10x performance increase; the latest 0.6~svn pyjamas compiler results in a python DEcellerator with a [finger-in-the-air] 10x performance DEcrease, thanks to the addition of several python strictness features

Of course, this is a 'just to do it' project', so I suppose performance is probably more of a secondary goal. :-)

iPhone application? (1)

cwike (1481913) | more than 5 years ago | (#29476445)

I wonder whether this would function correctly on the iPhone, because apple cannot restrict this, it is only JavaScript after all.

Re:iPhone application? (3, Informative)

nneonneo (911150) | more than 5 years ago | (#29476541)

I have an iPod touch running iPhone OS 3.1.1, so I tried these two projects out.

Skulpt works, but the console does not (I had to use the quick-links to test code). This is relatively easy to fix by using a textbox instead of using keyboard events. It would be very simple to write a simple webapp which evaluates Python code in the Safari browser. However, as I see it, Skulpt is still quite immature -- it doesn't implement much of the language (e.g. classes work, but can't be instantiated because Skulpt thinks you are trying to call the type object, instead of constructing it), and it doesn't do imports at all.

Pyjamas works extremely well, though it is compiled as pure JS and thus lacks (AFAIK) an "exec" method to run arbitrary Python code.

Given that Skulpt features a decent Python parser but lacks much of the core functionality, and Pyjamas implements a lot of functionality but lacks a parser built in JS, I think the projects would be mutually beneficial.

Re:iPhone application? (4, Informative)

lkcl (517947) | more than 5 years ago | (#29476615)

Pyjamas works extremely well, though it is compiled as pure JS and thus lacks (AFAIK) an "exec" method to run arbitrary Python code.

i'm working on it. last week i back-ported skulpt's parser and AST code from javascript to python, and regression-tested it; now it's a matter of improving the pyjamas compiler to be able to successfully compile that python into javascript, and we're bootstrapped.

Re:iPhone application? (1)

ceoyoyo (59147) | more than 5 years ago | (#29476773)

Thanks, Pyjamas looks like a great project. I've always wanted to be able to code client side web stuff in Python.

Re:iPhone application? (2, Informative)

lkcl (517947) | more than 5 years ago | (#29476855)

there are a ton of different ways, now: i've been maintaining a list on the python wiki, WebBrowserProgramming [python.org] page. pypy used to have a -to-javascript back-end (now abandoned); there's titanium appcelerator (which supports IronRuby and IronPython); there's PyXPCOMExt and a few more besides.

A practical use (4, Interesting)

slthytove (771782) | more than 5 years ago | (#29476503)

As a high school computer science teacher, I can see a practical application of this. Currently, I think Python is one of the best languages to learn basic programming concepts with, in that it is relatively straightforward, powerful, and there's not much "voodoo" to prevent students from diving right into programming. It's possible to do some really cool things in Python with not much code.

However, one of the problems is that it can be difficult to give students a way to show off their code. Since it's an interpreted language, they can't just give an .exe or a .app file to someone else to show it off - they need to say, "Oh, go and install Python, and these libraries, etc." Yes, there are solutions such as py2exe and py2app, but getting these set up can be quite a task in itself. By running Python inside JavaScript, you basically open up the whole web-connected world as a potential audience to these budding programmers. It's much easier to say, "Hey, check out this link!" than "Hey, download Python (but get the right version) and this graphics library, then download my .py file, and open up a command prompt and type python blahblah.py!"

Re:A practical use (1)

ceoyoyo (59147) | more than 5 years ago | (#29476701)

Actually, if you use pyobjc or whatever the Windows python packager/comiler is these days (py2exe?) you can do just that. They'll make you a self contained .app or .exe that you can just give to someone.

The web thing is pretty cool as well though.

Re:A practical use (1)

maxume (22995) | more than 5 years ago | (#29476763)

He mentions py2app and py2exe, noting that getting them going can take quite a bit of effort.

Re:A practical use (1)

ceoyoyo (59147) | more than 5 years ago | (#29476867)

You're right. Not sure how I managed to skip that whole sentence.

The setup for py2app and py2exe isn't that bad. Py2app comes preinstalled in Leopard and Snow Leopard after all.

You'd probably want to write some boiler plate to make it easy for the kids to get some instant gratification but you'd want to do the same thing with Pyjamas.

Re:A practical use (0)

Anonymous Coward | more than 5 years ago | (#29478313)

You saw "they can't just give an .exe or a .app file to someone else" and skipped the rest so you could go NUH UH!! :P

Re:A practical use (1)

maxume (22995) | more than 5 years ago | (#29476727)

They are still going to run into the problem that a lot of 'cool' stuff (graphics and whatnot) in Python depends on some C code.

Re:A practical use (1)

lkcl (517947) | more than 5 years ago | (#29476755)

that's exactly why i posted links to the GWTCanvas and the GChart demos, as they show that it is in fact possible to do "graphics" using DOM manipulation. also, with WebGL coming in HTML5 to both webkit and firefox [vlad1.com] , it will be a simple matter of having a framework that creates the relevant DOM elements.

voila - instant control over 3D graphics code (written in c), from python or javascript.

Re:A practical use (3, Insightful)

ggpauly (263626) | more than 5 years ago | (#29477249)

Why not teach Javascript itself?

It's a simple but powerful general-purpose object-oriented language. It's also a functional programming language with C-like syntax, closures, and lambdas.

A browser is the interpreter.

    **** Please read http://javascript.crockford.com/javascript.html [crockford.com] before modding this down. ****

Re:A practical use (1)

BZ (40346) | more than 5 years ago | (#29477621)

Javascript is not object-oriented in any of the traditional senses of the word. It provides features you can build an OO-like system on top of, but so does any language with closures and first-class functions...

Re:A practical use (1)

slthytove (771782) | more than 5 years ago | (#29477709)

JavaScript has a lot going for it, but it also has quite a few downsides. Just off the top of my head:

  • A very obscure sense of "type." While Python is looser than many languages in this regard, Python throws the concept of type out the window. The prototype system, while incredibly flexible, is best used by people who already understand object-oriented programming. It's difficult to start with that.
  • No strong set of coding rules/guidelines. Semicolons are semi-optional, variables can be declared but don't have to be, functions can be defined using multiple syntaxes... Many beginning (high school-aged) programmers are used to a system where there is One Right Answer. Programming introduces the idea that there is more than one way to solve the same problem. To throw JavaScript's notion that there is more than one way to express the same answer into the mix seems like too much.
  • It's great that JavaScript can be used from within a web browser. However, doing anything meaningful using JavaScript with a web browser requires at least a working knowledge of HTML and the DOM. I'd rather focus on the basics of programming separate from that first.
  • Speaking of web browsers, JavaScript implementations from browser-to-browser have nontrivial differences. Again, I'd prefer to focus on the bigger concepts without getting bogged down in implementation details.

Google Translate Extended (3, Funny)

aoheno (645574) | more than 5 years ago | (#29476509)

Announcing onelanguage dot com, an extension of Google Translate, ushering in an era where programmers need only learn one language and have it converted to another language of choice.

FAQ:

Q. How accurate is it?
A. Same as Google Translate. You have to learn the output language to know which parts of the language you already know result in garbage-out. We suggest you use our new Pidgin versions of Python, PHP, Java, and Ruby.

Re:Google Translate Extended (4, Interesting)

lkcl (517947) | more than 5 years ago | (#29476965)

i know you're joking, but there really _is_ a Visual Studio "universal translator" plugin available - i've seen it demo'd, converting c++ to java, to B, to ruby, to c#. it all used CLR as the intermediary. i heard that activestate were commissioned to add python to the mix, but, weirdly, it wasn't included in the release of the translator i saw.

Antigravity (0)

Anonymous Coward | more than 5 years ago | (#29476923)

I can finally make my browser fly!

Why don't browsers just support it? (1)

Blakey Rat (99501) | more than 5 years ago | (#29477011)

[script type="text/python"][/script]. Let one of the major browsers implement it, and see if the others follow... there's probably already DOM-access libraries in Python, yes?

Seems to make a hell of a lot more sense than this translation stuff.

Re:Why don't browsers just support it? (2, Informative)

redhog (15207) | more than 5 years ago | (#29477089)

That'd be damn hard. Python isn't made for sandboxing (google python and sandboxing, or restricted execution, and you'll see). If you did the script language=python implementation the "obvbious" way and just linked in the python interpreter into mozilla, you'd have a security hole big enough for a supertanker. There is Python support for extensions though - google PyXPCOM.

Re:Why don't browsers just support it? (1)

Blakey Rat (99501) | more than 5 years ago | (#29477133)

Well, that's a point. I still think this whole concept is a little daft, considering that web scripting has been designed to be language-independent from day one. I mean, IE has been the only browser to really embrace it, but still-- no reason other browsers can't.

Re:Why don't browsers just support it? (1)

lkcl (517947) | more than 5 years ago | (#29477537)

[script type="text/python"][/script]. Let one of the major browsers implement it, and see if the others follow... there's probably already DOM-access libraries in Python, yes?

Seems to make a hell of a lot more sense than this translation stuff.

there's two main ways in which this can be achieved:

1) pyxpcomext

2) appcelerator / titanium, with IronPython, via Silverlight/Moonlight.

the problem is - one that both skulpt and pyjamas avoid - you need browser plugins, in each case, to achieve the goal. the pyxpcomext plugin is a whopping TEN MEGABYTES because it literally contains the entire python runtime.

Just learn it. (0)

Anonymous Coward | more than 5 years ago | (#29477021)

Seriously guys. What the hell. We've reached some bizarro meta level of abstraction now. With things like this and GWT, we're just making things worse. I used to absolutely loathe javascript. Then, I took the time to sit down and actually _learn_ the language and it quickly became one of my favorites. It really can be a lot of fun.

Go watch Doug Crockford's presentations on javascript. He makes some excellent points about just how misunderstood the language is. Yes, it has some nastiness in it, but you don't have to and shouldn't use those parts. The vast majority of javascript books, tutorials, and web resources are just terrible. There's a lot of chaff out there to winnow before you find the wheat.

Download some of the better javascript libraries. Use them. Take them apart. Learn how they did things. Just start playing... seriously, it's fun.
I highly recommend MooTools, jQuery, Prototype, and their ilk. Rip those suckers apart and bend the browser to your will. Muhahah!

I propose a new contest: (1)

Hurricane78 (562437) | more than 5 years ago | (#29477083)

Who can string together the largest number of platform layers [wikipedia.org] over each other, and still have it running.

The first league will start in the 2 GB core memory and 2* 2 GHz (dual-core) CPU range with no other processor (like GPU) or storage (like HDD) usage.
Every type of platform is only allowed once.

Here is a list of platforms, to get you started:
- Emacs
- the CPU itself
- Virtual machine (e.g. VirtualBox/VMware)
- Browser(s)
- C/C++
- JavaScript
- interpreted Piet [99-bottles-of-beer.net]
- Python
- LOLCode [99-bottles-of-beer.net]
- Malbolge [99-bottles-of-beer.net]

Bonus points for achieving a circle jer^H^H^Hof platforms, so that no actual real program is ever executed.

Re:I propose a new contest: (1)

Hurricane78 (562437) | more than 5 years ago | (#29477121)

Oh, I forgot some very important ones:
- PHP
- Typo3's Smarty [wikipedia.org] & others [wikipedia.org]
- Wiki syntax (if possible)
- XSLT [wikipedia.org]

Re:I propose a new contest: (1)

Pulzar (81031) | more than 5 years ago | (#29478253)

For bonus points, make it all run on non-jailbroken iPhone ;).

Silverlight does this too (1)

zokier (1049754) | more than 5 years ago | (#29477233)

I know everyone hates Microsoft and its eeevil proprietary technologies but still, it can achieve nice things. A javascript library which parses python script-tags via Silverlight. Check it out: http://visitmix.com/labs/gestalt/ [visitmix.com]

Python implementations still suck (4, Insightful)

Animats (122034) | more than 5 years ago | (#29477363)

Python is quite a good language, but the implementations suck. This is holding back widespread use of Python. It's too slow, typically 10x to 30x slower than C. That's far worse than Java.

There have been several attempts at other implementations. But because Guido Rossum fights formal standardization of the language, treating his CPython implementation as a de-facto standard, everyone else has a moving target to hit.

Google (who hired Guido) likes Python, but they don't like the low performance. CPython is a "naive interpreter" (very little optimization). Worse, with the rather lame implementation the Global Interpreter Lock, not only can't it use a multi-core CPU effectively, multi-thread programs run slower on multi-core CPUs. (The threads fight over the lock in an embarrassingly inefficient way.)

Google is doing "Unladen Swallow", which is an attempt to bolt CPython to a just-in-time compiler to a virtual machine. It's not clear how well that will work out, but the end result will have more layers than seems to be indicated. The goal is 5x faster than CPython, which won't beat Java, let alone C/C++.

It's cute that Python to JavaScript translation is possible, but it's not going to help much on the performance front.

For a few years, the great hope of the Python community was PyPy, but that had too many goals, was being developed in "sprints", and after five years, the European Union pulled the plug on funding after it was slower than CPython.

Shed Skin [blogspot.com] , which is a Python to C++ hard-code compiler, is currently the lead in Python performance, but it doesn't yet implement the whole language. Still, with about two people working on it, Shed Skin is doing better than most of the bigger projects. Shed Skin does automatic type inference. Python doesn't have declarations, but with enough analysis, the compiler can figure out what types each variable can hold and generate hard types, which makes for much faster code.

Re:Python implementations still suck (1, Insightful)

Hohlraum (135212) | more than 5 years ago | (#29477637)

Why is it ok for Java to be slower than everything that came before it? Because supposedly its easier to use and hardware is always getting cheaper. Why is it ok for Python to be slower than Java? Because it IS easier to use and hardware is always getting cheaper.

Re:Python implementations still suck (1, Insightful)

jellomizer (103300) | more than 5 years ago | (#29477763)

It really wasn't OK for Java to be slower then languages that came before it. Its success is rather limited. (now I opened the door to all the JavaDevelopers and IBM Trolls) Java was meant to be a replacement for for all those apps that are out there. But it has done little in terms of front end applications, where it was hoping to succeed the most. Why because of its poor performance, on standard PC and especially with GUI's Even using a fast PC you know when you are running a Java App. That is why Microsoft Visual Studios even with the abomination of .NET virtual machine garbage, has made it more popular for front end development then with Java. Because it performs better.

Saying that is bad because it is slower then Java means that Java is really slow and people are not happy with that so anything slower will make us more unhappy.

Re:Python implementations still suck (2, Insightful)

OrangeTide (124937) | more than 5 years ago | (#29477861)

Saying that is bad because it is slower then Java means that Java is really slow and people are not happy with that so anything slower will make us more unhappy.

What?

Re:Python implementations still suck (1)

speedtux (1307149) | more than 5 years ago | (#29478131)

That is why Microsoft Visual Studios even with the abomination of .NET virtual machine garbage

I actully prefer the .NET virtual machine garbage to the Java virtual machine garbage, not because it's faster, but because it has features like pointers, structure return, and working templates.

Speed matters. Datacenters cost money. (4, Interesting)

Animats (122034) | more than 5 years ago | (#29478157)

Because it IS easier to use and hardware is always getting cheaper.

On the server side, 10x to 30x slower means building entire buildings full of servers. Or more expensive hardware in the cell phone. Or using another language.

Python is actually a good general-purpose programming language, not just a "scripting language". The big problem is slow execution.

The basic problem with CPython is that, being a naive interpreter, it has to check for the hard cases every time. "n = n + 1" ought to be a few machine instructions, maybe only one. But Python has to check for n being a float, n being a string, n being an object, etc., every time. Shed Skin, with a type inference systems, does analysis at compile time and determines that n is always an integer, then generates code for integer arithmetic only.

There are all sorts of dynamic things one can do to a Python program while it's running. You can add a function to an object. You can replace existing functions. You can load new modules on the fly. But most of the time, for most of the objects, you don't do that. An efficient implementation needs to separate out the cases where something unusual might occur, and the far more common cases when the program is doing routine stuff that needs to go fast. The common cases can then be handled with much simpler, and faster, code.

Re:Python implementations still suck (1)

BitZtream (692029) | more than 5 years ago | (#29477779)

It's cute that Python to JavaScript translation is possible, but it's not going to help much on the performance front.

I agree, its very cute that some people are doing it.

But this better be a school project or something, otherwise its just a waste of resources, these guys are obviously talented. If they are still learning or this is just a side project for the hell of it, fine. But please, put the effort into some more useful projects if possible.

Re:Python implementations still suck (1)

Joe Tie. (567096) | more than 5 years ago | (#29478077)

Personally, I don't see what's wrong with coding for the fun of doing something unique and fun. Seems like looking at art and saying "But what's it DO?"

Re:Python implementations still suck (0)

Anonymous Coward | more than 5 years ago | (#29478109)

PyPy, but that had too many goals, was being developed in "sprints", and after five years, the European Union pulled the plug on funding after it was slower than CPython.

PyPy funding ended because EU projects run for a set amount of time regardless of success or failure. The EU doesn't usually pull the plug on failing projects, and PyPy was actually quite successful by the low EU standards--it produced working code and other people were using it.

Re:Python implementations still suck (1)

lkcl (517947) | more than 5 years ago | (#29478387)

Google is doing "Unladen Swallow", which is an attempt to bolt CPython to a just-in-time compiler to a virtual machine.

It's cute that Python to JavaScript translation is possible, but it's not going to help much on the performance front.

thanks for posting this - it's interesting to see peoples' insights.

i'm aware of the unladen/swallow effort: they're replacing the FORTH-based bytecode engine with LLVM JIT compilation.

on their roadmap is "unboxing" of the http://python.org/ [python.org] c code types (Object/longobject.c, Object/intobject.c, Object/stringobject.c etc.)

basically the plan is (i believe!) to provide reimplementations of intobject.c's __add__, __mul__ etc. to call LLVM routines instead of straight c code. in this way, they intend to keep python "c code" module interoperability, as long as you replace the libpython2.6.so with an unladen/swallow one.

_as long as_ the speed was still there, i would like, at some point to do the same trick - but with Google V8 javascript engine, instead (and, for fits and giggles, throw in spidermonkey as an option as well). basically, the implementation of intobject.c's __int__ would have a pointer to a javascript object, in which there would be an __int__ function; a call in python from a standard python c-based module to create an int would result in the creation of a javascript object representing the integer, and the intobject.c code would simply "look after it". in this way, you would have interoperability between python that was converted to javascript, and python c-based modules.

the thing is: the performance of the pyjamas LoopTest was a bit lower than i was expecting, so i double-checked things, especially that the original experiment showed conversion of python to javascript executed under V8 having a whopping 10x performance increase (over standard python).

pyv8run running the fibonacci algorithm, it's confirmed: when you set -O (optimisation mode in pyjamas) we have a 2.5x performance INCREASE over standard python, WITHOUT having made any special effort or analysed what is going on and without having profiled things to find out if it can be done any better.

also confirmed: when you switch on "--strict", the object-accessing test comes down to 10% the performance of python, which is truly dreadful, but hey, it's "safe", what do you expect? :)

also confirmed: a simple object-accessing test is 50% (HALF) the performance of python - again, with no investigation as to why that is.

Re:Python implementations still suck (1)

ceoyoyo (59147) | more than 5 years ago | (#29478419)

"Google (who hired Guido) likes Python, but they don't like the low performance. CPython is a "naive interpreter" (very little optimization). Worse, with the rather lame implementation the Global Interpreter Lock, not only can't it use a multi-core CPU effectively, multi-thread programs run slower on multi-core CPUs. (The threads fight over the lock in an embarrassingly inefficient way.)"

The semi-new multiprocessing module is pretty cool. For the most part it duplicates the thread api interface, but it uses processes each running their own interpreter on the back end. True multiprocessing, and some care has been taken to provide decent interprocess communication, scheduling, etc.

OpenSource Web Browsers written in Python? (1)

marciot (598356) | more than 5 years ago | (#29477751)

Are there any open source web browsers written in Python? If so, I would like to run it in these JavaScript python interpreters so I can browse the web.

Re:OpenSource Web Browsers written in Python? (1)

lkcl (517947) | more than 5 years ago | (#29477937)

yes - paul bonser's pybrowser [paulbonser.com] is the beginnings of an implementation of a web browser in python. he uses python-cairo and pygame for the graphics and the event handling. a combination of flier liu's PyV8 [google.com] or python-spidermonkey would bring javascript execution to this effort, completing the loop.

also i just accidentally encountered this [telepolis.com] which is confusingly also called pybrowser: it uses python-gtkhtml2 (which is considered deprecated since this project named pybrowser was written, in 2005).

lipstick, dogs (2, Funny)

speedtux (1307149) | more than 5 years ago | (#29478083)

Compiling Python to JavaScript running in a browser really is like putting lipstick on a dog.

Load More Comments
Slashdot Login

Need an Account?

Forgot your password?