Web Application and Services ============================ Professional Context -------------------- *Disclaimer: I am not affiliated in any form with Typesafe.* In this section, we discuss how Scala can enhance the pedagogy in certain foundational and applied advanced courses. Given that the majority of students coming out of our undergraduate and graduate programs find jobs in local and global industry, we place considerable emphasis on professional practice. To this end, we draw on several (local and global) resources: - `Uncle Bob `_ - `ThoughtWorks Technology Radar `_ - `IEEE Software's Software Engineering Radio `_ We attempt to strike a balance among solid foundational knowledge, state-of-the-art technology, and job market demands. In particular, we have adopted the following rule for our advanced courses and research projects: *new code in Java (the language, as opposed to the platform)*. We also strive to choose technologies that scale properly. Here, the typical startup story goes like this: Implement in RoR, oops, it doesn't scale, then redo in guess what language? There are an increasing number of good language and platform choices here, and in our experience, Scala is one of them. The job market is also increasingly interested in Scala. `Here `_ is an interesting local internship ad. Curricular Context ------------------ Starting in 2010, we have been incorporating Scala into several of these courses, taught mostly by Konstantin and experienced professionals serving as adjuncts. - `COMP 373/473: Advanced Object-Oriented Development `_, using Scala since spring 2010, planning to add Android in spring 2014 - `COMP 372/471: Theory (and Practice) of Programming Languages `_, using Haskell (and some F#) since fall 2010 - `COMP 338/442: Server-Side Software Development `_ (focusing on web applications), using Scala with the `Play! framework `_ since fall 2010 - `COMP 388/433: Web Services Development `_, using Scala with the `spray toolkit `_ since spring 2011 - `COMP 313/413: Intermediate Object-Oriented Development `_ (focusing on software design and architecture), using Java with Android since fall 2012, considering the addition of Scala down the road Why Scala? ---------- In our experience, Scala can help with the pedagogy of advanced applied courses in multiple ways: - less boilerplate - focus on deep concepts - focus on good practices In the remainder of this section, we will give an overview of web application and web service development in Scala and contrast the experience with the corresponding Java-based techniques. Web Applications ---------------- The predominant web application frameworks targeting Scala are `Lift `_ and `Play! `_. Typesafe has adopted the latter as part of its `official stack `_, and we had actually started to use Play! in our course before Typesafe's decision was known. The primary concerns in the development of web application for human users---as opposed to a web service for programmatic consumption---are - views + presentation + visual styles + layout + navigation + i18n - controllers + validation + authentication + dynamic behavior/interaction/state - models + services + domain model - persistence + database technologies + mapping domain object to persistent storage - testing + unit testing + integration testing + functional testing + acceptance testing + performance/load testing When using a Java-based stack, we typically address these concerns with a stack tied together by a dependency-injection framework such as Spring and an object-relational mapper (ORM) such as Hibernate, along with a MVC framework for the upper layers. When using a Scala-based stack, we an express an equivalent architecture much more concisely and using language mechanisms instead of requiring a DI framework. Examples ++++++++ - `Linear regression in Java with Spring, Stripes, and maven `_ - `To-do list in Scala with Play! `_ - `Live version of the to-do list deployed to the cloud `_ Web Services ------------ As opposed to the Simple Object Access Protocol (SOAP), we will focus on representational state transfer (REST), which has emerged as the preferred approach of the broader agile community. The implementing-rest community has put together a helpful `language matrix `_ of REST libraries, toolkits, and frameworks. Typesafe's stack does not yet include strong support for RESTful web services in the sense of a high-level DSL for request routing, which is where some of the choices in the language matrix come into the picture. We have picked `spray `_ not only because the author is from Konstantin's home town but also because it is: - concise - flexible - type-safe - focus on HTTP and request routing - more and more widely used and supported Scala and Spray are supported by `Heroku `_ and several other newer APaaS cloud providers. Deploying a service to the cloud requires a simple Git commit; this makes it possible to achieve continuous delivery. Examples ++++++++ - `Social bookmarking example based on Java with the Restlet framework `_ - `Prime number checker based on Scala with spray `_