Friday, 4 February 2011

Android Development Made Easy

I treat myself (and my family) to a Samsung Galaxy Tab for Christmas last year. It's a nice device, I prefer it over the iPad which, for me, is just too big to be portable and, also, lacks the full browsing experience.

To date I've only had hands on with Android using friends phones - I have a BlackBerry myself. Android's a great platform, with some cool applications and an expanding App Store environment. that's starting to rival Apple's. For really cool apps I recommend you get yourself a copy of Google Sky - absolutely amazing.

In my work, I've been exploring the application of mobile devices to Equipment Maintenance and Asset Management. I thought, seeing as I had a Galaxy Tab to hand, I'd take a look at prototyping some concepts on it.

So, I headed over to the Android Development Site and got the SDK, Eclipse Plug-In and Device Emulator. For accurate Galaxy Tablet emulation you need the Galaxy Tab avd profile on Samsung's Mobile Innovator site.

Naturally the native platform for Android development is Java and the SDK is very comprehensive. But, as you'd expect, it is quite heavyweight and there's a substantial code set just to get a basic application up and running. I guess this is okay if you're a full time professional Android development or you've really set up to dedicate huge amounts of time to the platform, but for me it was all too big a learning curve given all the projects I currently have on the go.

After a quick Google I came across Android Scripting, used be called ASE now called SLA - Scripting Layer for Android. SLA has been around for a year, but it's not a core supported component of the SDK, but a Google Code project released under an Apache License.

And what a great project it is. Essentially SLA's all about lowering the barrier to developing simple Android apps supporting a number of common scripting languages such as JavaScript, Python, Lua etc. To install, simply scan the barcode (more on barcodes later) and, assuming you've got a Net connection, the core SLA package will install. The basic SLA runtime comes installed with only HTML and JavaScript interpreters.

In terms of settling on a scripting language I choose Python. I've been doing a fair bit in Python currently on a collaboration with some work colleagues and I'm really liking it for it's productivity. Also, the Python library is a native C and complied so, in a lot of cases, is just as quick as the JVM.

Productive is it, and just to show you how much you can do with very little code, take a look at the following:
import android

droid = android.Android()
barcode = int(droid.scanBarcode().result["extras"]["SCAN_RESULT"])
url='http://books.google.co.uk/books?isbn=%d' % barcode
droid.webViewShow(url)
As you can probably guess from reading the code, this little app invokes the Tablet's camera based barcode functionality, get's the barcode value, concatenates that with the URL for Google Books that displays a web page for the book you've just scanned! To support the barcode API call you do need the ZXing library installed. Still, pretty cool though.

Wednesday, 19 January 2011

NASA Conference on Intelligent Data Understanding

In October last year I had the privilege to attend the NASA Conference on Intelligent Data Understanding (CIDU) at the Intelligent Systems Division, Ames Research Centre in Mountain View CA.

CIDU is focused on applying Data Mining, Knowledge Discovery and Machine Learning techniques to a number of NASA relevant domains, including aviation, earth sciences and astronomy. These core areas of NASA's mission all have a common problem with the exponential increase in data generated. Whether this is the increased fidelity and resolution of the next generation telescopes such as the James Webb, or high resolution satellite data for near real time earth coverage mapping.

The main focus of the conference was on algorithm development, both improvement in accuracy and computation of existing algorithms and development of specific algorithms to solve certain classes of problem. Some of the applications were, for me, quite spectacular. In particular are the attempts to carry real-time classification of astronomical events from data streaming from digital sky surveys such as SDSS.

George Djorgovski, Co-Director for Advanced Computing Research at CalTech, gave a lecture on applying a number of advanced data mining techniques and algorithms to identify events such as Supernova etc. The real impressive aspect was the shear scale of the data being processed, in the Petabytes, and the fact that the goal was to able to react to these events in real-time to direct the right telescope / observation resources to investigate and gather detailed data.

Closer to my profession (and the reason I was there), were techniques to help drive diagnostics and prognostics in the aviation domain. Honeywell gave an interesting presentation on work they're collaborating with NASA on a next generation Vehicle Level Reasoning System. GE presented their research on Prognostics and anomaly detection on Jet Engines. The key difference between the Earth and Space Science fields and System Engineering, is, in general, the Systems Engineering problems tending to require combined (fused) data driven and model (physics) based approaches, rather then just data mining on it's own.

I guess to the casual observer these computing techniques may appear esoteric and only really relevant to high end science and complex engineering systems, but I believe that the exponential growth in data in business and consumer spaces will require the application of these techniques to have any chance of being able to "make sense" of it all. This is very much IBM's current viewpoint with their Smarter Planet theme.

The really exciting part of this conference though, was the knowledge that, as esoteric at they may seem, these computational capabilities are available to everyone, Open Source, though Apache Mahout. Mahout provides a lot of the core algorithms that the researchers presenting at CIDU were improving and / or extending. With Mahout sitting on top of the Hadoop platform and being available on Amazon EC2, everyone has (reasonable) access to their very own NASA Ames Supercomputing facility!

All in all a very fruitful event. Here's hoping I get to attend next year!

Wednesday, 22 December 2010

Domain Specific Languages

If, like me, you started your software engineering career on classic time-sharing systems (for me it was a VAX 11/780) you probably had a small restricted set of programming languages available to you, e.g. Fortran, BASIC, Pascal etc. These languages are all classed as General Purpose Languages. What binds GPLs together is that they are designed to solve any class of software problem and are not tied to any domain. In fact, when you examine the structure of languages like C, BASIC, Fortran, Java, they all share a lot of common constructs in terms of control structures, branches, looping, variable assignment etc.

This was all straightforward enough, in fact early in my career I moved  (fairly) freely from programming in BASIC, Fortran, C and Pascal. In the early 90s I moved into the CAD (Computer Aided Design) / PLM (Product Lifecycle Management) industry, specifically the AutoCAD industry. It was at this point I was introduced to a language which, at first, completely foxed me. This language was Lisp, specifically AutoLisp.

At a first view, Lisp looked quite alien, endless parenthesis, strange functions such as car, cons and cdr, but once I got to grip with he basics the power of the language became apparent. The key to Lisp are sets and lists, in fact Lisp stands for List Processing. Here's a bit of sample Lisp code:
(setq cntr 1)
(while (cntr < 5)
 (princ cntr)
 (seqt cntr (+ cntr 1))
)
A pretty simple example that sets the variable cntr to 1, prints the value of cntr to the console, loops round 4 times. The key to the Lisp language it sets and lists and Lisp is fairly unique in that it is a homoiconic, i.e. the representation of the language syntax is a data structure primitive type of the language itself. XSLT and XQuery are also classed as homoiconic languages.

Lisp lends itself to programming AutoCAD quite well, as it was set and list orientated and with a CAD system a lot of the programming was aimed at manipulating geometry of the CAD model / drawing.

Anyway, back to homoiconic. The clever bit about Lisp is the fact that functions can be treat in the same way as variables, that is, functions can be passed as function arguments and returned as function values. It's this key property that allows powerful abstractions to be built in a language like Lisp, hence it use as a DSL. As always an example helps:
(defun double (x)
 (* 2 x) /* define a function double that simply times the argument by 2 */
)
Now, here's the clever bit, if we want to compute 24 we could use the double transform on 1 four times.
(double (double (double (double 1))))
Now, that's a bit long winded, even better would be a function that took a function and an object and repeated the function transform n times. In Lisp, that's doable.
(defun repeat-transformation (F N X)
  /* Repeat applying function F on object X for N times */
  (if (zerop N) /* Returns true if the argument is zero */
      X
    (repeat-transformation F (1- N) (funcall F X))
   )
)
What's happening in this code is, of course, recursion. The key is the funcall which given a function F and objects X1,X2...Xn the form (funcall F X1 X2 ... Xn) invoke the function F with the arguments X1 X2 ... Xn. The variable N is a counter keeping track of the remaining number of times we need to apply function F to the accumulator variable X.

I'm not planning to do in-depth programming in Lisp here. If you're interested in learning more about Lisp I recommend you take a look at Practical Common Lisp by Peter Seibel. The text for the book can be found on-line here. Hopefully, though, you've got the idea that a programming language can, in essence, manipulate itself to create a new subset language, hence a Domain Specific Language.

So what use are DSLs? A good real life practical example is Apache Camel. Camel is an integration framework that provides a implementation structure and runtime for the classic Hohpe and Woolf Enterprise Integration Patterns (EIP). Integration is a great application for a DSL as you have a common patterns to solve and components to 'wire' together. In Camel's case, the common elements are wiring Processors that carry out functions such as transformation, mediation, routing etc, with Endpoints that allow messages to be sent and received, e.g. JMS, HTTP etc.

To demonstrate how productive and powerful a DSL (and in this case Camel) can be, imagine you've got a systems integration problem to solve which involves reading files from one directory and placing them in another. Simple right? Here's a possible solution in Java.
public class FileCopier {
 public static void main(String args[]) throws Exception {
  File inboxDirectory = new File("data/inbox");
  File outboxDirectory = new File("data/outbox");

  outboxDirectory.mkdir();
  
  File[] files = inboxDirectory.listFiles();

  for (File source : files) {
   File dest = new File(
    outboxDirectory.getPath()
    + File.separator
    + source.getName());
    copyFile(source, dest); 
  }
 }

 private static void copyFile(File source, File dest)
  throws IOException {
   OutputStream out = new FileOutputStream(dest);
   byte[] buffer = new byte[(int) source.length()];
   FileInputStream in = new FileInputStream(source);
   in.read(buffer);
   try {
    out.write(buffer);
   } finally {
    out.close();
    in.close();
   }
 }
}
There's a fair bit of code their for a simple task. Also, we haven't addressed error handling, concurrency, polling for the files, keeping track of what files have been moved etc etc.

Now here's the sample problem solved with Camel DSL.
public class FileCopierWithCamel {
 public static void main(String args[]) throws Exception {
  CamelContext context = new DefaultCamelContext();
  context.addRoutes(new RouteBuilder() {
   public void configure() {
    from("file:data/inbox?noop=true")
    .to("file:data/outbox");
   }
  });
  context.start();
  Thread.sleep(10000);
  context.stop();
 }
}
A lot simpler. Most of the code above is Camel boilerplate, for example setting a CamelContext that's started (context.start()) and subsequently stopped (context.stop()). The integration logic is all defined in the RouterBuilder function and the from.to function. Essentially down from around 30 lines of Java code to 14. Also, all the things we didn't address in the pure Java example, e.g. error handling etc, is all handled by the Camel framework and runtime.

For another good example of application of DSL is FIT (Framework for Integrated Test). FIT looks to solve that eternal software engineering problem of testing and test scripts and closing the gap between developers, business analysts and end users. FIT reads HTML tables that map onto system classes methods and properties. A Business Analysts or End User creates a FIT document that describes the tests to be carried out in the form of the table with inputs and expected outputs. The FIT document can be created in Microsoft Word and exported as HTML. Developers then create Fixtures which map the FIT documents onto the business logic code of the application being tested.

In the case FIT, the DSL is, what FIT term, the Fixture. Fixtures wrap the specific application business logic that allows the FIT documents to execute the tests. A simple Fixture class can be seen below.
import fit.ColumnFixture;

public class Division extends ColumnFixture { /* Extending the ColumnFixture class allows the FIT runtime to map the input test tables to the logic code */
    public float numerator;
    public float denominator;
    public float quotient() {
        return numerator / denominator;
    }
}
The language that's currently getting most attention in the DSL world is Groovy. Groovy, if you've not yet come across it, is a lightweight Java like language and, like Lisp, supports closures and code as data and, therefore, ideally lends itself to DSL creation. There is a great simple example of a DSL for Stock Market transactions written in Groovy by Justin Spradlin here.

Increasingly, there are tools becoming available for DSL construction. A good example of one of these is Meta Programming System (MPS) from JetBrains.

So what's the future for DSL? I believe they have a place. I'm not sure there are too many advantages in trying to build DSLs for business applications, they are just too varied to gain extensive reuse and may be too unfamiliar for use by end users. The Apache Camel project shows the way for me with DSLs, accelerating the development of common development patterns, Groovy is also being used for this kind of 'plumbing' application.

If you want to found out more about DSLs I'd recommend visiting Martin Fowler's Wiki and taking a look at his book Domain Specific Languages.

Sunday, 6 December 2009

Information - The Missing Architecture in the Enterprise?

Enterprise Architecture approaches and frameworks, such as Zachman and TOGAF, talk about Business, Systems, Technical Architecture components, but rarely use the term Information Architecture. It appears, to me, that the majority of Enterprise Architecture frameworks and tools have their roots in 'traditional' systems and applications and have yet to catch up with the world of Mashups, REST, Situational Applications and Social Computing.

Enterprises today are still grappling with a myriad of LoB (Line of Business) applications, both COTS and bespoke, all with varying degrees of heritage and legacy. It's my view that SOA has failed to deliver, and that's backed up by a number of commentators including Anne Manes at The Burton Institute and Tim Bray, Father of XML, now Director of Web Technologies at Sun.

So were do Enterprises go from here? I believe the development of systems has almost split into two tracks, those that entirely embrace the paradigm of the Web and those within Enterprises that still seem to be 'stuck' in a pre-Internet age. Take a look at any Internet facing consumer application, if it's usability, experience, graphic design and content don't meet user expectations then users will simply go elsewhere and use another service. I'm sure everyone reading this has had the experience of some torturous e Commerce application where we've abandoned a transaction in shear frustration with idiocy of the site design.

There is a good reason for this of course, Enterprises have a large legacy of applications, typically packaged COTS solutions with large functional footprints such as ERP. Packaged application vendors have always struggled to keep their architectures in-line with technology developments. Internet service providers, on the other hand, have much greater freedom in their application architecture, essentially only constrained by the capabilities of a browser, and very little legacy to contend with.

There are now attempts to bridge the Enterprise / Internet divide with technology platforms such as Microsoft SharePoint and IBM Mashup Center. The key difference with these solutions is that they 'fuse' traditional business data (ERP, PLM, CRM etc) with Web 2.0 content such as Wikis and Blogs. Both IBM and Microsoft have recognised the potential to bring Web 2.0 to an Enterprise environment. These platforms, though, require new thinking if benefits are to be realised. This is where Information Architecture comes in.

What is Information Architecture? Well, as you'd expect, there are numerous definitions. In the O'Reilly publication Information Architecture for the World Wide Web, Information Architecture is defined as:
  • Organisation, Labelling and Navigation
  • Structural Design of the Information Space to support Intuitive Access to Content
  • Structure and Classification to support Information Access
  • An Emerging Discipline
Not sure it helps, but it's a definition. The key challenge is that these solutions bring together traditional LoB data, such as Parts Information, Purchase Orders, Customer Records etc, and allow you to combine these with unstructured content and workflow. The use of Mash-up type approaches allow end users to combine information sources and visualise it the way they wish. These capabilities, when combined, require a different approach to system design and implementation than any traditional packaged application.

Skills, normally associated with pure web site design are of greater importance, in some cases, than application functionality. Disciplines required include graphic design, interaction design, usability engineering, experience design, content management, knowledge management, as well as the core software development skills.

So how do you go about creating an effective Information Architecture? Often, Information Architecture is described as being made up of three components:



Business Context - an organisation's culture, resources, skills, business model and constraints
Content - Information an organisation produces and consumes, both structured and unstructured
Users - Reflecting the way people in the organisation in the Information Architecture design is critical to it's success.

Web Designers and Solution Architects have, in the past, tended to 'live' in separate worlds that never meet. I guess this is possibly due to the career heritage of people who have these roles, i.e. Web Designers typically have a graphic design background, Solution Architects tend to more technology orientated. Going forward, though, the next generation of Enterprise applications need to converge these two historically separate disciplines if there going to meet the needs of Internet savy users.

Friday, 26 June 2009

The Internet of Things

The Internet is, of course, now universal, with over 625 million hosts currently registered according to the Jan 09 ISC Domain Survey. Even with the advent of Internet enabled end devices such as 2.5/3G mobile phones, the majority of these connections will be computers of some kind.

But, what if you could connect almost any device to the Internet, medical devices, cars, toys, weather stations your home even? The possibilities for opening up new classes of applications are mind bloggling. Since the early days of the Internet there have always been people connecting 'odd ball' devices to the Internet, the Internet fridge is just one example.

Pretty much any electronics hobby enthusiast can rustle up a circuit with some form of sensor board and wire it to an Internet connected PC. Also, numerous companies have manufactured data loggers and instrumentation devices for years, and most of these can connect to PCs. The key to enabling this vision is standards and interoperability. Sun's approach does just that, focusing on bringing together Open Source standards and hardware, Java, ad-hoc networking and the Internet.

This is where Sun Microsystems is heading with its Sun SPOT vision. Sun SPOT is a SunLabs research project that kicked off in 2003. This work has led to Sun selling a Sun SPOT Developer Kit to the public, mainly to drive interest in potential applications. The video below outlines Sun's vision.


The key innovation is not only have Sun made the SDK Open Source, but the OS (Squawk) and, believe or not, the hardware. This means that anyone's free to download the SunSPOT bill of materials, circuit designs, schematics and drawings, send them to an outsource electronics fabricator (of which there are loads who will build you small batch runs) and you can have your very own custom device.

One of the major advantages of the platform is the fact all development is done in Java. Anyone who's had experience of developing for embedded systems knows that specific architecture, software engineering and programming skills are required. Sun have put effort into ensuring that any skilled Java Developer can pick up a Sun SPOT device and get going straight away without any embedded systems background. It's important to note that Sun SPOTS are much more that your typical data logger device, they're a computing platform in their own right. The ability to create ad-hoc mesh networks of these devices, coupled with Agent-Based software architectures is what makes these devices so unique.

So what are the potential applications. I work in the Defence industry and I can see applications in military and security. For example, imagine parachuting dozens of these devices across a theatre of operations, each fitted with an array of sensors. They would also have the ability to network with each and other military systems when they are in range, for example warning a squad of troops of potential suspicious activity in an area.

Applications that require remote data acquisition and logging are also obvious candidates. SunLabs have an experimental environmental monitoring solution called Canopee deployed to Kalakad Mundanthurai Tiger Reserve (KMTR) in India.

Sun are hoping to repeat their successfully strategy of getting Java onto just about any device you can think of, from mobile phones to digital tv set-top boxes. Their goal is to open up and accelerate the market for wireless sensor based applications by standardizing the hardware and reducing software implementation effort. It will also be interesting to see how this technology starts to converge with RFID.

Currently, most applications are in Universities and Research Labs, but given the momentum behind Java and the Open Source nature of the whole platform, I believe we could soon be seeing SunSPOT applications opening up in the near future.