JavaScript and Python and Java too

You don’t usually see “JavaScript” and “Python” in the same sentence or even in the same article. That’s because they’re most often used for two different purposes by two different kinds of people. JavaScript is usually used within a Web browser whereas Python is used either on the server or as a general-purpose scripting language. Many web designers who don’t consider themselves programmers use JavaScript while Python is loved by the hardest core coders. Given the different worlds JavaScript and Python inhabit, I was intrigued to hear that JavaScript’s founder Brendan Eich intends for JavaScript to follow Python’s lead as it evolves.

Still, the news of JavaScript’s Pythonesque future is far less interesting and potentially important than Google’s announcement of a Java-based toolkit for Ajax development. Ajax uses JavaScript, XML, and asynchronous requests to a web server to make super-responsive web apps that don’t reload the page every time they grab some new data. Google has written a framework in Java that generates Ajax–i.e., JavaScript–code. How curious.

JavaScript, Briefly

JavaScript isn’t Java. JavaScript is the scripting language that Netscape developed for use within the Navigator browser. The story goes that they named in JavaScript in order to cash in on some of the buzz Java had at the time. JavaScript is standardized under the name ECMAScript. It’s similar to the C programming language in syntax and is considered a general-purpose programming language. You don’t have to use it within a browser, but you do have to have a JavaScript interpreter in order to run a script written with it.

Python, Briefly

The Python language is, like JavaScript, interpreted, meaning you don’t have to go through a time-consuming compilation step in order to run it. It was created by Dutch programmer Guido van Rossum in 1990. Python’s syntax doesn’t look much like C, at least to me, partly because of the unusual way of delineating program blocks. Instead of using curly braces, like C and many other languages, Python uses whitespace. The indentation of a program matters in Python.

Planned Changes to JavaScript

What is the JavaScript founder planning to borrow from Python? Eich mentions the following:

  • Iteration - JavaScript supports just two kinds of object iteration, property enumeration that walks through every single property of an object, and for loop iteration, which follows C syntax in a for (i=0; i
  • Generators - Python generators, introduced with version 2.2, provide the basis for iterators.
  • Array Comprehensions - Allow the programmer to use set-like notation to do operations on collections of objects. This can make for highly compact and readable code, if you understand the syntax.

Does This Matter to Most JavaScript Programmers?

No. First, these features aren’t available now. Second, though they’re kind of cool from a computer science perspective, they don’t fundamentally change how you program with JavaScript. And how could they? JavaScript needs to maintain compatibility with all the code that’s already out there. It can’t change into something that it isn’t already.

Java, Briefly

Java was created by Sun as an object-oriented, portable, network-aware high-level programming language. It took over from C++ as the language of choice for many corporate IT development projects and borrows much of its syntax from C++. Java has been tarred as boring and as enterprisey, but its breadth and power make it a safe choice if not the most bold.

I can’t quite get my head around writing Java to generate Ajax/JavaScript though. Granted, writing portable JavaScript code will give you a migraine, if you’re prone. This is exactly the problem Google is addressing:

Google Web Toolkit (GWT) is a Java software development framework that makes writing AJAX applications like Google Maps and Gmail easy for developers who don’t speak browser quirks as a second language. Writing dynamic web applications today is a tedious and error-prone process; you spend 90% of your time working around subtle incompatabilities between web browsers and platforms, and JavaScript’s lack of modularity makes sharing, testing, and reusing AJAX components difficult and fragile.

GWT lets you avoid many of these headaches while offering your users the same dynamic, standards-compliant experience. You write your front end in the Java programming language, and the GWT compiler converts your Java classes to browser-compliant JavaScript and HTML.

This gives me a headache of its own, as I try to make sense of it… What does this mean, that a web star like Google is driving developers from a dynamic scripting language to Java? In a way, I like it. I like that Google isn’t stuck on particular ideas, like that dynamic scripting languages are always the way to go. Java has tons of infrastructure support around it like development environments with good debuggers. It makes sense: Java and its ancestors were designed specifically to build highly dynamic applications whereas JavaScript was intended to do basic document object manipulation. Now that we want to make our web apps more like desktop apps, we find we need a desktop development language. Still, it seems kind of baroque to me. Perhaps I need to let the idea sit with me for a while, maybe even try it out, before I make a conclusion.

4 Comments

  1. Posted May 17, 2006 at 10:43 pm | Permalink

    Remembering OpenLaszlo’s work on similar technology wrinkled my thinking about Google’s annoucement. What seemed entirely novel, now seems less so, but even more interesting. While I have not personally developed applications with the OpenLaszlo framework I understand it to abstract Ajax development from the client runtime.

    Why did Google take Java? Probably a combination of i) Java infrastructure, as you mentioned; ii) wide Java adotpion among enterprise developers giving the release hues of an offensive against Microsoft; iii) I’m looking for an inherent technological advantage to put here, but can’t since both output Javascript–? If not baroque, then what?

  2. Posted May 17, 2006 at 10:55 pm | Permalink

    Ready. Shoot. Aim. Silly me.

    From Laszlo’s pr on sharing libraries with Dojo Toolkit:

    “Laszlo recently revealed that by the end of this year (2006) developers using OpenLaszlo will have the option to deploy their applications in Dynamic HTML (DHTML), in addition to the Flash runtime option that is currently available.

    http://www.laszlosystems.com/company/press/press_releases/pr_apr_06.php

  3. Posted May 18, 2006 at 7:06 am | Permalink

    Hmm, hadn’t heard of OpenLaszlo before… sounds like you use some type of XML language with JavaScript embedded to develop dynamic web applications, output to either Flash or DHTML? Very interesting. It seems better to me to be closer to the actual output (i.e. write JavaScript vs. Java to get ultimately to Java) but I suppose in these cases the actual implementation of the framework is what really matters.

    I guess Google can target all the Java developers in corporate IT departments this way and, like you said, do an end run around Microsoft and ASP. I didn’t think of it from a strategy point of view and obviously that’s what you’ve got to do when thinking about Google, or any big company for that matter. They don’t make decisions based solely or even mainly on technical/architectural concerns.

  4. Posted May 19, 2006 at 1:26 pm | Permalink

    hey Anne,
    seriously thanks for that–hate to say it, but it might make me seem less dumb in these here parts! very useful! hope the move treated you well:)

Post a Comment

Comments are moderated. Rude comments may be edited or deleted.

Your email is never published nor shared. Required fields are marked *

*
*