7. Web Application and Services

7.1. 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:

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 [http://jobs.cs.luc.edu/post/41214148685/telecommuting-internships-and-full-time-positions-at] is an interesting local internship ad.

7.2. 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.

7.3. 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.

7.4. Web Applications

The predominant web application frameworks targeting Scala are Lift [http://liftweb.net] and Play! [http://playframework.com]. Typesafe has adopted the latter as part of its official stack [http://typesafe.com/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.

7.4.1. Examples

7.5. 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 [https://code.google.com/p/implementing-rest/wiki/ByLanguage] 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 [http://spray.io] 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 [https://devcenter.heroku.com/articles/scala] 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.

7.5.1. Examples