This sounds like an excellent project, mostly because it's a) retargetable (running the same code as a desktop application is a nice trick) and b) handles "the various tricks needed to make an application work consistently across multiple browsers, all of which must be wrapped up inside HTML".
What I don't get is why it's so fashionable to add bits like "the clumsiness of the Javascript language itself". Javascript is probably my second favourite programming language (after Lua, which I sadly find too little opportunity to actually use). Usually when people deride Javascript it turns out they are actually talking about, say, inconsistent event handling across browsers, or implementation bugs like IE's memory leaks when closures are used in particular ways - or other problems which really are in no way part of the 'language itself'.
I do write a fair bit in Python, because of the broad array of libraries available, but I can't imagine that automated compilation of arbitrary Python libraries into JS+HTML is feasible, so this seems to take away most of Python's appeal. Nevertheless I'm sure I'll give it a try some time...
Posted Aug 26, 2009 21:14 UTC (Wed) by iabervon (subscriber, #722)
[Link]
The scoping and line termination rules, combined with being interpreted at runtime, make a large portion of bugs difficult to detect without actually reaching every line of code.
Of course, Python has the same problem as Javascript here, but it's more than twice as bad if you're doing a project with both, because they not only both have error-encouraging scoping and line termination rules, they have different rules. So the Python you're writing encourages you to accidentally make your Javascript variables global and forget required semicolons.
Pyjamas: writing AJAX applications in Python
Posted Aug 26, 2009 22:07 UTC (Wed) by drag (subscriber, #31333)
[Link]
> because they not only both have error-encouraging scoping and line
termination rules,
What?
I don't understand. The line termination rules for python is very simple..
A line of code ends with a newline. The only exceptions that I can think
of to this is that you can explicitly end a line of code with ";" and you
can extend a mathematical statement by enclosing it in ().
This, to me, is a hell of a lot better then requiring ;'s all over the
place.
I tend to forget those time to time and it's sometimes very irritating to
track that down. In python as long as I keep my code clean and line
lengths to under 80 characters (or so) then it's easy to know what a line
of code is just by looking at it. A line of code is a line of text.
And what is error prone about Python's scoping? I can't imagine that its
any worse then C++ or C or Java or anything like that.
Pyjamas: writing AJAX applications in Python
Posted Aug 28, 2009 7:12 UTC (Fri) by niner (subscriber, #26151)
[Link]
Open brackets or braces can extend an expression to multiple lines. And that is a very
good thing, otherwise it would make code quite unreadable. The ''' or """ quotes do the
same.
But both mean that you cannot simply trust a statement to be a single line of code.
Pyjamas: writing AJAX applications in Python
Posted Aug 30, 2009 13:18 UTC (Sun) by kleptog (subscriber, #1183)
[Link]
Actually, python's scoping is one of my biggest problems. The fact that the scoping of a variable can change in odd ways. Consider:
import time
def main():
print time.clock()
time = 1
main()
This program produces an error on the "print" line, yet if you comment out the "time = 1" line it works. This means you have to read a whole function before you can determine the scope of a variable. Being someone who controls scopes carefully so that typos are more easily found, it all feels weird.
Pyjamas: writing AJAX applications in Python
Posted Sep 3, 2009 4:28 UTC (Thu) by tjc (subscriber, #137)
[Link]
This, to me, is a hell of a lot better then requiring ;'s all over the
place.
I tend to forget those time to time and it's sometimes very irritating to
track that down.
Semicolons are optional in Javascript, so why bother to "track that down?" If you don't like them, then just leave them off.
Pyjamas: writing AJAX applications in Python
Posted Aug 29, 2009 5:44 UTC (Sat) by SteveAdept (guest, #5061)
[Link]
Add me to the list of people who don't like Javascript. My primary peeve is how it represents null values, similar to the mess PHP makes of it. If I never initialized a variable before I start reading from it, I want to know about it. Ick. I find that it often makes debugging extremely frustrating for me.
And I realize this isn't specifically a language issue, but I hate the fact that we have to deal with so many different implementations. I'm spoiled by the ubiquity and consistency of CPython, I guess.
Pyjamas: writing AJAX applications in Python
Posted Aug 26, 2009 22:10 UTC (Wed) by quotemstr (subscriber, #45331)
[Link]
Yet it has lexical closures, which somehow most languages seem to relax. Closures are Javascript's saving grace; with them, most of your other concerns can be addressed.
(Well, and never using the scope-destroying, mind-liquefying, optimization-prohibiting with facility.)
Pyjamas: writing AJAX applications in Python
Posted Aug 27, 2009 5:24 UTC (Thu) by flewellyn (subscriber, #5047)
[Link]
I quite disagree: Javascript has a few warts, but it's quite elegant at its core, and very powerful.
Namespaces might be of use, but you can use objects to handle them easily enough; the variable scoping rules are only a problem if you don't understand closures (which are one of the things that gives JS such power), automatic semicolon placing...yeah, that sucks, so I don't rely on it. I always use semicolons.
The main thing I dislike about Javascript, the language, is the overloading of + to mean "addition" and "string concatenation". Operator overloading is never a good idea, especially in this case, because JS is dynamically typed, and numeric values may be misinterpreted as strings.
I think JS gets a bad rap because people are used to dealing with DOM incompatibilities, and blame those on the language.
Pyjamas: writing AJAX applications in Python
Posted Aug 29, 2009 11:24 UTC (Sat) by lkcl (guest, #60496)
[Link]
"I quite disagree: Javascript has a few warts, but it's quite elegant at its core, and very powerful."
oo, absolutely! think about this: an implementation of python classes - dynamic multiple inheritance including superclasses and the (very rarely used and misunderstood _three_ arguments to the type() function: kls = type("ClassName", [Baseclass1, Baseclass2], {'method1': fn })...
... that can be implemented in UNDER 100 lines of javascript!
there's a little trick to do "object-like" inheritance which is typically deployed in javascript frameworks: it creates a new Object() and then sets up the prototypes copying them from the base object. that's typically implemented in about... 15 lines of javascript. all we did was expand that a little bit further.
voila. instant emulated multiple inheritance and python superclasses.
the warts: achhh. anonymous objects that don't carry around the "this" pointer properly. having to create a wrapper function which re-associates the .... never mind :)
Pyjamas: writing AJAX applications in Python
Posted Aug 26, 2009 23:43 UTC (Wed) by gouyou (guest, #30290)
[Link]
I didn't like JavaScript up to the point I read "JavaScript: The Good Parts" from Douglas Crockford. This book was a revelation for me. (If all languages would have such a book, it would make learning new language for people with already a bit of programing experience much simpler.)
Pyjamas: writing AJAX applications in Python
Posted Aug 29, 2009 12:14 UTC (Sat) by lkcl (guest, #60496)
[Link]
"but I can't imagine that automated compilation of arbitrary Python libraries into JS+HTML is feasible, "
into HTML? no. into javascript? yes. that's exactly what pyjamas does, and it's also what skulpt is aiming for, and it's exactly what the pypy project aimed for, except they gave up.
the tricky bit is doing it _efficiently_. we decided that that was a bad decision to enforce onto people, so we decided to offer two options: -O and --strict. they do exactly what you'd expect.