Seaside: a Flexible Environment for Building Dynamic Web Applications
Total Page:16
File Type:pdf, Size:1020Kb
focusdynamically typed 1 languages Seaside: A Flexible Environment for Building Dynamic Web Applications Stéphane Ducasse, Université de Savoie Adrian Lienhard and Lukas Renggli, University of Bern, Switzerland age-centric Web development structures an application into indi- The Seaside vidual scripts, each responsible for processing a user request and framework generating a response. Links pass control from one script to the provides a uniform, next. This imposes a go-to hardwiring of the control flow because pure object-oriented P each page must know what comes next. Although software developers have view for Web long considered go-to statements harmful,1 they are still present in today’s applications. mainstream frameworks, and they hamper the reuse of pages in different parts Exploiting Smalltalk’s of the application. Another issue with Web ap- approaches provide mechanisms to model con- plication frameworks is the limited support trol flow over several pages with one piece of reflective features, they provide for composing multiple parts on code.3–5 WebObjects, Ruby on Rails, Google Seaside reintroduces the same page. The client-server relationship’s Web Toolkit, and .NET, on the other hand, of- stateless nature requires passing the current fer better abstractions by composing an appli- procedure call state back and forth between browser and cation from components, but they fail to model abstraction in server, inevitably leading to undesired coupling control flow at a high level. With any solution, between these parts. combining multiple simultaneous flows inside a client-server Recent Web application frameworks have the same page is difficult. context. tackled both of these problems. JWIG (Java In this article, after briefly discussing the key Extensions for High-Level Web Service Devel- challenges of modern Web application develop- opment),2 RIFE (Full-Stack Open Source Java ment, we present Seaside (www.seaside.st), a Web Application Framework), Jakarta Struts, highly dynamic framework for developing Web and JBoss SEAM (Web 2.0 Application Frame- applications in Smalltalk. By exploiting Small- work) solutions model control flow explicitly. talk’s dynamic nature and reflective capabili- However, most of these approaches don’t inte- ties, Seaside offers a unique way to have multi- grate well with the rest of the code, because it’s ple control flows active simultaneously on the necessary to specify the flow in external XML same page. Furthermore, there’s no need to re- page-flow specifications or to use a different compile and restart Seaside application servers programming language. Continuation-based after each modification. Web developers can 56 IEEE SOFTWARE Published by the IEEE Computer Society 0740-7459/07/$25.00 © 2007 IEEE debug and update applications on the fly, thus between the client and server to provide the il- reducing development time considerably. lusion of developing a desktop application. Smalltalk’s reflective capabilities make this Web development challenges high abstraction level possible. Smalltalk is a To bring Web application development to uniform language that applies simple princi- the same level as desktop application develop- ples systematically. In Smalltalk, everything is ment, a Web development environment or lan- an object—an instance of a class. Objects ex- guage should offer the following key features: clusively communicate through message pass- First, it should have reusable and compos- ing. In addition, Smalltalk supports closures, able components. A Web application logically anonymous functions that can be passed contains reusable components—input forms, around, stored in variables, or executed at a sortable reports, and so on. Building applica- later time. tions from reusable parts is natural. In addition, Smalltalk is written in itself and offers pow- these components should define their own con- erful reflective capabilities: structural as well trol flow. Composing new components out of as behavioral reflection.7 We limit our brief several other components, each having a differ- overview to the reflective capabilities that en- ent flow, should be easy to achieve. able creating a powerful Web development Second, it needs to produce valid XHTML. framework that offers multiple control flow Producing valid XHTML code and connecting composition, hot debugging, and hot recompi- it to the application logic is difficult, especially if lation. The reflective features of Smalltalk are the XHTML code and application logic must be comparable to those of the Common Lisp Ob- developed in different environments. Template- ject System (CLOS),8 except that Smalltalk of- based XHTML generation lacks the host lan- fers full access to the execution stack. These guage’s power and expressiveness. Seamless in- features include the following: tegration of development tools is often missing. Third, it should enable hot debugging. Effi- I Shape and class changing. Objects are in- ciently identifying bugs is a major challenge for stances of classes. When the class changes Web developers. Web applications are becom- (that is, when instance variables are added, ing increasingly more complex, and the charac- renamed, or removed), Smalltalk automat- teristics of client-server interaction make de- ically migrates all instances of the class. bugging more complicated, especially because I On-the-fly recompilation. Developers can advanced debugging support is often missing in define and recompile methods on the fly. A today’s mainstream approaches. The ability to changed method’s currently active execu- hot-debug exceptions and use break points tion contexts run to completion using the would speed up productivity considerably. old definition. Once a problem was fixed, the session could re- I Stack reification. In addition to self and sume at the place where it had left off. There super, Smalltalk offers a third pseudovari- should be no need to restart and navigate to the able, thisContext, which represents the problematic part of the application continually. execution stack on demand. For efficiency, Fourth, it should support hot recompilation. Smalltalk reifies the stack (that is, makes it On-the-fly method recompilation—that is, re- an object) only when the pseudovariable is compiling a method while the application is run- used. This object is causally connected to ning—is important because it lets developers up- the stack it represents. Therefore, not only date the code without restarting the session. does this object represent the stack, but any This is especially beneficial for Web develop- change made to the object reflects onto the ment because it avoids time-consuming edit- execution stack itself. Hence, developers compile-run cycles. Hot recompilation is a nec- can manipulate the stack to change the pro- essary requirement for hot-debugging support. gram’s execution. For a more in-depth presentation of these problems, please see our previous work.6 Seaside’s key features Seaside is open source, and many applica- Smalltalk’s reflective capabilities tions have used it since the first version of it Seaside introduces an abstraction layer was released in 2002. Originally written by Avi over the asynchronous interaction protocol Bryant (a consultant at the time, and now September/October 2007 IEEE SOFTWARE 57 I Programmatic XHTML generation. Fol- TodoFilterView lowing Smalltalk’s principle of treating http:/ / localhost/seaside/todo everything as an object, Seaside provides a TodoApplication very different approach to XHTML gener- To-Do List ation compared to template systems. Sea- What can you do today? side generates XHTML through an object TodoListView Filter: All Completed Pending Due Date layer using pure message sending. Using block closures, Seaside binds action call- Repair and clean the bike 1 February 2007 edit remove backs to components. Read “The ACME Novelty Library” I Multiple simultaneous control flows. Each 15 May 2007 edit remove component can define its own control Buy birthday present 11 June 2007 edit remove flow independently from the other com- add ponents displayed on the same page. This makes it possible to implement business logic spanning multiple pages as one con- tinuous piece of code. The enabling fea- ture is the concept of continuations, which Figure 1. The to-do harness Smalltalk’s ability to access and application, built from owner of dabbledb.com), Seaside is continually manipulate an execution stack. three different Seaside under active development by a growing com- I Hot debugging, code-editing, and recom- components. munity of contributors, including the third au- pilation. Seaside offers excellent develop- thor of this article. Here, we discuss the key ment support; most notably, it makes the features and characteristics of Seaside and how debugger work seamlessly with Web ap- they address the Web development challenges plication code. Smalltalk enables this that we identified earlier. Because of space lim- through hot recompilation and its treat- itations, we won’t discuss the advanced AJAX ment of exceptions as first-class objects, (Asynchronous JavaScript and XML) support which can be inspected and resumed. offered by Seaside (see http://scriptaculous. seasidehosting.st for details). In the remainder Domain-specific language of this article, we use a simple application that for generating XHTML lets users manage a to-do list of pending tasks. Seaside doesn’t keep XHTML code fragments Figure 1 shows the main view, which contains in external files; there is no template