My name is Juri Strumpflohner and this is my technical blog. I'm a software architect, .Net, Android, Web and Java dev, TDD and best practices promoter and martial arts practitioner.

Recent Posts Subscribe

Dear reader of Juri's TechBlog,
I moved my blog to a new domain and a new hosting solution as well. I'm now blogging on juristr.com.

First steps with Silverlight. What about GWT?

Last week I had some time which allowed me to do some experiments with Microsoft Silverlight. I had to give it a try since you hear so much on the web about it, so I was quite curious, how it works out.
When searching for a tutorial, I watched a couple of videos and finally ended on Scott Guthrie's blog where he presents a "End-to-End tutorial" of creating a Digg search client with Silverlight 2. I followed the tutorial and it's great, since it gives you quite a good feeling of the environment. The tutorial consists of the following eight parts:

And here's a screenshot of my outcome (basically the same as on Scott's tutorial obviously :) ):
I was really impressed of the environment. And you know...as most of us probably do, I'm personally always aiming to build highly user-friendly applications because at the end that's what counts, since that's the point where your users interact with your application. When we talk about web applications and user-friendliness, most often we have to speak about high-responsiveness of the web application, which again - on the web - is strongly connected with Ajax. Traditional Asp.net applications don't give you this value. Having the page refreshing on each action is somehow annoying because the user has to continuously wait till he sees the user interface again for being able to continue and this is somehow distracting.

What regards Ajax technologies, Google is for sure one of the leaders in that field. They are able to build highly-interactive web applications (i.e. Gmail , Google Maps ,...) which don't feel any more like web applications but more like normal desktop apps. I did a couple of experiments also with the GWT (Google Web Toolkit) which allows you to program (quite) normal Java code which then gets translated into pure JavaScript by the GWT-compiler. Again these applications are great. GWT allows you to build desktop-like applications running on the browser that communicate with some server over web service calls (using XML, Json,...) or even with RPC (remote procedure calls). Programming GWT is cool and there are a couple of good online tutorials. Everything is perfectly integrated into Eclipse , and you can even debug (!!) your application, your written Java code in Eclipse, which is not that straightforward if you think of debugging JavaScript code. Also the deployment process is easy, you've just to copy the compiled (generated) set of HTML and JavaScript files on your webserver. If you then combine your GWT client with advanced web frameworks like the Spring Web MVC framework you get even more benefits out of it. Although it is possible, that process of letting GWT communicate with your Spring application framework through GWT RPC calls is not that easy (I may post a short tutorial on that on some later posts). The point with GWT, as with most Java technologies, is the learning curve. You need to investigate quite a lot initially to really become productive (especially in designing good user-interfaces and user-interface components).
Now why did I mention GWT? Well because Silverlight seems to be somehow Microsoft's answer to it. Well not exactly because it is more similar to Flash than the GWT, but it is Microsoft's trial to provide a framework for easily developing highly interactive web applications. You can build Silverlight applications by using XAML files and the .Net framework. So you don't have to learn anything new and that will be one of the major advantages. Another point which is really cool, is how easily you can bind object properties on your interface (inside the XAML file). Scott Guthrie's tutorial points this out. The best is that you try the tutorial to get a feeling of Silverlight.

If you compare Silverlight with GWT from the point of the prerequisites which you need to run the different kind of applications, GWT is for sure the winner. It uses the standard JavaScript which is supported by all of the commonly used browsers. The produced JavaScript is performance and cross-browser optimized. For being able to run Silverlight applications you need to download the framework to the client first (similar to Flash, where you first have to install the Flash Player).
From a "productivity" point of view, I think Silverlight will be better, but it very much depends on the situation. If you start from scratch, Silverlight will for sure be better, due to the Microsoft "visual" way of programming. You have your designer, where you can quickly compose several predefined components. By using Microsoft Expression Blend, designing UI's will even be more easy. Also the rendering of the object-data on the UI is straightforward due to the implemented data-binding mechanism. Moreover you can nearly continue programming like you were accustomed when building normal Asp.net apps. Here, GWT is (initially) a bit more complicated. For programming you can only use a subset of the Java programming language. This is due to the fact that GWT "compiles" Java into JavaScript and so the GWT team has to continuously implement the new Java features into their compiler. Designing the UI is a bit awkward. You have to keep a good overview and impose a good structure, by creating UI components which again you combine on the UI s.t. everything remains flexible and exchangeable. As I mentioned, this will produce some overhead, since initially you spend quite a lot of time in producing good UI's. Once you have your components, you may reuse them however on your other GWT apps. Unfortunately there don't exist any predefined "visual editors" for GWT integrated in Eclipse. Instantiations however provides one (you have to pay it), but I never tried it out. Another "disadvantage" is the databinding mechanism (binding your object-data to the UI). You have to create a data-binding mechanism yourself. There doesn't exist anything like in Silverlight. MVC works out well here, and again, if you design your components in an intelligent and smart way, you're able to reuse them. The prerequisite here is that you have a good understanding of such design patterns as MVC, observer, mediator etc...everything it includes basically. In Silverlight you can get rid of these details which from a productive point of view may be an advantage, from a learning point of view however you loose some interesting aspects.

Don't take this comparison too seriously, it's just a really informal description of what I experienced somehow...to do a better job, one would have to really program the same sample app with Silverlight and GWT and extract some metrics.

Generally speaking, I think that Silverlight is as most of Microsofts technologies. Microsoft provides you with great and powerful tools, where you can quickly build and set-up a  running application, possibly already connected to some datasource. But that may be also a dangerous part, these "fast" solutions may not always be optimal from an architectural point of view, but again that would be enough stuff for another post (which may come :) ).
But I'm concluding this post now, it already became too long...btw with this post is number 100 for this year :D
I wish you Merry Christmas!!

References:
Install Silverlight
Silverlight tools for Visual Studio 2008
GWT main site
http://code.google.com/webtoolkit/app_gallery.html

Using extenders to abstract details and improve code readability

Extenders are a really cool feature of C#, which can be quite handy sometimes. I found the following extender I've written the most useful. Think for instance how often you have to write conditions like

if(someObject.stringPropertyX.Equals("abc") || someObject.stringPropertyX.Equals("def") || ....){
    //do something
    ...
}else{
   //do something other...
   ....
}
This concatenated or's or also ands may be quite messy to look at and also to change. And in addition it's not very comfortable to write since you repeatedly have to write the object.property etc...(or copy&paste it). Packing all of this inside an extender method for the string object (this is just a special case, you could do that of course also for other kind of objects) makes everything much cleaner:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Some.Namespace.Extenders
{
    public static class StringExtender
    {
        /// <summary>
        /// Evaluates whether the String is contained in AT LEAST one of the passed values (i.e. similar to the "in" SQL clause)
        /// </summary>
        /// <param name="thisString"></param>
        /// <param name="values">list of strings used for comparison</param>
        /// <returns><c>true</c> if the string is contained in AT LEAST one of the passed values</returns>
        public static bool In(this String thisString, params string[] values)
        {
            foreach (string val in values)
            {
                if (thisString.Equals(val, StringComparison.InvariantCultureIgnoreCase))
                    return true;
            }

            return false; //no occurence found
        }
    }
}
So using the extender with the dummy example above would result in the following code
if(someObject.stringPropertyX.In("abc", "def",...,"xyz"){
   //do something
   ...
}else{
  //do something other...
  ....
}
Doesn't this look much nicer?? I find it much more readable. It abstracts and hides all of the logical operators and property calls. By looking at the code you immediately see the important facts without being distracted. You're also much quicker in adding (in this case) new strings for comparison in contrast to the case before where you have to make sure to copy (write) the object + parameter invocation, add the logical connector properly etc... You could easily do the same with the AND logical operator and also for the corresponding negations (I just didn't work out the details).

A thing which I don't really like about the extenders is the fact that you have to explicitly define the extender class's namespace in the new class where you want to use the extended methods. Otherwise you won't see your extended methods. This is kind of stupid because the other developers in the team won't recognize the method until you tell them explicitly to use it (which anyway is the best way to ensure it).


Related links:
http://manfred-ramoser.blogspot.com/2008/10/extension-methods-in-c.html