Pattern in RIA

2009-01-17 17:49:48 +0100

The Flex framework is getting more and  more populair, and other similar RIA-frameworks as JavaFX and Sliverlight get a lot of attention. Some people see Flex as a alternative for webframeworks as Widget, JSF, Struts or GWT. However, there's something fundementelly different. When program in Flex, you actually build a client-application. That application runs entirely on the client's computers. The client connects to the server only when the client need information from the server. The client retrieves information via (web)services.

The pattern (as you can call it) is very unlike webframeworks, where the software runs mostly on the server. When a user accesses a webapplication, the webframework will generate html, javascript and xml and send that to the client's webbrowser. The webframework also needs to create a (HTTP-)session along with a sessionid that is stored at the client-computer.
When a client performs some interaction, like pressing a button, a relatively complicated process is started: a javascript event or browser submit is emitted. The webframework will retrieve that event on the server using generated javascript- and html-code. Using the sessionid, the right user-session, containing client-data is loaded after which more automagic processes are performed.
You might wonder, what about Ajax ? The answer, with Ajax, or JQuery or other framework, the only advantage is, in case o a UI-event not the entire browserpage has to be reloaded and shown on the user, but only a part.

Not so long ago most enterprise software was developed as client-server: a client application would run on an users computer, while the server would consist of a database server. The client would make a connection to the database. The (business) logic of the software was contained in the application, while the database contained the data.
This development-model was quite easy for developers. I don't have hard data, but I think the productivy was much higher back then. My guess is that, for many simple CRUD-like requirements, a average Visual Basic, Delphy, Clipper developer was a lot faster.
Of course one of the mayor problems back then, were the installation and maintance of the client computers. Webapplications pretty much solved that, as the only client software you had was the browser.  Another problem is security: usually the client was connected with the server via a direct connection to the database. That means, if an unauthorized user would gain access to the client software he could do a lot of harm.
In webapplications, a user can only access the software by logging in the the webapplication. Without a username/passsword or other means of authentication, getting access to the server is very hard.

In modern RIA frameworks these problems are mostly solved. The software runs in a standardized plugin like the flash-player or java-player. That software is a lot easier to maintain then custom client software. A RIA-application accesses the server via a webservice. Fine-grained security can  added accessed to the webservice, preventing unauthorized access. That way, access to the server/backend can be controlled.

All in all, modern RIA bring back productivity to the developer and the user. Developers finally don't have to waste time learning yet another greatest framework (Struts, SpringMVC, JSF, ADF, GWT), and solving problems inherently part of webdevelopment (http-sessions, javascript debugging, html hell, generated code) . Users finally don't have to wast time waiting for browser refreshes, loading times and timewasting slow operations.

For an overview on different RIA-frameworks, and more on this subject see: Rich Internet Applications: State of the Union . The term design pattern for RIA I got from the following presentation of a Adobe Evangelist on J-Fall '08.

Read more

Scala release

2009-01-15 00:36:47 +0100

The final release of Scala 2.7.3 is out! You can download the release from the scala-download page.

Some background: Scala is a elegant language that runs on the JavaVM. Unlike languages like Ruby and Groovy, Scala is statically typed. One of the reasons a lot of people like dynamic languages more than Java, is because Java is very verbose. That verbosity is, amongst others, because of its type-system.
However, unlike Java the typing-system is much more elegant and flexible. Because Scala can infer types, you'll have to define types only when necessary. Look for example at the following code (taken from the Scala website):

object Maps {
  val colors = Map("red" -> 0xFF0000,
                   "turquoise" -> 0x00FFFF,
                   "black" -> 0xFFFFFF,
                   "orange" -> 0xFF8040,
                   "brown" -> 0x804000)

  def main(args: Array[String]) {
    for (name <- args) println(
      colors.get(name) match {
        case Some(code) =>
          name + " has code: " + code
        case None =>
          "Unknown color: " + name
      }
    )
  }
}

There are no explicit type definitions, eventhough every defined value is statically typed. The scala compiler can infer that the val colors should have type scala.collection.immutable.Map[java.lang.String,Int]. Compare that to Java, where you'd  have to use Map<String,Integer> several times.
Minor sidenote: there are languages that have an even more advanced typing system, see, this nice article.

Furthermore, another what's very much to like about new dynamic languages is it's extendibily. You can extent a language like Ruby or Groovy, and create a new internal language.  Eventhough Scala is statically typed, in Scala this is possible as well.
Let's say you want a sort method for the general Array type. This can be accomplished with the following code:

/* Defines a new method 'sort' for array objects */
object implicits extends Application {
  implicit def arrayWrapper[A](x: Array[A]) =
    new {
      def sort(p: (A, A) => Boolean) = {
        util.Sorting.stableSort(x, p); x
      }
    }
  val x = Array(2, 3, 1, 4)
  println("x = "+ x.sort((x: Int, y: Int) => x < y))
}

There's a lot more exciting, as a last example, I put a code-snippet that demonstrates how XML is integrated in Scala:

  val header =
    <head>
      <title>
        { "My Address Book" }
      </title>
    </head>;

  val people = new AddressBook(
    Person("Tom", 20),
    Person("Bob", 22),
    Person("James", 19));

  val page =
    <html>
      { header }
      <body>
       { people.toXHTML }
      </body>
    </html>;

Finally, an example of a quicksort taken from this sample website. Impressive, but I am to much unexperienced in Scala to grasp that code immediately:

  def sort[A <% Ordered[A]](xs: List[A]): List[A] = {
    xs match {
        case List() => xs
        case _ =>  sort(for(item <- xs.tail if item < xs.head) yield item) ::: List(xs.head) ::: sort(for(item <- xs.tail if item >= xs.head) yield item)
    }
  }

Below a book about Scala I recently read

Read more

Archive

subscribe via RSS