Feed on
Posts
Comments

I’m been following Scala language since a while and I’ve to admit that the first curiosity is becoming more and more a real enthusiasm. As technical responsible for my company I’ve also tried in the past to move major projects to Scala at beginning with no much success and recalling the experience I came up with some considerations that maybe can be useful to support the progress of migration to Scala of a J2EE based organisation like mine.

Errors to avoid

  • Don’t push too much: innovation is a iterative and shared process so has to be metabolised and embraced by your team.
  • Avoid web projects at the beginning: you cannot pretend to move an organisation with a complete stack of working JEE technologies to Scala in one day: that would be even intimidating for the developers since could even represent a lack of consideration of their skills and work
  • Don’t use PlayFramework! Play it’s an excellent framework for web application but It’s not a good start to Scala in my way: it use extensively the most advanced Scala features and it’t too much distant a traditional web project based on Spring MVN for example, so it represents a non trivial barrier t for a starter

And here’s a very short recipe:
The “greedy way”

  • 1. Start from small project
    Detach a small project from a J2EE context and dedicate it to Scala. I consider that log analysis, reporting, command line tool works very well as beginning dive into Scala world, not a web application: it has too many layers (persistence, MVC, log, cache, etc) and it’s too business sensitive!
  • 2. Adopt functional aspects with measure
    SCALA is a functional language and have a lot of functional aspects which comes to an experienced Java developer as big Leap at the beginning, therefore use it gradually. You don’t have to use extensively
    “partially applied function, currying, implicit objects” since your first line: first move the OO java to Scala and then add the new features to show as useful they can be.
  • 3. Involve Opinion Leaders
    As any other innovations, software innovation comes from people, so you need to catch the attention and enthusiasm of your opinion leaders: promote adoption of Scala among the most experienced developers (gradually) and promote knowledge sharing between the team.
  • 4. Be ambitious:
    Raise the bar just after your first project, having in mind that a rollback to J2EE would be an epic failure in this context.
    Illustrate the ultimate goal: (functional) Reactive Programming.
    This is the crucial point why you should be thinking of adopting Scala, as reactive programming has in Scala a natural declination language.

When you’ll have completed this steps you might realise that the “cultural” migration to Scala has gone too far to move back, and so you can move on.
Last: Iterate over point 4 :)

I’ve been interested in Big Data since a while. This post is the result of a work for University on combining Hadoop and Lucene, and in general could be considered a contribute to an architectural exploration of a Map and Reduce implementation

To download the complete paper, click on
Hadoop-BigData-Search.pdf

I have to admin that I’m not at expert in Python. After years of developing in Java and Php, I’ve looked at this option just for personal projects or technology discovery. In the last months we’re considering to swicth some application to Python in order to speed up in particular the front end development and I’m studying it more deeply.
The more I get into it the more I’m really amazed by the semplicity and beauty of it’s philosophy.
Just an example: to order a list using quicksort algorithml in python you just need these few lines:

def quickSort(list):
 
    if list == []: 
        return []
    else:
        pivot = list[0]
        lesser = quickSort([x for x in list[1:] if x < pivot])
        greater = quickSort([x for x in list[1:] if x >= pivot])
        return lesser + [pivot] + greater
 
 
 
print (quickSort([1,5,6,32,2,15,221,3321,4]));

In C the implementation would be:

 
/**
 
Quick sort array
**/
void q_sort(int numbers[], int left, int right)
{
  int pivot, l_hold, r_hold;
 
  l_hold = left;
  r_hold = right;
  pivot = numbers[left];
  while (left < right)
  {
    while ((numbers[right] >= pivot) && (left < right))
      right--;
    if (left != right)
    {
      numbers[left] = numbers[right];
      left++;
    }
    while ((numbers[left] <= pivot) && (left < right))
      left++;
    if (left != right)
    {
      numbers[right] = numbers[left];
      right--;
    }
  }
  numbers[left] = pivot;
  pivot = left;
  left = l_hold;
  right = r_hold;
  if (left < pivot)
    q_sort(numbers, left, pivot-1);
  if (right > pivot)
    q_sort(numbers, pivot+1, right);
}
 
 
void quickSort(int numbers[], int array_size)
{
  q_sort(numbers, 0, array_size - 1);
}

While in our beloved Java:

	public static int partitionDet(Comparable A[], int left, int right){
		int inf = left, sup=right+1;
		int perno = left;//il perno Ë in posizione arbitraria, diciamo in prima posizione
		if(stampa) System.out.println("A[perno]="+A[perno]);
		Comparable app;
		while(true){
			do{//cerca il primo elemento da sinistra > del perno. Nota il ciclo do-while
				inf++;
			}while(inf<=right && A[inf].compareTo(A[left]) <= 0);//il primo test serve perchÈ potrebbero non esserci elementi > del perno
			do{//cerca il primo elemento da destra <= del perno.
				sup--;
			}while(A[sup].compareTo(A[left]) > 0);
			if(inf<sup){//effettua uno scambio
				app = A[inf];
				A[inf]=A[sup];
				A[sup] = app;
			}
			else break;
 
		}
		//infine scambia il perno (in prima posizione) con l'ultimo degli elementi <= del perno
		app = A[left];
		A[left] = A[sup];
		A[sup] = app;
		if(stampa){
			for(int i=0; i<left; i++) System.out.print("- ");
			for(int i=left; i<=right; i++) System.out.print(A[i]+" ");
			for(int i=right+1; i<A.length; i++) System.out.print("- ");
			System.out.println();
		}
		return sup;//restituisce la posizione del perno
	}
 
	//ci serve public per quickSortDet
	public static void quickSortDetRicorsivo(Comparable A[], int left, int right){
		if(stampa) System.out.println("quickSortDetRicorsivo("+left+","+right+")");
		if(left >= right) return;
		if(stampa){
			for(int i=0; i<left; i++) System.out.print("- ");
			for(int i=left; i<=right; i++) System.out.print(A[i]+" ");
			for(int i=right+1; i<A.length; i++) System.out.print("- ");
			System.out.println();
		}
		int perno = partitionDet(A,left,right);
		quickSortDetRicorsivo(A,left,perno-1);
		quickSortDetRicorsivo(A,perno+1,right);
		if(stampa){
			for(int i=0; i<left; i++) System.out.print("- ");
			for(int i=left; i<=right; i++) System.out.print(A[i]+" ");
			for(int i=right+1; i<A.length; i++) System.out.print("- ");
			System.out.println();
		}
	}
 
 
	public static void quickSortDet(Comparable A[]){
		quickSortDetRicorsivo(A,0,A.length-1);
	}

More compact In Scala:

def qsort[T <% Ordered[T]](list:List[T]):List[T] = {
  list match {
  case Nil => Nil     
  case x::xs =>        
    val (before,after) = xs partition (_ < x)
    qsort(before) ++ (x :: qsort(after))
  }
}

But in this case (and this in my opinion is a general problem with Scala), the syntax is too compact and not easy to read at all.
In the end, Python really improves simplicity but also consistency into the code with a real coherent philosophy from low to high level. Really good stuff for a programming language invented to by occupied in the Christmas week around 1989 :)

Yesterday looking after old file I’ve found some old flash games I did from 2001 to 2003 when flash version was just 5 and math functions were… let’s say poor.
Still you can get some fun playing it. Hope one of this night to find the time to port just one of this in HTML5.
Pinball

  • A pinball made for a french portal (i guess)
  • Cartoon Network games

  • Wrestling with Johnny Bravo
  • Milan Soccer Champ
  • Horse race (Mandragame)
  • Photo stech
  • Thanks John

    Today I’m very sorry at the news of the death of John McCarthy, definitively one of the most fascinating person in Computer Science, according to my poor opinion.
    Yes, I’m not using LISP in my day work, but still I considered one of the best programming language you can learn from any perspective.
    A good and funnny guide is definitively this one http://lisperati.com/

    This reminds me also that’s time to read something more about AI :)

    I strongly believe that the real challenge in the SW development as nothing to deal with the engineering process, but much more on the team management and human resources.
    I came across this article about Steve Jobs and it’s extremely clear which was the “difference”
    http://www.thedailybeast.com/newsweek/2011/08/28/steve-jobs-his-10-commandments.html?fb_ref=interactive&fb_source=home_oneline

    • Go for perfect
    • Tap the experts
    • Be ruthless
    • Shun focus groups
    • Never stop studying
    • Simplify
    • Keep you secrets
    • Keep teams small
    • Use more carrot than sticks
    • Prototype to the extreme
    • My favourite? Of course the last one!

    Apache CXF

    For a large project I’m currently involved we were discussing a good technology to use in combination with Spring 3.0 to create a light SOA infrastructure based on a few Web Service and several restful services.

    The solution came with Apache Cxf a very easy to adapt technology in combination with Spring and extremely fast to develop.

    2 Minutes Guide
    Basically to declare a Restful service, you need just to annotate a normal Business Logic class:

    1
    2
    3
    4
    5
    6
    7
    
    	@Override
    	@Transactional
    	@GET
    	@Path("get/{grantId}/")
    	public Grant get(@PathParam("grantId") Integer </code>id) {
    		return grantService.getGrant(id);
    	}

    Not very different if you want a Soap Service

    1
    2
    3
    4
    5
    6
    
    @WebService(endpointInterface = "eu.innovationengineering.matchpoint.service.soap.GrantSearch")
    @Component("grantSearch")
    public class DefaultGrantSearch implements GrantSearch {
     
    	@Autowired
    	private GrantService grantService;

    Also the combination with Spring it’s fairly simple. After you define the path of your Apache Cxf servlet in the web.xml

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    
    <!-- APACHE CXF WEB SERVICE -->
    	<servlet>
    		<servlet-name>CXFServlet</servlet-name>
    		<servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>
    		<load-on-startup>1</load-on-startup>
    	</servlet>
     
    	<servlet-mapping>
    		<servlet-name>CXFServlet</servlet-name>
    		<url-pattern>/service/*</url-pattern>
    	</servlet-mapping>

    to avoid overlapping with spring MVC servlet for example, you can plug in apache cxf into the normal spring beans injections using the support for namespace.

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    
    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
    	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
    	xmlns:jaxrs="http://cxf.apache.org/jaxrs" xmlns:jaxws="http://cxf.apache.org/jaxws"
    	xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
     
          http://www.springframework.org/schema/context 
          http://www.springframework.org/schema/context/spring-context-3.0.xsd
         http://cxf.apache.org/jaxrs http://cxf.apache.org/schemas/jaxrs.xsd
         http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd
            ">
     
     
    	<import resource="classpath:META-INF/cxf/cxf.xml" />
    	<import resource="classpath:META-INF/cxf/cxf-extension-soap.xml" />
    	<import resource="classpath:META-INF/cxf/cxf-extension-jaxrs-binding.xml" />
    	<import resource="classpath:META-INF/cxf/cxf-servlet.xml" />
     
    	<import resource="classpath:matchpoint-serviceContext.xml" />
     
    	<jaxrs:server id="restServices" address="/rest">
    		<jaxrs:serviceBeans>
    			<bean
    				class="eu.innovationengineering.matchpoint.service.restful.impl.DefaultGrantRestService" />
     
    				<bean
    				class="eu.innovationengineering.matchpoint.service.restful.impl.DefaultContactsService" />
     
    					<bean
    				class="eu.innovationengineering.matchpoint.service.restful.impl.DefaultProjectRestService" />
     
     
    		</jaxrs:serviceBeans>
    		<jaxrs:extensionMappings>
    			<entry key="json" value="application/json" />
    			<entry key="xml" value="application/xml" />
    		</jaxrs:extensionMappings>
    		<jaxrs:languageMappings />
    	</jaxrs:server>
     
     
    	<jaxws:server id="searchGrant"
    		serviceClass="eu.innovationengineering.matchpoint.service.soap.impl.DefaultGrantSearch"
    		serviceBean="#grantSearch" address="/SearchGrant" />
    	<!-- <jaxws:endpoint id="searchGrant" implementor="grantWebService" implementorClass="eu.innovationengineering.matchpoint.service.soap.impl.DefaultGrantWebService" 
    		address="/SearchGrant" /> -->
    	<!-- <jaxws:client id="searchGrantClient" serviceClass="eu.innovationengineering.matchpoint.service.soap.GrantWebService" 
    		address="http://localhost:8080/matchpoint/service/SearchGrant" /> Connect 
    		a client use as a normal Spring Bean -->
     
    </beans>

    As you can see, support for XML/JSON in restful is automatically provided by the framework but in order to use not primitive objects in your response you need to annotate your domain object class with the following Jaxb annotation

    1
    2
    3
    
    @XmlRootElement
    @XmlAccessorType(XmlAccessType.FIELD) 
    public class Grant implements Cloneable, Serializable{

    Basically that’s it, and in my case it solved a lot of problems :)

    Ops, if you use maven just add this to your pom

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    
    <!-- APACHE CXF -->
    		<dependency>
    			<groupId>org.apache.cxf</groupId>
    			<artifactId>cxf-rt-frontend-jaxws</artifactId>
    			<version>${cxf.version}</version>
    		</dependency>
    		<dependency>
    			<groupId>org.apache.cxf</groupId>
    			<artifactId>cxf-rt-transports-http</artifactId>
    			<version>${cxf.version}</version>
    		</dependency>
     
    		<dependency>
    			<groupId>org.apache.cxf</groupId>
    			<artifactId>cxf-rt-frontend-jaxrs</artifactId>
    			<version>${cxf.version}</version>
    		</dependency>
    		<dependency>
    			<groupId>org.apache.cxf</groupId>
    			<artifactId>cxf-rt-core</artifactId>
    			<version>${cxf.version}</version>
    		</dependency>

    Android design tips

    I’ve recently find this slides, which is partially useful to design and Android application. It’s very basic, but enough clear…

    Wimove (Turismo Roma)

    I’ve recently published a new application on the Android Market. It is the project Wimove, an official guide to Rome.
    The platform contains more than 10000 items, from events to museum, and it’s fully geolocated.

    If you pass by Rome, this is something that can help you discover the city!

    The idea that new code is better than old is patently absurd. Old code has been used. It has been tested. Lots of bugs have been found, and they’ve been fixed. There’s nothing wrong with it. It doesn’t acquire bugs just by sitting around on your hard drive. Au contraire, baby! Is software supposed to be like an old Dodge Dart, that rusts just sitting in the garage? Is software like a teddy bear that’s kind of gross if it’s not made out of all new material?
    http://www.joelonsoftware.com/articles/fog0000000069.html
    Lesson to learn: It’s worth to spend time to read and understand code!!

    Older Posts »