Wednesday, June 16, 2010

Newspeak: A Principled Dynamic Language?

I just watched Gilad Bracha's talk Newspeak: A Principled Dynamic Language, and I find myself disagreeing with most of what he says. For the kind of programming I'm interested in (systems & networks scripting), Newspeak's principles seem to be all the wrong ones.

It starts with the declared goals of the language:
  • Modularity
  • Security
  • Reflectivity
  • Interoperability
Regarding modularity, I think that the new unit of modularity is a (REST) service. In this case, modularity isn't even a language issue anymore, you solve it out of band. Or, if you don't want to go that far, the unit is some big library like ImageMagick. And that kind of modularity really is a solved problem. (Of course, there are interesting research issues around modularity, say in-language dependency injection (Noop) or what Newspeak does. I just don't think it's practical right now, and maybe not even needed.)

Regarding security, I simply don't get the point of in-language, capability-oriented security. Until we can secure an OS, which we can't at the moment, the only workable solution is sandboxing the whole OS. Whether the language is safe or not doesn't matter, if you can't trust the OS, and if you want to work with unsafe languages. Again, solve it out of band.

Reflectivity seems to have become another word for "things that shouldn't be done in the first place", like say, ActiveRecord's method names like find_by_name_and_email() or whatever. (This is simply a sign that you're lacking macros, which would allow you to do the right thing and define a frickin' embedded DSL.) Of course, you should be able to introspect every object, class, etc, but I'm taking that for granted.

Regarding interoperability, there's a choice quote by Bracha: "the real world, the nasty stuff that's out there". Now, that's the attitude that killed the Lisp machines, killed Smalltalk, and will continue to kill whatever project takes that stance. If your reaction to the real world is "egad, nasty stuff", do you think you'll ever "interoperate" with it well?

After the introduction, Bracha has to explain Newspeak's precedence and parsing rules for minutes, because otherwise, as he says, nobody would be able to understand the following code. Syntax other than S-expressions is simply irrational.

Surreal Virtuality

Then there's this business about everything being a virtual method call. Now, if there's one language that combines virtual method calls and functions correctly, it's CLOS (and thus, Factor). And CLOS shows exactly that virtual lookup is not fundamental. Basically, DEFMETHOD works like this:
(defmacro defmethod (name params &rest body)
(put-method ,(get-the-class-of-param (first params))
(lambda ,params ,@body))
(defun ,name (&rest args)
(call-method (first args) ,name args))))

So, the virtual lookup happens inside an ordinary function, the generic function. Function calling is the primitive onto which the virtual lookup mechanism is layered, not the other way around. That's the sane, rational way to combine the functional and generic object-oriented paradigms.

(OK, I like to do as little "virtuality"/polymorphism as possible, although I do find it indispensable. The thought of having virtual lookups all over the place, when all I want is to read a variable or call a function kinda freaks me out. So probably I'm not in the right target audience to begin with.)

Taken all of this together, I find Newspeak a fairly ill-principled language for my needs.

1 comment:

dmbarbour said...

Regarding Modularity: Not all programs effectively break down into interaction with RESTful services, such as interactive fiction and simulations (which, by nature, must share a lot of its own state between components). When developing an episodic game, it would be very useful to modularly reuse characters, areas, objects, sub-plots, physics, etc.

I would especially like the ability to share a unit of code for another project risk of dragging along a whole dependency forest. See also Luke Palmer's singularity article for one vision.

Regarding Security: if you're going to share untrusted code or extensions (scripts, plugins, etc.) it's very nice to have language-level security. If we have security in the language, we don't need to depend on a flaky OS.

Regarding Reflectivity: I'm not all that fond of reflection myself, but Newspeak's 'mirrors' are the best approach I've seen. They would allow us to develop secure, distributed debugging capabilities, and can actually be separated from the language (i.e. like a foreign service).

Regarding Interop: our languages should be designed to interact with the physical world (e.g. consideration for sensors and actuators and UI). Where it gets nasty, however, is interaction with incumbent software (protocols, concurrency and resource management assumptions, portability and configuration management, etc.).