Spaghetti Code for the 21St Century
Total Page:16
File Type:pdf, Size:1020Kb
Web Applications – Spaghetti Code for the 21st Century Tommi Mikkonen and Antero Taivalsaari Sun Microsystems Laboratories P.O. Box 553 (TUT), FI-33101 Tampere Finland {tommi.mikkonen, antero.taivalsaari}@sun.com Abstract have reintroduced problems that had already been eliminated years ago in the aftermath of the “spaghetti The software industry is currently in the middle of a code wars” of the 1970s. 1 paradigm shift. Applications are increasingly written In this paper , we investigate web application for the World Wide Web. Unfortunately, the development from the viewpoint of software technologies used for web application development engineering principles such as modularity, consistency, today violate well-known software engineering and portability. We argue that current web principles, and they have reintroduced problems that technologies are inadequate in supporting many of had already been eliminated years ago in the aftermath these principles, but that there is no fundamental of the “spaghetti code wars” of the 1970s. In this reason for web applications to be any worse than paper, we investigate web application development conventional applications in any of these areas. Rather, from the viewpoint of software engineering principles. the current inadequacies are just an accidental We argue that current web technologies are consequence of the poor conceptual and technological inadequate in supporting many of these principles, but foundation of the web development technologies today. also that there is no fundamental reason for web The structure of this paper is as follows. Section 2 applications to be any worse than conventional provides an overview of web development, followed applications in any of these areas. Rather, the current by an introduction to software engineering principles in inadequacies are an accidental consequence of the Section 3. Sections 4 and 5 analyze web development poor conceptual and technological foundation of the technologies in view of the software engineering web development technologies today. principles and some additional topics, and Section 6 offers possible solutions to emerging problems. Finally, Section 7 concludes the paper. 1. Introduction 2. Web development – A view from the The software industry is in the middle of a trenches paradigm shift towards web-based software. Consequently, applications are increasingly written for The World Wide Web has undergone a number of the web rather than for any specific type of operating evolutionary phases. Initially, web pages were little system, CPU architecture or device. We believe that more than simple textual documents with limited user the trend towards web-based applications will continue interaction capabilities. Soon, graphics support and and even strengthen in the future, causing a form-based data entry were added. Gradually, with the fundamental change in the way people develop, deploy introduction of DHTML [12], it became possible to and use software. create increasingly interactive web pages with built-in Unfortunately, programming languages and support for advanced graphics and animation. software development environments and tools have not Today, we are in the middle of another major yet adapted to this ongoing shift. Today, software evolutionary step towards “Web 2.0” technologies, development for the web is based on a myriad of commonly associated with systems such as Ajax [5], technologies and tools with little consistency or elegance. Even worse, many of the technologies violate 1 An earlier version of this paper has been published as Sun Labs established software engineering principles, and they Technical Report TR-2007-166, June 2007. Ruby on Rails [35], and Google Web Toolkit (GWT) ebay.com, or cnn.com contain large chunks of HTML, [34]. However, these technologies are still hybrid CSS and JavaScript code, in which HTML definitions, solutions and only partial steps in the evolution style sheets and JavaScript functions are interspersed in towards using the web as a true application platform. no specific order, other than the order established by In general, they enable building web sites that behave the tools used to generate the web page. Consequently, much like desktop applications, for example, by the source document of such web sites is often nearly allowing web pages to be updated one user interface unreadable to humans. Furthermore, the document element at a time, rather than requiring the entire page usually contains generous hard-coded references to to be updated each time something changes. In this other similar documents and resources such as images paper, we refer to such applications as web or animations. These resources may be located applications. anywhere in the world, and they are usually included in The fundamental components of the web browser the document in the form of long Uniform Resource include the Hypertext markup language (HTML), Locators (URLs). Some of these entities do not even Cascading Style Sheets (CSS), the JavaScript scripting need to be available, in which case the browser ignores language, and the Document Object Model (DOM). In the references and uses a placeholder instead or the following, we provide a summary of these overlooks the entire item. This is enabled by the technologies: general principle to ignore erroneous or incomplete 1. HTML is the predominant markup language for the parts of the web documents. creation of web pages. It provides a means to If the document that represents the web site is describe the structure of text-based information in commonly difficult to read, the actual behavior of the a document – by denoting certain text as headings, document is even harder to understand. This is because paragraphs, lists, and so on – and to supplement the typical user interaction model of the web is such that text with interactive forms, embedded images, that a new web page is generated and sent to the and other objects. browser each time the user clicks on a link or a button 2. CSS is a stylesheet language that is used to on a page. While adequate for displaying documents, describe the presentational aspects of a document the approach is not ideal for Web 2.0 development, in written in a markup language. A stylesheet allows which the web browser runs applications that behave the stylistic rules of a web page (e.g. colors and like conventional desktop applications, with rich fonts) to be defined independently of the content desktop-style user interface and direct manipulation of the web page. capabilities beyond navigation of pages. The above technologies do not introduce a coherent 3. JavaScript. In addition to declarative HTML and foundation for real applications on the web. Rather, CSS definitions, a web document can also contain they reflect the evolution of the World Wide Web, in executable code. The most commonly used which new features have been added on top of existing scripting language on the web today is JavaScript features. For instance, the I/O model to generate new [10]. Syntactically JavaScript resembles the C and web pages on the fly when anything changes seems Java programming languages. However, in outright arcane compared to the direct manipulation practice JavaScript is a much more dynamic, capabilities provided by most desktop applications in interpreted language that borrows features from the 1980s and 1990s. other highly dynamic languages such as Smalltalk In order to compensate for the inadequacies of the [11], Lisp [20] and Self [36]. underlying technology, today's web development 4. DOM is a platform-independent way of environments rely extensively on tool support. Tools representing a collection of objects that constitute such as Adobe Dreamweaver and Microsoft a page in a web browser. The DOM allows a Expression Web are utilized for enhancing the end-user scripting language such as JavaScript to experience and for providing a more reasonable programmatically examine and change the web development experience. This has made web page. Effectively, the DOM serves as an interface development a lot less arduous. However, it has also – essentially a large shared data structure – exacerbated problems: If programmers had been fully between the browser and the scripting language, exposed to the gruesome details of web development, allowing the two to communicate with each other. they would have undoubtedly questioned some of the In practice, web pages that utilize the above four technological foundations and put more pressure on technologies – serving as the logical equivalent of improving the underlying technology. “binary code” of traditional applications – are often messy. Even major web sites like amazon.com, 3. Software engineering principles these technologies bring the need to apply software engineering principles to web development. In 1968, Edsger Dijkstra started his crusade against In general, web development in its current form “spaghetti code” [7]. Spaghetti code is a pejorative resembles software development in the 1970s before term for source code that has a complex and tangled real engineering principles were applied. We argue that control structure, especially one using many gotos, there is a need to introduce engineering principles to threads, global variables, or other "unstructured" web development. constructs. Next, we investigate web development in view of As highlighted by the spaghetti code discussions, software engineering principles. Our analysis is software engineering remained an undeveloped, independent of any particular web