In an earlier post I mentioned that Brazil was designed to support cross-platform native UIs, and that I was working on our second platform mapping, Windows (the first one was Morphic). That was in May and for some time now Windows support is fully functional and Brazil applications can, as intended, work in either Morphic or Windows with no explicit provisions for that in the application code. What comes along is dynamic remapping–the ability to move the UI of a running application between Morphic and Windows without shutting down. This is just like switching the look in an emulated environment like VisualWorks–except that nothing is emulated and the widgets are the real deal.
Here is a screencast showing what it’s like.
This feature is not as gimmicky as it may seem. When an image-based environment is given a native UI, dynamic remapping is exactly what should happen when an image starts–and not only when it starts on a platform different from where it was saved. Even on the same platform, recreating native windows and widgets open at the time the snapshot was taken amounts to essentially the same thing.
One of the features that distinguish Smalltalk from most other languages is the keyword message syntax, and one of those that distinguish Newspeak from Smalltalk are implicit receivers. They work very nicely together to allow writing very readable code. Here is a drag-and-drop related method I just wrote:
createDropTargetFor: session <DragDropSession> ^<DropTarget> = (
^if: session source
otherwise: [createClientSuppliedDropTargetFor: session]
What we have here is a method with the selector createDropTargetFor:. The things in angle brackets are type annotations–essentially, optional structured comments telling the reader what the method expects and returns. Unlike Smalltalk, the body of the method is explicitly delimited by “=(” and “)”.
The three message sends in the body have no explicit receivers, which in this case means they are sent to self, self being what any Smalltalker would expect. In the general case, however, because of class nesting there may be a choice of selves available, so the receiver is not necessarily the object whose class contains the method with the send. This is why “implicit receiver” is a more precise term. For details, see Gilad’s On the Interaction of Method Lookup and Scope with Inheritance and Nesting.
This is the second part of the Newspeak UI overview. Hopscotch is the name of both the application framework and the IDE of Newspeak, built on top of Brazil. Brazil provides “logical widgets” mapped onto the host platform artifacts and takes care of laying them out. Hopscotch adds the concepts of an application, domain objects, and mechanisms to keep the model and the view synchronized.
Hopscotch-the-IDE is based on a web browser-like model of navigation. I say “web browser-like” because the framework could support other application shapes as well, but in the particular case of an IDE, an interactive document viewed in a universal navigator is a model that works exceptionally well for visualizing a complex structure such as application code. The interactive documents are specified in a declarative and highly composable way.
The work on the framework is still in progress. I am interested in achieving a usage experience (the user in this case being a programmer using the framework) reminiscent of functional reactive programming, and that has some interesting algorithmic challenges.
More details are in this paper, and hopefully the video of my Smalltalk Solutions demo will soon be available. The paper has been accepted to WASDeTT, co-located with ECOOP, as a featured talk on July 8 at 12:00. Unfortunately, this coincides with the DLS, but I’ll also show a short demo during Gilad’s Short Introduction to Newspeak on July 10.
Brazil, which is the foundation of Newspeak UI (and is indeed named after the movie), could be best described as a multi-platform logical UI and layout framework. It provides the familiar widgets (“visuals”) such as Labels, Buttons, and ListBoxes, and container visuals for combining widgets and managing their layout. Unlike the UI frameworks of Squeak or VisualWorks, Brazil does not attempt to actually implement the widgets by emulating them. Instead it functions as a “logical UI” layer that builds and drives the equivalent “physical UI” made of native artifacts of the host platform.
The first host platform of Brazil was Morphic–meaning the first “native” Brazil interfaces were in fact emulated. This trick allowed us to quickly build a minimal working implementation and polish the API without getting bogged down with FFI issues and native widget peculiarities early on. Since Morphic works on all OS platforms, so did Brazil from the start, allowing to use it on all platforms we need before we build real native mappings for those platforms.
Brazil also manages the layout of interfaces using a capability-based extensible model. Layout is fully managed by Brazil both on native platforms which usually provide rather weak layout facilities of their own, and in Morphic which provides a rich but baroque one. All that Brazil expects from the host are the abilities to position a widget within the specified rectangle, and to measure its natural (desired) extent.
Work on Brazil began in mid-March 2007 and in June a first real UI was built using it. I am currently working on a native Windows mapping. This work is at an advanced enough stage to be able to open all of the existing Brazil UIs as native in Windows with most functionality in place, without any changes in application code. Brazil windows can also be dynamically remapped, so that what appears as a Morphic window can “jump out” of Squeak and become a native window with native controls, and then go back to Morphic all the while retaining its state.
Unlike prior implementations of native UIs in Smalltalk, Brazil is implemented entirely at the image level. This means that there is not a single VM primitive to support UI operations. The mapping relies on “raw” OS functions accessed via the general-purpose Newspeak FFI to do everything, from Windows class registration to widget management and GDI+ painting.
Newspeak will be open sourced under Apache 2.0 license. Note the future tense; there is much work still to be done. In the meantime get the scoop here.
I’m presenting what I’ve been busy with for the past year and a half (well, almost) at Smalltalk Solutions in June. The title of the talk is “Interfaces without Tools”.
Programming environments are commonly built as sets of tools, where a tool has the shape of a pre-composed window displaying and manipulating a set of domain objects. This talk takes a critical look at that approach and presents Hopscotch, an application framework and development environment based on different concepts. Hopscotch is the IDE and the application framework of Newspeak, a new language and development platform inspired by Smalltalk and Self.
The talk is on the first day of the conference, June 19 at 1:30 pm.
About a month ago Gilad gave a talk at the University of Potsdam about our work. The video of the talk is now available online. I have been quiet for quite a while busy with our UI framework and environment (Brazil and Hopscotch), so this is a chance to see some of it in action. I hope to eventually find more time to tell about it here, but for now feel free to leave a comment with any questions and I’ll do my best to answer them.