viernes, 6 de diciembre de 2013

Xamarin and Google Glass together

For the latest weeks I've been playing around with Google Glass, amazing technology!!! and for about a year I've been following Xamarin and using it for small projects/hackathons because I think that it is the PERFECT way to develop mobile apps.   Today it is time to try to use both together!!!

Let's start with some introductions:

Google Glass runs Android 4.0.4 and you can easily run any android app [1]  (thanks song for introducing me to Google Glass world).   You can run any standard android app, Google just released a specific SDK (the GDK) that you can also use with Xamarin if you want deeper integration with Google Glasses.

Xamarin is a cross platform framework allowing you to create mobile apps (e.g. for android) in C#/.NET will using the native UI framework in each platform.

Now, let's start having fun:

1. Download the standard Xamarin package and open Xamarin Studio

2. Create an Android project targeting an android version <= 4.0.4

3. Disable the system status bar and the application title for your Application with this code:
            Window.AddFlags(WindowManagerFlags.Fullscreen);
            RequestWindowFeature(WindowFeatures.NoTitle);


4. Use standard android controls, buttons, textviews...

5. Try to follow google guidelines if you want to create a coherent experience [2]



Screen on Google Glass


I don't have a Xamarin license to create something much better (because of the limitations of Starter licence) but if somebody gets one for me I'll be happy to build something much better to show the powerful combination of Xamarin and Google Glass :)

[1] http://songz.quora.com/How-to-run-Android-Apps-on-Google-Glass
[2] https://developers.google.com/glass/design/index

miércoles, 4 de diciembre de 2013

Distributed load testing: Introduction (1/5)

One of the typical tasks required in all the projects when building server side components is testing and specifically load&performance testing.

The first recommendation is the usage of tools or libraries as much as possible.   Please, don't try to reinvent the wheel, there are plenty of libraries and tools for testing for every possible language and type of service.  If your project is simple enough you can probably make use of simple command line tools like apache ab and if it gets more complex there are some tools like jmeter or soapui or frameworks for testing that should fit your needs.  I have to admit my preference is not to use UI tools for testing and in general prefer simple scripts easy to hack, run and maintain.  One thing to remember is that most of those tools are specially suited for HTTP services and testing is usually more complicate for other types of connection oriented protocols.

The second recommendation is to use a solution supporting distributed execution of tests.    That will ensure that your are able to put as much load as needed in the servers under test.   Typically most of the solutions are based on a master node controlling slaves nodes where the master node schedule and submit jobs to the slaves and collect and present the results and stats received from them.

In this series of posts I will explain my approach for load testing of custom non-HTTP services using  python scripts and virtual machines.

domingo, 10 de noviembre de 2013

What is AOP (Aspect Oriented Programming)?

For me AOP is a all about avoiding repetitive code to support common functionally by replacing that functionality with simple declarations associated to a method, class or module.

Think about it for a moment, I'm sure there are a lot of common tasks that you have to repeat in your projects: logging, authentication, caching, transactions, locking...     Those are commonly called cross-cutting concerns. In the worse case you will have lot of lines of code duplicated in all your methods for that functionality,  in the best case you will have that code in a library and you will have only one 1 line of code in all your methods.    But 1 line of code is still infinitely more than 0 lines of code!!!

If we were able to define those functions in a declarative way it would be great.   We need a way to tell the compiler "Add logging to this method", "All the responses in the methods of this class can be cached", "Make sure this method is executed in a transaction"... but hopefully without having to put that code in the middle of the real code of our application.  Business logic of our service should be easy to read and maintain and not obscured with tons of lines implementing plumbing functionality.

Most of the modern languages have a way to add some information attached to classes and methods.   For example we have Annotations in Java, Attributes in C# or Decorators in Python.

It is very easy to define in Java an annotation saying @Logging that can be attached to any method or class, the problem is how to associate some behavior to those annotations.    This is completely language/framework dependent but taking Java as an example, we have different options:
* Code modifications: A pre/post compiler task will modify the source code or byte code to introduce the code associated with each annotation.
* Dynamic proxies: When using IoC the container can instantiate a proxy instead of the real object and that proxy will execute the code associated with the annotations.
* Middlewares/Filters: In some frameworks (like jersey) you have the concept of filters that are executed for each request and you can add specific filters that can check the annotations in the class serving the request.

// Pending (I'm lazy) adding an example

I have been using AOP for years without any idea of this terminology, but just for completeness.... When we talk about AOP we usually mention Joint points and Advices.  Joint points are the points where the code will be added (for example before the method or after the method) and Advices the actual code that will be added.   An aspect is the combination of Joint points and Advice.