Login

Scala

Scala is a general purpose programming language designed to express common programming patterns in a concise, elegant, and type-safe way. It smoothly integrates features of object-oriented and functional languages, enabling Java and other programmers to be more productive.

Leveraging Scala

In this article, I am going to introduce the computer programming language "Scala". I am going to use "Scala" to enhance my mobile site generation utility (see previous article for details).

Project Functional Enhancements
I want to add the following functions to the mobile site generator utility:

  • Publish a "Site Map" document that allows search engines to index my mobile web site.
  • Replace the current mobile sites's document file naming scheme. The current file naming scheme is numeric (E.G. doc-1.html, doc-2.html). My main website is built with the Drupal content management system (CMS). Drupal provides a facility for generating "Search Engine Optimization" (SEO) file names, and thus SEO friendly links. I want to use the SEO friendly file name/links in the mobile version of my website.
  • Add a mobile-friendly contact mechanism to each article. Currently, each article contains a footer section which directs readers to contact me via my website's main contact page/form. That contact/page form does not render properly on a mobile browser. I've already composed a simple contact mechanism that renders on a mobile device. An example is located at the bottom of this page. Thus, when republishing an article for the mobile version of my website, I want to replace the current contact box with the "mobilized" contact box.

Scala
Scala runs on the Java Virtual Machine (JVM). Thus, in a single program you can use both "Scala" and "Java" instructions. For this release, I replaced all of the Java functions with Scala with a single exception. I decided to use the Apache Common IO library to perform file/directory operations. Other than the file/directory operations I was able to re--write the mobile site generator fairly quickly in Scala.

Generating the SiteMap with Scala
A "Site Map" is an XML document. Scala has XML operations built directly in to the base computer language. In addition, Scala allows you intersperse the computer language instructions with document fragments. Most computer languages provide some facility to mix html/xml (document fragments) with business objects (computer instructions). This feature is sometimes referred to as "templates" (E.G. JavaScript/Html templates, Apache Velocity templates). Also known as "embedding" instructions (E.G. Embedded Ruby/ERB). Or the feature is implement as framework extension. For example, Microsoft's ASP framework, Java Servlet Paged (JSP), etc).

The ability to ember Scala statements in a XML block turned out to be quite handy. The implementation details bear this out.

Syndicate content