LWN.net Logo

Pyjamas: writing AJAX applications in Python

Pyjamas: writing AJAX applications in Python

Posted Aug 26, 2009 19:30 UTC (Wed) by Cyberax (✭ supporter ✭, #52523)
In reply to: Pyjamas: writing AJAX applications in Python by nye
Parent article: Pyjamas: writing AJAX applications in Python

JavaScript is extremely cludgy language. It has no namespaces, idiotic variable scoping rules, absolutely moronic automatic semicolon placing, etc.

See this presentation: http://googlecode.blogspot.com/2009/03/doug-crockford-jav...


(Log in to post comments)

Pyjamas: writing AJAX applications in Python

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 :)

Copyright © 2013, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds