Thursday, December 20, 2012

Spanish Budget Deficit. What if ...?

EDIT: I've done again the calculations and are more unbelievable even. I won't update this post but IMO it is quite reasonable to hit the target.

From time I tend to write about the Spanish budget deficit.

Almost nobody expects that Spain will meet its commitment around budget deficit for 2012.

Well. I want to say, that, regarding central government, I do think they are going to hit the target. There are others components of the budget deficit (regional and local government, and social security agency). And I don't know how do they go. But the target for the central government is 38bn euros, and the data for the twelve month period ending in November is 44bn, down from 76bn in July.

Limitations of the chart (not quite proficient using Google Docs). No legend. Green line is target, red is cash flow data and blue accounting data. Bear in mind that the y-axis does not start in zero, and x-axis show days but should be monthly data.

Anyway, I find it pretty impressive. I've seen it since August and still can't believe it.


Monday, December 17, 2012

The most popular video in Spain this Christmas

Below you can see the ad that in my opinion will end up being be the most popular video in Spain this Christmas

It depicts Fofito (a clown very well known in Spain) with other well known comedians, actors and even journalists, sending parcels to "important people": from Angela Merkel and IMF to Moody's and Standard&Poor's. In those parcels, Fofito sends, bundled with "cold meat" (that's what makes the company that prepared the ad), some sort of Curriculum Vitae of Spain, telling those "important organizations", why Spain should be respected.

The ad is quite moving, because it mixes Spanish popular culture, jokes (i.e. considering Felix Baumgartner as Spaniard) with drama (i.e. elder people are paying the bills for their unemployed children and grandchildren).

Even the background melody is "Suspiros de España", which could be translated like something like "Sighs of Spain". Spain suffers. Spain sighs.

I find it very interesting from a pure "getting to know what think many people in Spain", however.

Many people in Spain do not understand the root of their problems. In fact, for many people in Spain, their problems are motivated by those "sort of villains": Angela Merkel, IMF, rating agencies and "markets". Nobody has explained them neither the root of their problems, nor the path to get out of them. When I was coming to London (to work for one of those villains), some people looked at me as if I was a traitor.

And for many people, speaking 6/7 different official languages (none of them English) in a 45 million people country is something to be proud of (despite the money wasted in making those languages official). Or having some 50 airports most of them have a couple of flights a day. Or being the country with the biggest high speed railway network in Europe. Or having the highest percentage of people with university studies ("la generación más preparada de la historia")

And many people do not connect the dots. They don't understand that their problems have many roots, but some of them are exactly those things they feel proud of. That every local authority in Spain wanted to have their airport, high speed railway, and university. Because those things were an easy sell to their voters, and because those things left money in many pockets (corruption).

And they blame the people could help.

Yes. In my opinion there are things happening in Spain to be proud of. Some of them appear in the video but from a wrong perspective.

But this post is long enough already.

Saturday, December 15, 2012

Driving in the UK


Today I rented a car for a few hours. I used to drive in Spain, but I hadn't driven since I came to London. I wanted to practice in not too stressful conditions before my family comes to visit me. Also I needed to buy some furniture.

There are two problems for a Spanish driver in the UK (actually for most drivers from outside of the UK). 

First. Cars have the steering wheel on the right hand side of the car, while outside the UK(overseas as they say) the steering wheel is on the left. 

Second, people drive on the left of the road while in many other countries is on the right.

You probably knew that.

Now, my experience.

On one hand, things a knew I had to pay attention, and have not been too problematic: Remember to go clockwise when you enter a roundabout. Remember to go to the left hand side when you turn to and enter in a new street.

On the other, things that I knew, but that have been more difficult to manage. I know the gear stick is on the left, but my 20 years of manual car driving experience kept telling me the stick is on the right. No, no, no. On the right is only the door. No tips on that, but I guess it is a matter of practice. Another thing quite difficult is to not be too close to the left side of the road. My tip is to be aware of this problem and force oneself to be close to the right side of your path.

Anyway, no big issues (and the ones were more because of driving a diesel car). Safe at home at 2pm. Siesta (one day I'll write about it), and evening assembling a new table and chair.


Thursday, December 13, 2012

The future of this blog

When I started this blog, I had a goal. I needed to practice my English, because I wanted to go abroad. Months (or even years) later, more reasons appeared. First, I discovered that writing about solutions to job related problems could give people a way to solve their own problems more easily. Later on, I realized it could also be a way to show that I wasn't a newcomer while looking for a position abroad. But practicing my English kept being the main reason.

On 1st November I came to live to United Kingdom. I got a position for a company in London. I know people in that company read this, and I don't want to look too "creep", but the company is not stressful, and people are quite nice and are really trying to make me feel fully integrated. I'm not at all there, but once I get over the communication barrier, I feel I will be really part of it.

So I'm living abroad and I don't expect to be looking for a different job in the near/medium term. I should say that some of the original goals are completed.

However, I do need to keep improving my English. Probably more talking than writing or listening. But also writing and listening. And, because of that, this blog still could have a mission. But I don't know what to write about.

The most obvious topics could be about my life here in London. Unfortunately, I have started a blog in Spanish to keep my family on the loop.

Also I fear sometimes I could offend people with my comments.

A short example. People here tend to ask me about my opinion of London. I used to not answer ("I've only been here a few weeks dadada"). On Monday, a colleague (who wasn't born in the UK, but have been here for long time) asked me the same question, and this time I answered quite honestly. I think is a city focused on living and not in tourism. I mean, I know it has vibrant cultural life, and obviously it has many places to visit. But it is not a "charming" tourist based city. From his feedback (I'm not at all good at receiving non obvious tips in English) I got the impression I don't have a clue, so I played down.

Apparently my impression is not so strange, although it probably shouldn't be carved on stone. But you get the idea.


Monday, October 22, 2012

Relocating to London

In two weeks I will be working in London. I know I was expecting to continue my last post about Spring persistence. I have lots of things to write about the incredible experience of finding a job abroad and relocating.

But as you'll imagine, I'm quite busy. I'll try to post before starting in my new job, but I don't promise anything. Thank you. Each and every one of you.

Monday, October 1, 2012

Crash course on Spring MVC, transactions and persistence (I)

A couple of weeks ago I was asked to do an assignment for a selection process. The task was trivial for expected 2-3 hours, and mentioned that the final project would end as a Web Application based on Spring and Hibernate. So I decided to do it as a full application. I didn't want to copy code from work as a template, but I wanted to do it as a fresh project.

If you are busy, go for the code here. But for those moving from JEE to Spring and wanting a more in-depth explanation, here comes the long (as in two LOOOOOOOOONG posts) detail.

One of the main difficulties was managing the transactions. In particular I had lots of problems with transactions not being persisted, errors like "No Hibernate Session bound to thread, and configuration does not allow creation of non-transactional one here", and NonUniqueObjectException. I wanted to develop with @Transactional. Despite reading the documentation and lots of posts out there, I wasn't able to find explicit end to end functional code that helped me solve my own problems.

Finally I managed to understand what was going on. And I've decided to write my personal crash course on Spring MVC, transactions and persistence. If you arrived here out of the blue, comments are very much appreciated.


Project creation

OK. So you want a Spring Web application. Then first thing you should do is create a new web project. There are several alternatives for doing this. In Eclipse the two more obvious are 1.-you can create a Dynamic Web Project, or 2.-create a Maven Project. If you choose the former, you'll have to download and add lots of libraries to the Java Build Path, but you'll have a better understanding about the code. I started from a Maven Web Project. I think I chose a Maven Archetype from codehaus for spring and jboss but I don't really remember because later I tuned it.
Anyway here comes a list of dependencies I have in my project. Some of them come from the maven archetype I chose, so maybe not all are needed:
  • org.springframework.spring-asm
  • org.springframework.spring-aop
  • org.springframework.spring-expression
  • org.springframework.spring-beans
  • org.springframework.spring-context
  • org.springframework.spring-context-support
  • org.springframework.spring-tx
  • org.springframework.spring-core
  • org.springframework.spring-jdbc
  • org.springframework.spring-web
  • org.springframework.spring-orm
  • org.springframework.spring-webmvc
  • aopalliance.aopalliance
  • taglibs.standard
  • commons-logging.commons-logging
  • log4j.log4j
  • org.springframework.spring-asm
  • org.springframework.spring-aop
  • org.springframework.spring-expression
  • org.springframework.spring-beans
  • org.springframework.spring-context
  • org.springframework.spring-context-support
  • org.springframework.spring-tx
  • org.springframework.spring-core
  • org.springframework.spring-jdbc
  • org.springframework.spring-web
  • org.springframework.spring-orm
  • org.springframework.spring-webmvc
  • aopalliance.aopalliance
  • taglibs.standard
  • commons-logging.commons-logging
  • com.h2database.h2
  • junit.junit
  • org.springframework.spring-hibernate3
  • org.hibernate.javax.persistence.hibernate-jpa-2.0-api
  • commons-dbcp.commons-dbcp
  • commons-pool.commons-pool
  • org.hibernate.hibernate-annotations
  • jstl.jstl
  • org.springframework.spring-test
  • javax.transaction.jta


The web.xml

As you well know, the file web.xml is essential for every web application as it maps URL patterns to Servlets, among many other things. This is my web.xml file


Things to note. Starting at the end of the file I declare a mapping between one servlet called "Spring MVC Servlet". The servlet, defined in lines 11-17, is of type org.springframework.web.servlet.DispatcherServlet and it takes one parameter named contextConfigLocation. That parameter points to a spring context file named spring-mvc-context.xml (we'll talk about it later).
One point interesting to note is that Spring Web application tend to have two spring-context file. One context-file is related to web (e.g. controllers) and is loaded from the servlet. This is spring-mvc-context.xml.
The other is loaded from a listener. A (servlet) listener acts on container events. In this case we load a  listener called ContextLoaderListener (line 9). This listener is in charge of loading the other Spring context. It takes it route from a parameter called contextConfigLocation (lines 5-6).
Warning. You have two context-files BUT ONLY ONE CONTEXT. The so called "web context" and "root context" are both part of the same context. You define servlet related things in the "web context" and the rest in the "root context". The web (servlet) context inherits form the "root" context.
So two contextConfigLocation. One for the listener, points in this case to spring-business-context.xml. The other for the servlet, points in this case to spring-mvc-context.xml.
What else? From lines 19-30 we load a filter. A filter, as you well know, is an artifact that sits in between the web and servlet and does something. In this case it is going to do something about transactions, but we'll talk about it later.


The web-scoped context: spring-mvc-context.xml

My web context in this case is quite short:

As you can see there are 3 main groups:

  1. context:component-scan looks at the specified package for annotations to fill.
  2. mvc:annotation-driven fills some magic relating validation, json and so on.
  3. InternalResourceViewResolver is a pretty standard way to point to where the JSP reside and the way they are named.
Nothing very fancy, you see.


The root context: spring-business-context.xml, part I

Ahh. This is quite longer than the web context. Let's see.

Here you are. In this post the easy part. Next post database, transactions and so on.

First, again, (line 13) a component-scan for annotations in business objects. Beware. If you scan the same package/class in the root context and in the web context, you are screwed and will get some nasty errors.

Second. Line 15. We are going to look for a file called spring.properties (anywhere in the classpath) and we are going to load it. It will help us to separate specific properties from the configuration.

Third. Two bean definitions. Lines 51-56 for one bean, and lines 66-67 for other. The first one needs some properties we just loaded on line 15. The second bean I'm not absolutely sure I need. I think it needs to be here because I have two different beans that could match (one in src and one in test), and here I wanted to load one of them.

That's it. The rest is persistence and transaction related. We'll leave it to the following post.



Monday, September 24, 2012

OptionalDataException while reading JMS message

We've been dealing with another bug in JMS code. The symptom was blocked queues and the following exception:

javax.jms.JMSException: getObject
          [...] 
Caused by: java.io.OptionalDataException
      at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1325)
      at java.io.ObjectInputStream.readObject(ObjectInputStream.java:348)
      at java.util.HashMap.readObject(HashMap.java:1066)

In trying to reproduce people in the team introduced a non-serializable object, but he got an exception at sending the message (Caused by: javax.jms.JMSException: setObject [...] java.io.NotSerializableException). In a similar way, trying to send an int, he got a NotSerializableException. And trying to send some class and then changing the serialVersionUID, he got an error at receiving, but a different error (java.io.InvalidClassException).

Everything in Internet pointed to a thread-unsafe error, so we looked at the code and found this


        mensaje = receptorMensaje.receive(timeOut*1000);
        [...]
        mensaje.acknowledge();


with several lines of code between the receive and the acknowledge, and without synchronization

Under very heavy load, it was easy to have a thread execute the receive, a different thread execute the receive and then the first thread acknowledge. But by then both threads have the same object and if the first thread changed its copy, the Exception would be triggered.

We extract a method this code and synchronized.

Sunday, September 23, 2012

June deficit was 8.54%

From time to time I write about politics in Spain in general and in particular Spanish deficit. Sometimes I try to do some simple estimations and comments.
More recently there has been some comments in Spain regarding the publication of regions' budget deficit up to second quarter. But I don't really understand why people insist to pay attention to quarterly data without reference to a twelve month period. Let's do the math.

First deficit: It seems that, if we leave out the help to the financial institutions, deficit in 1Q2012 and 2Q12 has been 39815 million euro. Deficit in 3Q2011 and 4Q2011 was:-16.616-34.054 = 50670 million euro. So, twelve month period ending on June 30th: 90485 million euro.
Then GDP: Acording to INE, GDP for 3Q2011,4Q2011,1Q2012,2Q2012: 255367 + 275032 + 259198 + 269739: Total: 1059336 million euro.
Now let's divide both. 90485/1059336.

Deficit in terms of GDP at June 30th using public data: 8,54%

Daniel Lacalle says it's 8,56%. Surely I missed something. But not too much.



Saturday, September 22, 2012

Weird IE9 bug

This last two weeks I have dealt with a weird bug in IE9.

  • The problem appeared in a legacy web application. 
  • The issue reported by the user was a combo that didn't drop down. 
  • The problem appeared in different pages, but only for some combination of values.
  • The issue appeared after installing IE9 from IE7 in a Windows Vista. 
  • The user could reproduce the issue (for a certain combination of values).
  • We (both devs and ops) couldn't reproduce in a standard machine even tough at work final users deal with a very standard machine (machine setups are pretty standarized at work). 
  • When we finally were able to reproduce in a standard machine, it only failed the first time a user logged in (second time, or even IE close rendered the bug irreproducible).
  • We finally were able to pinpoint the problem to a very large option (as in 400 characters).
  • And now I've been able to reproduce it with a reduced version of the page even in my setup (Vista64+IE9). See the gist. Save to a file, launch it with IE9 and try to change the option.

We trimmed down to 200 chars (I guess even 150 chars wouldn't be viewable).

UPDATE (2012-09-30): Tested on IE10 in Windows8 and seems to work fine.

Thursday, September 20, 2012

Techzing wives

I tend to listen Techzing podcast. It's a podcast about very different topics, recorded by two geeks, (or developers, and entrepeneurs). I don't remember when I started listening them. I do remember I started because I wanted to practice English and it was great (Justin is an Englishman and Jason is American). Soon I forgot why: they were great by themselves. The topics are very diverse from Technology, Entrepenurship, Politics (Loom and Gloom Report), Education, Genetics...

I listen them while commuting, and I was a couple of months behind. However, I just listened episode 200: techzing wives.

And it's simply the best. I couldn't help but laugh in many different parts of the episode.

I guess that episode is not very interesting for a newcomer. But I'm sure that for most of their regular listeners it has been a great experience to listen to our own wives in the voices of three complete estrangers.

Friday, September 14, 2012

My first Chrome extension(II)

In last post I wrote why. In this post I want to explain how I wrote my first chrome extension.

First. The Chrome Extensions developer's documentation is quite good.

Second. A chrome extension is a zip of a folder with an crx extension instead. The folder has to have a particular file called manifest.json. It tells the extension name and the permissions asked. It also points to the main file. Pretty standard in my case.

The main file, in my case was called background.js. You should read the documentation to know more about background pages and so on.

In my case, I attach an event listener to the click of the extension button (browserAction.onclick). The listener gets the url of the current tab, process that url, encode it, get a Google url redirection from it, and ask for it.

chrome.browserAction.onClicked.addListener(function(tab) {
  var currentTab=tab.url;
  var processedURL=processURL(currentTab);
  var encodedURL=encodeURIComponent(processedURL);
  var newUrl="http://www.google.es/url?sa=t&rct=j&q=&esrc=s&source=web&cd=1&cad=rja&sqi=2&url="+encodedURL;
  chrome.tabs.update(tab.id, {url:newUrl});

});


The processing of the URL do a bit of tweaking for some specific servers. Pretty uninteresting.

My first Chrome extension(I)

This afternoon I was preparing an interview I expect to have next week, and came to an interesting page with information about job selection process and companies inside information. However, after surfing a bit, the inevitable, "become a registered member" started to bug me.

And I got tired.

And I remembered FT similar "become a registered" and WSJ "first-paragraph-only". Lots of sites show you the page when you come from Google, but ask you to register if you start to surf (or just come from a different page). Completely understandable, but not very pleasant.

So I asked myself if it would be too complicated to build an extension for Google Chrome, that when you are at a page and asks to register, you ask google to get redirected to that page. It seems it's not. I started poking at 19:00 (local development folder creation time was 19:07) and ended building it at 20:30 (icon included). It's pretty basic, but it makes a bit of tweaking with FT and WSJ URLs because just coming from Google was not enough. And now it works, with glassdoor, FT, and WSJ.

Great. I learnt and I have something interesting to show.

In the future.

Maybe showing I'm willing to "hack" a paywall is not something I should be publishing when interviewing for a financial information company. Or maybe yes. Anyway: this is me.

Next post. How I did it.

Monday, September 10, 2012

Tuesday, September 4, 2012

Calisthenics

I didn't know about object calisthenics. They are a set of rules to help develop better:

1. One level of indentation per method
2. Don’t use the ELSE keyword 
3. Wrap all primitives and Strings4. First class collections
5. One dot per line
6. Don’t abbreviate
7. Keep all entities small
8. No classes with more than two instance variables
9. No getters/setters/properties
Some of them are a must, with some others I have some doubts. But the point 2 is so intriguing I have to test it.

Sunday, September 2, 2012

No more applets

For more than three years I've been managing certificate-based digital signature applications.

 One of the main source of pain always was and is generating the signature on the user browser. As it needs access to the user's keystore, the browser alone didn't have access to it, and was needed some kind of component (either ActiveX, usually a Java applet). The deployment of the component and the debugging of different OS/browser/Java version configurations tends to be time consuming.

I even was trying to create my own version of component to help stop reinventing the wheel.

For all the time lost, the existence of a group in the W3C to incorporate crypto to the browser is GREAT NEWS.

Sunday, August 26, 2012

Little robot (IV): Ruby version

Besides the console faking and the dependency inversion issue, my code in Ruby was pretty rough. You can see here the version I sent.

One obvious problem is the use of string instead of symbols. It was a bad bad mistake. So big if I had been the person testing, I would have thought very bad of myself.

Anyway it was clear that Java version was considerably more verbose.

So one obvious improvement is using symbols instead of string. But during the interview, I asked what other improvements people have done on the assignment. One tip I received is the use of Array.rotate. I don't like that improvement, because it makes the code less understandable. But I didn't like the verbosity of the case, and I tested a different approach. This is the code I left in the end:

class Robot
  VALID_X = 0..4
  VALID_Y = 0..4
  VALID_F = [:NORTH,:SOUTH,:EAST,:WEST]
  TURN_RIGHT = {:SOUTH=>:WEST,:NORTH=>:EAST,:EAST=>:SOUTH,:WEST=>:NORTH}
  TURN_LEFT = {:SOUTH=>:EAST,:NORTH=>:WEST,:EAST=>:NORTH,:WEST=>:SOUTH}
  MOVE = {:SOUTH=>[0,-1],:NORTH=>[0,1],:EAST=>[1,0],:WEST=>[-1,0]}

  def initialize
    @accepting=false
  end

  def place(cols,rows,facing)
    x=cols.to_i
    y=rows.to_i
    f=facing.to_sym
    if is_valid?(x,y,f)
      @x=x
      @y=y
      @f=f
      @accepting=true
    end
  end

  def left
      return unless @accepting
      @f=TURN_LEFT[@f]
  end

  def right
      return unless @accepting
      @f=TURN_RIGHT[@f]
  end

  def move
      return unless @accepting
      delta=MOVE[@f]
      x = @x + delta[0]
      y = @y + delta[1]
      if is_valid?(x,y)
        @x=x
        @y=y
      end
  end

  def report
    return nil unless @accepting
    "#{@x.to_s},#{@y.to_s},#{@f}"
  end

protected
  def is_valid?(x,y,f=@f)
      VALID_X.include?(x) && VALID_Y.include?(y) && VALID_F.include?(f)
  end
end

Saturday, August 25, 2012

Little robot (III): Dependency inversion

As I wrote some posts ago, I received an assignment, and I decided to do both in Java and in Ruby. When doing in Ruby I wanted to make sure I was able to test the UI, and not only the engine. For doing that, I chose to fake the console interaction (both stdin and stdout). I didn't consider dependy inversion.

Sometimes a higher level class A has to invoke methods in a lower level class. Let's say this lower level class tends to be class B. Typical approach (non DI) is to make class A depend on class B. Dependency inversion is to make class B implement some contract associated with class A (the dependency is inverted).

I think I'm still in the process of converting from Java(where DI and interfaces is compulsory) to Ruby. With Ruby is much easier to fake classes B and don't even think about inversion while developing class A.  Maybe I should have done my class more testable. But I didn't realize it until in a different selection process I was asked when to use Dependency Inversion in Ruby.

Thursday, August 23, 2012

Rails in Ubuntu

I'm planning to make a newbie post about rvm, bundler and the rest. But just in case you're starting with ubuntu, here comes a piece of advice.

There is some controversy about editor to use for ruby. Some people prefer Vim+tmux, which seems the more standard. Other people prefer TextMate on MacOSX and Redcar on Ubuntu. I must say that I prefer vi to emacs, but for the time being I prefer Redcar to vim. In the future this may change, but not at the moment. Anyway, one of typical topics when migrating from Linux Mint is "how the h*ll do I anchor an application to the Unity bar?". Well, in the case of Redcar, here is the answer.

Side question: "Why the h*ll are you leaving Linux Mint?"

Anyway, back to more interesting topics. If you are a Rails developer, you should be using RVM. How do you use RVM in Ubuntu. Two tips:

First. Forget about apt-get install rvm, and if you are reading this too late, go here.
Second. If you are using gnome terminal, read this.


Monday, August 20, 2012

Faking the console in Ruby

A few days ago, I was preparing an assignment for a job process both in Java and in Ruby. While doing in Java, I decided to test the engine. But in Ruby I wanted to test the whole application, including the communication via standard input/output on the console.

And how do you mock standard input/output in Ruby?. Well. It turns out it is quite easy to do it with Rspec. But I wanted to do it without any additional requirement. How do you mock STDIN and STDOUT in plain Ruby.

It turns out it isn't difficult. Based on this gist, I prepared my own solution. First the input faker:
class InputFaker
  def feedStrings(strings)
    @strings = strings
  end
  def gets
    next_string = @strings.shift
    next_string #TODO: I guess next_string is superflous
  end
end
Second the output faker
class OutputFaker
  def initialize
    @result=[]
  end
  def write(str)
    @result << str.chomp
  end
  def clear
    @result=[]
  end
  def result
    @result.join
  end
end
Third, setup and teardown methods
  def setup
    $stdin = InputFaker.new
    $stdout = OutputFaker.new
    @robotUI=RobotUI.new unless @robotUI
  end
  def teardown
    $stdin = STDIN
    $stdout = STDOUT
  end
And fourth, the actual use (in this case a test)

  def actual_test(array_of_inputs,expected_output)
   $stdin.feedStrings(array_of_inputs)
    array_of_inputs.size.times{@robotUI.parse()}
    assert_equal(expected_output,$stdout.result)
  end

Sunday, August 19, 2012

Little robot (II): Java version

As I wrote in a previous post, I was asked to design a software managing a robot inside a board of 5x5 cells. The typical commands were

PLACE X,Y,F ->Places the robot in the x,y position facing F
MOVE ->Move the robot 1 cell in the facing direction
LEFT ->Changes the facing counter-clockwise
RIGHT ->Changes the facing clockwise
REPORT ->Shows the current position and facing

and the main requirement was that the robot didn't fall outside the board. The assignment allowed to read commands from the console (standard input/output) or from a file. You can read the assignment here, but that's not my code.

Initially I didn't want to focus on the input/output, so I decided to test only the engine. Without writing a line of functional code, I developed a JUnit test class just from translating the requirements into code. It wasn't pure TDD, because there weren't tests for individual methods. But it gave me the security net I needed to play a bit with the design.

It was obvious for me that the there was going to be a class between the user and the engine, mediating input and output. For me that class was the UI of the engine. I could think of a console UI, a file UI, or even a graphical UI. The implementation I decided was a console UI (read from standard input and standard output), but I decided not to make tests for that class. Probably I should have done the tests, and I don't love the code in the method parseLine().

Following that, I focused on the engine class. Should the engine class have everything in it? Should it manage variables independently? I did different implementations, refactoring the code, peaceful, knowing my tests were saving the bacon. In the end I decided to manage whole objects with the whole status (both position x,y and facing f). That way I was thread safe: either the new position is good, (and it becomes the current position), or bad (and I kept the previous). I played a lot with the names of these entities, not deciding between Status, and Position. I didn't love either of them, but chose Position. I also played a lot with the facing. Should I use constants in Position class, or an enum? I thought about creating a service implementing the commands, doing it in the Robot engine, in the position, or in the enum?

The bad thing about an assignment like this is that you have too many options. The code in Java wasn't perfect, but I guess it was good enough.


Friday, August 17, 2012

Little robot (I)

While applying to a position a few days ago, I received an assignment trying to test my coding style.

IMO, assignments are quite a good way to get a peek on the coding style of someone. They are easy programming tasks that show if somebody is able to code (it seems many of us can't), and what's his/her style.

Another similar tool would be online testing web applications such as codility. My opinion of codility is mixed. I think it's a good way to test, but some of the assignments are already on the Internet, and doing a bit of research you can find some of them. Besides, focusing on a fixed time frame (one hour), it's more prone to errors on the assignee.

Anyway, no method is perfect, and I've discovered the assignment I was given was already solved on the Internet. For the record, with due respect, I think googled solution is overkill. But you can see there the specific assignment.

When I received the test, first thing I thought was about the programming language. I was allowed to code in any language, but the position I had applied was Ruby based. I was more comfortable doing it in Java, but wanted to do it in Ruby. What if I wasn't able to do it right in Ruby? Better to do it right first, and then to try to show the point I am at in Ruby.

So I did it both in Java and in Ruby.




Wednesday, August 15, 2012

Savon.rb and sequences

As I wrote in my last post, I've recently learned it is important to be able to show what you've been doing. So I'm trying to increase the posts on a number of small problems I find in my daily job, and in my hobby projects. This one appeared in my daily job.

I was developing a small interface between two applications via a SOAP web service. Actually, we are using Redmine for development, and Remedy for the whole organization, and we didn't want to fill the information twice.

I was using Savon.rb for creating a client in Redmine that would invoke a SOAP web service in Remedy. The code was something like this:

          response=client.request "Resolver" do
            soap.header={:AuthenticationInfo=>{
                 :userName=>ws_user,
                 :password=>ws_pwd,
            }
            soap.body = {
                "Status"=>"Resolved",
                "Resolution"=> message ,
                "Status_Reason"=>"Client Action Required",
                "Incident_Number"=>code,
                "Status_Reason2"=>"Client Action Required",
                "AssigneeLoginID"=>user,
            }
          end


However, I was getting a SOAP error

ARERR [8962] Unexpected element encountered in the input XML document

The problem lies in Ruby hashes not preserving the order and Savon sending XML sequences in incorrect order. I just updated the call to something like this

          response=client.request "Resolver" do
            soap.header={:AuthenticationInfo=>{
                 :userName=>ws_user,
                 :password=>ws_pwd,
                 :order! => [:userName, :password]}             }
            soap.body = {
                "Status"=>"Resolved",
                "Resolution"=>message,
                "Status_Reason"=>"Client Action Required",
                "Incident_Number"=>code,
                "Status_Reason2"=>"Client Action Required",
                "AssigneeLoginID"=>user,
                :order! => ["Status", "Resolution", "Status_Reason","Incident_Number", "Status_Reason2", "AssigneeLoginID"]             }
          end


and it solved the issue. I expected Savon to take care of this, but anyway, I understand this is solved in Ruby 1.9x.

Tuesday, August 14, 2012

A great experience applying to a position (II)

In my previous post I explained a great experience applying for a position. In this post I wanted to share what lessons I've learnt from that experience.

  1. Selection: Be very selective about what you apply for. For me this means no recruiters, making a pre-research of the company, and reading carefully the description to get a sense of what the company is asking. It's pretty obvious, but essential for the following lesson.
  2. Visa: When applying for a foreign country, make some research about Visa requirements. For example, unless you are a guru, don't apply to an US listing. It's quite difficult to get an sponsorship for the US, but no so for Australia. Are you an European citizen? Doors open in Europe. And so on.
  3. Target: Carefully target the ad and the company with the cover letter. In my experience this is more important than the CV. CVs doesn't work. I'm in the process of completing a 35 pages CV (no kidding) and I can tell you it won't describe me. 
  4. Try to target the cover letter but be honest and open. There was a great post on 3degrees blog, unfortunately deleted. See this cache copy.
  5. Test, code, refactor: Yes, you know about TDD and BDD. In fact you are expected to send the tests along with the code. But at least in my previous assignments, I had tested, then coded, but I had forgot to refactor to get a nice design. And I had sent code not adequately designed. This time, I set a good set of tests, then hacked something quick, then refactored lots of times.
  6. Research: For the interview do a great research. Be prepared. Who would be your mates? Nasty comments about the company? Source code of the pages?. And if the interview seems in a loop, (not the case this time), be open but drive it to a point. 
  7. Build a presence online. Most asked request: show us your code. Yes, I have a github account (actually two). And I also have a blog (this one ;D) But at work I don't have the time to build the presence. And doing it at home is quite difficult. But it's essential
I think fifth and sixth really made a difference, but I'm really starting to learn how to apply to a position.And I'm trying to complete the seventh point. This blog posts are part of that effort.


Monday, August 13, 2012

A great experience applying to a position (I)

I wrote in my last post about lessons I've got from bad experiences looking for a job. In this post I'm going to tell you about a good experience I had last week, how much I learnt from it, and the lessons I got from it. Make no mistakes: I didn't get offered the position in the end.

For me, the outcome is not the most important thing in such a process, but the feeling you're not losing your time, and the lessons learned. In this post I'll try to point why I felt I wasn't losing my time, and in the following I'll post the lessons learned. Experiences

  1. The job listing was in a specialized place for software job listings, but the tone of the listing was not a yet-another-ad-looking-for-a-guru. I think there is some kind of kind of wrong game between companies and candidates. Companies asks for lots of things from candidates. From my recruiting experience (yes I've been on the other side too) candidates usually fall in three categories: candidates good at everything asked, candidates that consider themselves an expert in a topic for an article they read about the topic, and candidates that try to tell beforehand why they think they match the position. My impression is that the first group does not apply and companies tend to ask for an interview to people on the second group. However this company was asking for people "good enough". It was something like "hey, we are looking for good programmers. But mere mortals. If you can think you can match, please apply". They made a funny listing with what they were looking for, they got a lot of attention and they were proud of their listing, not giving a damn for the comments. Good for the listing.
  2. I applied a Wednesday, I had a first reply on Thursday, and we wrote each one back an forth (despite 8 hours and 17200 km of distance) several times until Friday. On Friday I got a basic assignment. I sent it back on Sunday, and on Monday morning (his Monday afternoon) he had revised the assignment and was planning an interview on Skype. We did the interview on Thursday, and on Friday we wrote me back telling me I wasn't going to be offered the job. Yes, 10 days total.
  3. Regarding the mails previous to the assignment, he made interesting questions. In retrospect, there were wonderful questions to know if somebody is what it seems, but from reading them at the beginning, they seemed pretty innocent. Good for the previous
  4. With respect the assignment, I did both in Java (for now I feel more comfortable), and in Ruby (the main language of the position). He evaluated both, and even if Ruby's one was not good (in retrospect I would say clearly wrong), he was interested in talking with me. Both he (CEO of the startup) and the developers' manager. So the assignment was part of the process, but not the whole process. I had told him I wasn't perfect rubyist, so he only wanted to know if I was a good developer (and it seemed my Java was good enough), and my level of Ruby.
  5. On the interview we were talking about lots of topics for an hour. Despite my sometimes rough spoken English, they were very patient, and they didn't seemed bored or in run to cut the interview. I had done a research of the company, but they point it and were grateful.
  6. And the following day I got an email telling me I was no longer in the process. I think this was the part less clear for me because the rejection seems to point to a "there were better candidates", but there were something in the tone (like a polite "contact us if your circumstances change")  that could point to "you seem good but you need to learn Ruby better". I know enough from girls rejections that "I like you as a friend" is not what it sounds but it is what everybody knows. :D 
Anyway, overall I got a really nice experience, I felt valued, and I learnt a lot. Lessons in the following post.

Sunday, August 12, 2012

Bad experiences

For some time I've been applying to different positions. I have two daughters and I want for them (and for me) to live in a different culture and language. After a few experiences, I'm tempted to say something about bad experiences:
  1. Forget about recruiters. They have different alignments than yours. In my experience (it could be biased), 90% of them are just form fillers. They ask you things (CV, tests, questions), in order to fill a form in a random web site. When they send you the position, look for the most weird sentence, and put it on Google. You'll probably get the company hit, because they don't bother to change it (sometimes I've been tempted to apply directly). Usually they don't know about the IT bussiness (I've been offered Javascript position because my CV had lots of Java in it). And for me, the more important problem with recruiters is that they won't ever (EVER), contact back for a position. They can ask again new things for a new position but they won't tell you anything about the previous one. So recruiters are a lot of effort but with very low response.
  2. Forget about public/international employment unless there is a competitive examination. Here my personal sample is smaller (just two cases). But from what I've heard, it's quite representative and unbiased. Usually behind a public offer there's some procedure forcing to publish a public profile to hire somebody already known. In my personal experience(an embassy on 2008 and an EU position in 2011) it was like this.
I'm still in contact with a recruiter because I have some type of personal commitment with him. But this is what I've learned and I share just in case it's useful. However, I have good experiences to tell you about. You'll have to wait next post for it.

Sunday, July 1, 2012

Xerces, Xalan and Saxon, more recipes

In a previous post I proposed some tips for trying to manage and control the hell of XML and XPATH parsers. However, as one reader pointed, those tips sometimes are not enough. What Simon explained may not seem obvious, but sadly for us (I came across a different problem with the same underlying cause), it is.

In my previous post I explained how to make Java choose a class for a parser. But, unfortunately that's not enough when different libraries provide that class. And that happens to be the case with some classes that are both in Xalan an Saxon (Simon's case) and some Xerces classes (both in server and WEB-INF/lib in my case). 

Simon needs Xalan classes for the general case, but he also needs Saxon for some specific (maybe XPATH2) parsing. He is able to set the parser for the general case, and initialize the specific parser for the XPATH 2 case. But having Saxon jar in the classpath makes the classloader load Saxon classes before  Xalan classes. 

What can we do in that case? It's not easy to answer, and sometimes there's not even an answer. Some tips:

  1. Play with the classpath general mechanism loading order. For example JRE/lib/ext are usually loaded before WEB-INF/lib, so maybe Xalan would be placed in JRE/lib/ext and Saxon in WEB-INF/lib. This tip could have it's drawbacks in the booting of the server and in other applications sharing the same JVM, because JRE/lib/ext gets precedence from server specific mechanisms. Besides, operations people gets very nervous about placing anything in the JRE/lib/ext (not without reason).
  2. Use some mechanism specific of the server. In my case (Oracle WebLogic Server), there were several
    1. Use $DOMAIN/lib folder instead of JRE/lib/ext (ops people get more comfortable, and it reduces the applications affected
    2. Classloader-structure in weblogic-applicaiton.xml.

  3. Play with classloaders. This page from OWLS is not very server specific and should give some hints.
  4. In the worst case, I guess one could try to use its one specific packaging.
Hope this helps. I solved my case but for the general case it will depend on what are we allowed to do.

Thursday, June 7, 2012

Why LinkedIn breach is so important?


It's widely spread that there has been a security breach in LinkedIn. At least there is a file with passwords in that social network. Even LinkedIn acknowledges it and suggests it will try to alert users whose passwords have been compromised.

We know that, and we know passwords were not in the clear (they were stored hashed), but they weren't quite protected (they weren't salted). My own password was on the file and had been "unhashed". No it was not "secret" or "alibaba". Mixed letters and numbers. You can check yours and is a relatively safe process. But even if your password was not in the leaked file, it doesn't mean your password is safe.

So we must assume our Linkedin password and user are compromised. We must assume that every other web we were using that same password in, has the same password compromised.

But we must also assume until proved otherwise that other LinkedIn data has been compromised. Billing address or credit card for premium users? I don't have any information, but from a security perspective (typical CERT practice), and until LinkedIn explains exactly what has happened, is enterely possible.

Somebody could say that credit card data will be hashed. Yep. If it's like passwords, hashed but nos salted. And so crackable.

"Houston we've got a problem".


Monday, May 14, 2012

Google, where are you going?

I've been Google fanboy for a long time. I remember the invitation for Gmail I received around mid-2004. Gmail was a revolution. From 50MB mail space at the time, they offered 1000MB (1GB). But the size wasn't the only thing revolutionary. A great UI interface, faster than anything seen before was shocking.

I remember Google video chat. Being able to talk from the mail. "No installations".

Even Google Wave was revolutionary although the launch was a big failure, and the project was more in Alpha than in Beta.

Android was great, and Chrome too. ChromeOS??. It's lame that the only precompiled images are through a (great) guy.

And then Google plus. I think they had to be social at any price, and they did. Good ideas but nothing revolutionary.

Lately, change in privacy terms, most of us do not read. It's sad,

And now, Google drive? 5 GB? Are you kidding me? Is this the competition to Dropbox? Even Microsoft has a better services. I use Box.net and I'm afraid I'm not going to change.

Maybe next hit from Google is a new Twitter with 150 characters ;D

Tuesday, April 3, 2012

Javascript all the way

These days I'm playing with NodeJS.
And today I was thinking about the fundamental change in Javascript.
A few years ago it was a darn language for the web.
Now someone could query a database using Javascript (CouchDB), create the server portion of a web application using Javascipt(NodeJS), create the browser portion of a web application using pure and fast Javascript, and even create a pure mobile interface using Javascipt (Appcelerator Titanium).
Google has proposed a language trying to replace Javascript called Google Dart, but I seriously doubt Google will succeed.

Thursday, March 29, 2012

Estimating Spanish budget deficit

This is one of my political/economical post (nothing related with computers) I write from time to time.

Past February, Spain published its estimation of whole year budget deficit.

Many well respected analysts suggested or explicitly wrote that maybe new Government was increasing 2011 deficit so that it could blame previous Government, and also in order to make it bigger so that it was easier to make it smaller. One for all, Xavier Xala i Martin:

Los números presentados hoy los ha construido el gobierno del Partido Popular y evalúan el año 2011, último año de gobierno del Partido Socialista. Bajo este punto de vista, hay que resaltar que al PP le interesa magnificar el déficit de 2011 (es decir, le interesa poder decir “hemos encontrado un déficit muy superior al esperado”) por varias razones: Primero, para “demostrar” la incompetencia del PSOE. Para los políticos de todos los colores, nunca está de más echar por tierra la reputación de tu enemigo político. Segundo, porque en la medida que puedan mover contablemente ingresos del 2011 al 2012 y puedan mover gastos en dirección contraria, el mayor déficit asignado al PSOE en 2011 se traduce en menor déficit para el PP de 2012. 
Even EU Commission was expected to open an investigation to clear if Spain had overestimated deficit for political purposes.

I couldn't believe it. If there had been any kind of manipulation in Budget deficit Spanish figures it has been downwards, not upwards.

I expected somebody could examine the data in a similar way, as I had been doing, and tell everybody 8.5% budget deficit in Spain for 2011 shouldn't have been a surprise. When I started to read this post of Edward Hugh, I thought "he finally got it", until I got to the part: "the deficit itself will not form the primary subject matter of this post."

OK. So maybe I've come a to a methodology to study monthly/periodic data so that we can anticipate its evolution before end of year. [laugh]

Usually for periodic data you get it compared with similar period of the previous year. For example, for a company you get quarterly data compared with same quarter previous year.

Sometimes you get the data for all the previous periods of the same year. For example, you get data for the 3Q2011, and accumulated with 1Q2011 and 2Q2011, compared with the first three quarters of 2010.

Both two methods (single period, natural accumulated) do not help estimating data series. I'm told econometricians try to remove variability using different techniques.

I use a simple method.

If you want to know some value at the end of the present year, but you don't have data of  the whole year, you should take data equivalent to a twelve month period.

For example: if you have accumulated data up to third quarter, and you want to estimate the data you'll have at the end of the fourth quarter, you should take the amount accumulated up to third quarter of this year, and add the amount of the the fourth quarter of last year.

Yes I know. It's not a great estimate, but for budget data shows a trend and it is very easy. On January 31st, 2012 we had available third quarter Spanish deficit figures. It was, in European terms (PDE,) 56719 million euros. So if we wanted to estimate fourth quarter 2011, we should form a twelve month period. We take fourth quarter 2010: 37042 million euros. Let's add up:56719+37042=93761 million euro.

Using a twelve month period for 2Q2011, you can get a total of 97956 million euro (in European terms).

So, with 2Q2011 data, estimation was 98 billion euro, with 3Q2011, estimation 94 billion euro. Is that a perfect estimate?. Of course not. But it shows a trend. And with that trend, it was obvious we were decreasing our deficit, but it was obvious we weren't decreasing fast enough.

February, 28th. Official figure: 91344(*). And everybody said the government was forging the data upwards.

Look the following data, and tell me somebody forged it (December 31st, 2011 data is official figure).



(*)The official figure is an estimation, and is not homogeneous with the quarterly data. The fourth quarter is still to be closed in accounting terms.

Friday, March 23, 2012

The synchronized silver bullet

I lead a team that is transitioning a 9-year-old internal framework from a somewhat Struts based to Spring IoC and Spring MVC based. However in the meantime we keep hunting old bugs, which needs to dive in the code. In those occasions, from time to time, I find non-thread-safe code. When talking with the team, one of the usual solutions (at least at the beginning), was something like "Let's put synchronized to the method". I explained why I thought it was a bad decision. But after some of these episodes, I used to think "how is it that people smart and competent in many aspects of Java, people from whom I learn lots day in day out, just don't get it".

Today I was reading a book. And I've found this :


You declare this method as synchronized to make it thread-safe.
package com.apress.springenterpriserecipes.sequence;
public class SequenceGenerator {
private String prefix;
private String suffix;
private int initial;
private int counter;
public SequenceGenerator() {}
public SequenceGenerator(String prefix, String suffix, int initial) {
this.prefix = prefix;
this.suffix = suffix;
this.initial = initial;
}
public void setPrefix(String prefix) {
this.prefix = prefix;
}
public void setSuffix(String suffix) {
this.suffix = suffix;
}
public void setInitial(int initial) {
this.initial = initial;
}
public synchronized String getSequence() {
StringBuffer buffer = new StringBuffer();
buffer.append(prefix);
buffer.append(initial + counter++);
buffer.append(suffix);
return buffer.toString();
}
}


(mine is a newer version, but you get the point).

Let me put it clear: Synchronized IS NOT A SILVER BULLET. Synchronized makes sure that code is executed only by one thread. But it doesn't make sure that fields(member-variables) used in that code are not modified in between.

In particular, in this case, you could get a prefix, then other thread modifies the initial, a different thread modifies the suffix, and you get a real mess in your synchronized method.

Many people could tell me "You're right, but the setters are not supposed to be invoked after the creation of the object". Then I have to tell two things:

  1. Delete the setters and the default constructor (Spring allows it).
  2. Don't synchronize a whole method if you only need to be thread-safe the counter++. There is plenty of methods for doing it.

And how would I do it?. Uhm. That's a whole post itselt, and it would depend on the class behavior.

By the way. A great book in the topic: Java Concurrency in Practice.

Tuesday, January 31, 2012

Xerces and Xalan: Recipes for the win

OK. I have explained why Xerces and Xalan are a source of problems, and I have explained why you shouldn't use System.setProperty to resolve them. In this post I wan't to give a few recipes to resolve Xerces and Xalan problems.

  1. Under no circumstances use System.setProperty anywhere in your application. I know I have already dedicated a post, but I wanted to stress it once more. Sometimes you'll need some specific parser (OC4J had a strange bug that needed a specific parser, and Weblogic seems to have special needs too). If you need a specific parser, do it at container level (2nd  point), at application level (3rd point) or at the specific code (4th point).
  2. If you have to define any property do it at the start of the container or the server. For example, in Weblogic 10.3.3 in Windows, we had to edit the file startWeblogic.cmd at the domain path, inserting the following line

    set JAVA_OPTIONS=-Djavax.xml.soap.MessageFactory=weblogic.xml.saaj.MessageFactoryImpl

    Sometimes you don't need to do it at the container/server level. In Weblogic you can use something called XML registry that enable a different parser for a particular Document Type.
  3. Sometimes you can define the parser at the application level. For example, in Weblogic you can define a specific weblogic-application.xml with the following text:
    <?xml version = '1.0' encoding = 'UTF-8'?>
    <weblogic-application xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
    http://java.sun.com/xml/ns/javaee/javaee_5.xsd
    http://xmlns.oracle.com/weblogic/weblogic-application
    http://xmlns.oracle.com/weblogic/weblogic-application/1.1/weblogic-application.xsd"
    xmlns="http://xmlns.oracle.com/weblogic/weblogic-application">
    <xml>
    <parser-factory>
    <saxparser-factory>org.apache.xerces.jaxp.SAXParserFactoryImpl</saxparser-factory>
    <document-builder-factory>org.apache.xerces.jaxp.DocumentBuilderFactoryImpl</document-builder-factory>
    <transformer-factory>net.sf.saxon.TransformerFactoryImpl</transformer-factory>
    </parser-factory>
    </xml>
    </weblogic-application>
  4. When somebody needs a specific property for a factory and is not possible to modify the container or the application, the solution is not to do a System.setProperty (see 1st bullet), but to instantiantiate the specific factory. For exmaple, instead of doing

    import net.sf.saxon.TransformerFactoryImpl;
    System.setProperty("javax.xml.transform.TransformerFactory",
          "net.sf.saxon.TransformerFactoryImpl")
    TransformerFactory tf= TransformerFactory.newInstance();


    you should do

    import net.sf.saxon.TransformerFactoryImpl;
    TransformerFactory tf=new TransformerFactoryImp();


  5. In the long run, it should be great to use mechanisms to prevent using System.setProperty like this link http://stackoverflow.com/a/4208150/54256
Update (2012-10-01): I see lots of visits to this page. Maybe you should visit 


too

Sunday, January 29, 2012

Things about Xerces, Xalan and Saxon I didn't know (III)

In my previous entry, I tried to explain why Xerces and Xalan are so complicated. In this entry I want to focus in System.setProperty. Because, as I said that is the usual solution you are going to find when you need a specific parser for whatever reason.

And that solution is wrong. Very wrong.

Because, if you choose to change the provider using System.setProperty, you are changing the provider for all the applications in the container/server. It doesn't matter that you change it, then instantiate, and then change to the original value. Because, when you're running in an application server, there are some chances of additional threads needing to instantiate and getting a different provider of the one they are trying to get. In fact, that same problem was reported to my group a couple of weeks ago. We tend to give support to applications that use our framework. And, as I say, we received a strange error. Sometimes one report was generated OK, and sometimes it failed with some exception (don't remember off hand). Same query, same data. Fortunately, the stacktrace came with some reference to xerces. Quick search and discovered the report failed when a different report changed the Property for DocumentBuilderFactory to an old sun implementation. What was even better: the old implementation seemed to be not particularly needed. Looked like a copy&paste.

I guess you'll be asking yourself what to do if you can't use System.setProperty. Too late for this blog post. Wait for the next.

EDIT: Stack trace

java.lang.ClassCastException: com.sun.org.apache.xerces.internal.util.XMLGrammarPoolImpl
            at org.apache.xerces.impl.xs.XMLSchemaLoader.reset(Unknown Source)
            at org.apache.xerces.impl.xs.XMLSchemaValidator.reset(Unknown Source)
            at org.apache.xerces.parsers.XML11Configuration.configurePipeline(Unknown Source)
            at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
            at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
            at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
            at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
            at org.apache.commons.digester.Digester.parse(Digester.java:1647)

Wednesday, January 18, 2012

Things about Xerces, Xalan and Saxon I didn't know (II)

I said in the previous post that Xalan and Xerces sometimes look like magic. So what are they and why are so complicated?.

  • Xerces is a Java library that helps parsing, validating and managing XML documents. You can parse XML documents in different ways. You can transform into a memory structure, building a big object, or you can even parse only the elements you need. There's a whole array of ways to manage XML documents and schemas, and Xerces helps with them. 
  • Xalan is a Java library that helps transforming (XSLT 1.0) and querying (XPATH 1.0) XML documents. 

If you've reached this point you'll be asking why the buzz about Xerces and Xalan. There are four things that make Xerces and Xalan special:

  • Java application servers usually manage their configuration with XML and they need some version of a parser.
  • Because of that, Xerces is probably one of more forked projects in the history. Every little server that worth its bucks have its own version of Xerces. Yes, you have one official version of Xerces. But your own server maybe has it own. And probably instead of org.apache.xerces.jaxp.DocumentBuilderFactoryImpl, they will have called something like com.sun.apache.xerces.jaxp.DocumentBuilderFactoryImpl.
  • Even if your server doesn't use its own version of Xerces, chances are high that it will be using classes of type javax.xml.parsers.DocumentBuilderFactory or  javax.xml.parsers.SAXParserFactory to parse xml documents. To get an instance of these classes you'll use a design pattern called factory that will give you a specific implementation of the class. And the specific implementation you'll get depends on... a system property.
  • If you need to parse an XML document, you'll have to use those classes too. And if for whatever reason you don't like the specific implementation your server (or even somebody in your own project) is using, then you're basically screwed. Because you'll use something that appears in 80% of the articles about the topic: System.setProperty.

Things about Xerces, Xalan and Saxon I didn't know (I)

These days I'm getting very proud of myself. I'm acting less as a project manager and more as a true Scrum Manager. I go to the scrum, listen, and a great deal of my work that day is trying to solve problems for the team. That's great because in order to remove the glitches of my team I have to learn a lot on very different topics.
One of those topics has been Xerces and Xalan.
Xerces and Xalan is one of the those things every developer has listened about authentic horror stories. When it goes OK, you don't worry. And when things go wrong, the usual tactic is to put different versions of those libraries in different places of the server, make some System.setProperty and hope the best.
That tactic usually work (somehow). But not always. And it looks like (dark) magic.