Globalcode’s Casual Class: Spring

Quick post: in this last Friday, February 26th, 2010, I attended the first Casual Class of the year, from Globalcode. The topic was the spring platform and, among the main subjects mentioned were Spring itself, Spring Roo, Spring and cloud computing and the launching of the Spring Brasil User Group. If my memory doesn’t fail me, this was the most packed  Casual Class until now. Thank you Globalcode for one more great event!

A few pictures for your pleasure:

Dr. Spock Introcting Spring

Dr. Spock Introducting Spring

Renato Bellia talking about Spring Roo

Renato Bellia talking about Spring Roo

Claudinho playing with our tags

Claudinho playing with our tags

This time, SIX developers from our team decided to attend! And it was a great time for everyone. Thank you guys (and gals)!

Posted in java | Tagged , , , , , , , , | 1 Comment

Testing XML data in your unit tests with XMLUnit

Once upon a time I had to compare two pieces of XML data. And it was good.

Well, actually, it wasn’t. Comparing two sets of XML can be really tough. Initially, I considered doing so by hand. Bad, bad idea, because:

  • You can’t simply say xmlString.equals(xmlString2) – any white space, including those indentation of yours will make the test fail;
  • The same equals call mentioned above will never say that <mytag></mytag> is the same as <mytag/> – and it almost always is;
  • How would you consider namespaces at all in those circumstances?
  • To solve all of the problems above, you could parse the XML data and verify each node… manually. A whole lot of work.

equals is totally out of the game for the reasons mentioned above. And I’m too lazy to check manually each node of the XML data. Also, such verification would be very error prone.

A better solution is needed, and after some ‘googling’ around, I found XMLUnit. In summary, what it does is that manual verification… But well tested and guaranteed to work – it is a framework developed specifically with that purpose in mind.

This is how a JUnit test using XMLUnit looks like:

import org.junit.Test;
import static org.custommonkey.xmlunit.XMLAssert.*;

public class SampleJCrankyTest {
    @Test
    public void testXml() {
        // this test will pass =)
        asssertXMLEqual("<myxml></myxml>", "</myxml>");
    }
}

This code is using JUnit and, obviously, java – but they seem to be developing a .Net version as well, if you prefer that – its just not as complete as the Java version.

There is a lot of additional xml related features supported, so a look in the documentation is recommended. But concluding, if you need to make xml comparisons, please do yourself a favour and don’t even consider doing any kind of manual testing – go for XMLUnit.

Have you ever faced this kind of problem before? How did you solve it? Please leave a comment! =)

Posted in agile | Tagged , , , , , | 1 Comment

Iced Earth in Brazil

Hi everybody! This post is EXTREMELY off-topic and contains no technical information, so feel free to skip it – I just couldn’t help it but write this one!

This last Saturday, February 6th, Iced Earth came to São Paulo – Brazil. Iced Earth is one of the greatest metal bands I know, and I had to go =)

Following I’ll post a few pictures from the event. Before that, I just have to say: Matthew Barlow is amazing. The guy sings like no one else – his live performance is as good, if not better, than the CDs. In summary: I WANT MORE !!

Iced Earth

Iced Earth

Iced Earth

Iced Earth

Iced Earth

Iced Earth

Iced Earth

Iced Earth

Posted in misc | Tagged , , , | Leave a comment

Pair Programming as a Motivator

Everyone has ups and downs. Maybe a fight with a significant other, or a problem with family, it doesn’t matter, brought you down. I went through something in this line a while ago, although for a completely different reason. But why am I talking about this?

People who read my blog for sometime now probably know I like agile software development. One of the strategies it uses (from eXtreme Programming) is pair programming, and I talked about it a long while ago here.

Now, to the point. What I found out is that, at least for me, pair programming has one more advantage that I was not used to pay attention to: it can help you get motivated. Just having to explain my ideas and having to listen to my pair’s ideas goes a long way in terms of motivation. As I love what I do, this conversation “thing” helps me get back to reality and be productive.

If you cannot do pair programming constantly, what I would suggest you should do is, as soon as you’re feeling you’re not doing as well as you could, do some short pairing. Even if at least for an hour or so, it should help renovate your thoughts.

Now get your hands dirt, try it out and post a comment with your opinion! =)

Posted in agile | Tagged , , , , | 1 Comment

XML Handling in Scala

It is finally time to get back to Scala. In this post, lets cover briefly some of the support Scala has for handling XML data. This is impressive stuff, and more so if you are used to how complex this can be in Java, for example.

Lets start with a simple example. Lets imagine you are dealing with a legacy system that exposes user information in an XML file like this excerpt:

<users>
  <user>
    <name>Paulo</name>
    <country>Brasil</country>
    <website>http://www.jcranky.com</website>
  </user>
</users>

In Java it would take you a lot of code and some patience to get this file transformed into an entity object. At the very least, you would need to find some library and/or configure some kind of mapping. Now this is how you can do it in Scala:

// define the User entity class
case class User (name: String, country: String, website: String)

// create a new User instance, using the xml data
val user = new User((userXml  "name").text, (userXml  "country").text, (userXml  "website").text)

The case keyword above says that the User class is a bean – i.e. Scala will generate getters and setters for you, you will have a nice “toString” implementation, among other things.

If you want to try it yourself you can simply type the xml data in the scala interpreter and attribute it to a variable or constant, like the code bellow, and then use to code above to process it:

val userXml =
<users>
  <user>
    <name>Paulo</name>
    <country>Brasil</country>
    <website>http://www.jcranky.com</website>
  </user>
</users>

The only additional thing you have to do in order to allow Scala to understand the xml code is to add this import statement:

import scala.xml._

There are  two things happening in the xml handling above. First, userXml “name” gets a NodeSeq for each name tag found. Then text gets the String representing the tag’s body, which can be passed to the User’s constructor.

Now, something is wrong here, right? If I left the code in the example as is, I will only be able to read ONE user! Ok, I hear you. Just add a foreach loop, like bellow, and you’re done:

// extract the user reading code to a function
def readUser(userXml: NodeSeq): User = {
  new User((userXml  "name").text, (userXml  "country").text, (userXml  "website").text)
}

// loop through all users found in the xml and print them
usersXml.foreach(userXml => println(readUser(userXml)))

Better now? =)

Do you see that foreach thing we used in the last example? Well, that is not a XML specific function. It is defined in the Scala Collection API. Since the XML support is built on top of the Scala Collection API, you can do to xml everything you do to collections.

In this example, I’m demonstrating very basic features. There is a lot more worth taking a look in the Scala xml libraries. We only covered xml reading, for example. Writing may come in another post =)

Posted in scala | Tagged , , , , | Leave a comment

Program-ME Dojo Globalcode

Quick post, to bring back some life to this blog =)

About one month ago, on December 10th, Globalcode organized its first programming DOJO. The topic was Program-ME, Globalcode’s version of Arduino.

The idea of a dojo is to try to development/implement something, with the participation of the entire audience, instead of just the speakers doing “the hard work”.

The goal of this one was to develop a clone of the genius game, where the platform presents a series of lights and the player has to press buttons in the same order presented by its respective lights.

The session was mediated by Felipe Rodrigues and Alberto “Spock” Lemos. The code was to be written in C and, using Arduino’s tool, transferred to and executed in the device, a frankstein-thing assembled by Spock, heheh =)

Claudinho no pair programming

Claudinho doing some pair programming

In summary, it was a lot of fun, and I want more! I was the first to go there and code, which made me kind of nervous, but this was a nice experience, thank you Spock! =)

The only thing I didn’t like, and I would be happy to see improved is that they used a netbook as the development platform. And the keyboard of that thing is just too freaking small…

Posted in agile, java, misc | Tagged , , , , , | 2 Comments

Spring Roo: First Impressions

Two weeks ago I attended to the event The Developer’s Conference, down here in São Paulo, Brazil. I covered it here and here. One topic I decided to cover separated is Spring Roo. Rod Johnson, from SpringSource presented it in the conference, and really got my attention.

During the last few days I’ve being spending a few minutes per day with the tool. Following are an explanation about what it does, and my impressions in general. Hope you enjoy =)

The statement that describes better what Roo tries to do is “Roo is Rails for Java, but better”. Rod Johnson said something similar to this during his presentation in the TDC event, and I can agree with that. Rails productivity is nice, sure, but it doesn’t have the power of the Java platform. So bringing this productivity “home”, to Java, is an excelent idea.

To achieve this goal, Roo generates code for you. This isn’t, of course, a new idea. But the way Roo does it is what makes it really interesting. The concept is that you should be able to read and edit any code generated by the tool. Also, you should be able to use whatever IDE you prefer during development, without Roo getting in your way – I actually use Netbeans to edit the source code files, and although the IDE they officially support is Eclipse (the base for their Spring Tool Suite), it worked just fine.

The code generated by Roo has also desirable qualities: it follows good programming practices, like separation of concerns, and has good performance – there is no reflection in any of its “magic” to slow things down, for example.

This is how Roo looks like when running:

Roo Shell

Roo Shell

This is the Roo shell. It is where you type commands and execute tasks when using the tool. It features TAB completion, which works very nicely, and a lot of development support – you can type hint anytime to get a help message. Also, you can type help to see full list of commands currently available.

We haven’t created a project yet, so hint shows this:

Hint on an Empty Folder

Hint on an Empty Folder

Lets take a look at Roo in action. In the next screenshot, I’m using the command project to create a new project called JCranky:

Project Creation

Project Creation

Notice the TAB completion working; also, notice how Roo tells you what it did to your files, so that you can keep an eye on his behavior 😉

I’m don’t intend to write a tutorial, so I’ll just show one more code generation example and go back to commenting. Lets install persistence support, and then create an entity. The command to do the former is persistence setup and for the later is entity EntityName. The next two screenshots ilustrates the result of these commands:

Persistence Setup

Persistence Setup

Entity Creation

Entity Creation

Again, notice how TAB completion helps us. We don’t have to remember all those commands. Just hit TAB and Roo tells you what commands are available. Notice on the entity creation that Roo created a few .aj files. This is one of its secrets: it uses Aspects to insert code into your class, making it more simpler during source editing time. So boilerplate code like getters, setters and toString are inserted automatically in your entities to you. To understand a little bit more about this, take a look at the Aspect J site.

I’m not a fan of Spring, which obviously is used a lot in Roo and in the generated sources. But this tool seems to work so nicely that it might make me change my mind. And the same thing goes for maven, which Roo uses in the generated sources. But in this case, Roo also allows you to replace maven if you want to – but in this case you will have to write your own plugin to do that, at least for now.

I’ll stop here, but if anyone asks for more I might feel like writing another post =D. But before closing, lets mention the only one thing I really hated about Roo: it seems to generate code with TABs instead of whitespaces. So, Roo developers, I beg you: please generate whitespaces! I know it is a small thing, but it really freaks me out…

For more information, besides the official site, these three blog posts are very interesting: Jump into Roo for extreme Java Productivity; Getting Started with Spring Roo and Exploring Roo’s Architecture.

bye!

EDIT: After Ben Alex’s comment I looked again into the sources generated for my tests and couldn’t find any TABs. So please ignore this part of the post, until I find them again =D

Posted in java, web development | Tagged , , , , , , , , , , | 2 Comments

Globalcode’s Bug Novo Video

Just a quick update, while I finish the post about Spring Roo. Globalcode has finally published their “Bug Novo” video, which they had shown at the TDC event. Take a look here. It’s really worth watching, but its in portuguese =p.

Again, I covered TDC here and here.

Posted in java, misc | Tagged , , , , , , | Leave a comment

TDC – The Developers Conference 2009 – day 2

In the last post, I talked about the first day of The Developers Conference. Now lets talk about day number 2.

Very different from the previous day, this one started full of coding. And during the day, we kept seeing lighting talks and Vinicius’ toys. The only real problem we had was that the place ran out of eletricity for a while… but at least it didn’t last too long and the event could finish right.

Rod Johnson

The first speech was again from Rod Johnson. But this time, it was not philosophical at all. He presented Spring Roo, a project that aims at bringing to Java the productivity found in Rails. After seeing what he showed, I believe it. And love it.

In summary, the tool generates a lot of boilerplate code that we would otherwise have to write ourselves. And keeps it all out of the way while you develop your project.

I liked this so much that Spring Roo will be covered in a new post, exclusive to it, soon enough. And look, I don’t like Spring, but this thing can make me change my mind.

Rod Johnson on SpringRoo

Rod Johnson on SpringRoo

Lightning Talks

One of these lightning talks was about Spring best practices, which followed Spring Roo’s presentation. Ricardo Jun presented it, and mentioned things like how people tend to simply want to totally discard xml, instead of using it in moderation; the importance of using tools; the importance of modularization and also that we should always mind concurrency.

Jun and Spring Best Practices

Jun and Spring Best Practices

Another quick demonstration about robotics had an application server installed in a device, which was accessed through http. This device was connected to a lamp, and Vinicius turned it on and off through a web interface. Meaning: I want all the power plugs in my house accessible through the internet!! =D

On the note of excited people, I must talk about Vinicius Senger again. When presenting the balloon robot for the second time now, he breathed Helium, the gas used in the balloon to make it float. The effect was that his voice got very thin for a few seconds, creating a very funny moment.

Balloon Robot

Balloon Robot

Another lightning talk was about what was previously called Web Beans – now Weld: the reference implementation of JSR 299: Contexts and Dependency Injection. Alessandro Lazzarotti, from Red Hat, gave a quick demo on the implementation which is, of course, full of annotations everywhere.

An interesting lightning talk was about performance in JPA. Alberto “Spock” talked about how the Open Session in View filter pattern can be a little bit outdated when it comes to ajax applications – an environment which wasn’t there when the pattern was created.

Alberto "Spock" on Ajax and JPA Performance

Alberto “Spock” on Ajax and JPA Performance

In Globalcode’s blog here, he explains this problem better. During the presentation, he also mentioned the Apache Myfaces Orchestra project, which should also help minimize the problem bringing the conversation scope to your application. The conversation scope was first introduced by JBoss Seam, and brings us a scope bigger than request, and smaller than session, which can really help us manage resources in a lot of situations.

Mike Keith

This time Mike Keith presented about JPA 2.0. The goal of JPA 2.0 is basically to standartise what we currently do with, for example, hibernate, because we can’t with JPA 1. Nothing really new was presented – unless you didn’t know anything about JPA 2 already. But a few topics are worth mentioning.

A new evictall function was added. Useful to completetly clear cache between test cases. Small change but sounds interesting.

Now my pet peeve: the new criteria API. He presented it and showed a few examples and comparisons between the criteria code and the JPQL code. Just made me dislike it more. Just as a reminder, I already said that I don’t like this thing when I wrote about Globalcode’s Casual Class #006. Trying to access a database completely through OO code is just too much purism. At least, Mike is a very funny presenter to watch =)

Mike Keith on JPA 2.0

Mike Keith on JPA 2.0

Francisco Gioelli (Google)

The original plan was to have Chris Schalk talking about Google App Engine. Unfortunatelly, he had problems with the immigration and couldn’t get into the country. So google sent Francisco Gioelli, who did a nice job instead.

Among other languages, Google App Engine allows us to write Java web applications and publish them on the google cloud, leaveraging from the monstruous google scalability. A few features available include possibility of scheduling cron tasks through a xml file and the Big Table, their (non-relational) database. This last feature is the only thing that makes me a little bit worried about using google’s cloud.

Francisco on Google App Engine

Francisco on Google App Engine

This talk had a demo and was complemented by another one from Rafael (from Globalcode) – this last one using JSF 2.0 – nice! Two little extras mentioned by him: each request can take at the very most 30 seconds and the internal server used seems to be Jetty.

Alejandro Guizar (Red Hat Mexico)

This one was about BPEL. This is not a topic I can talk too much, so I won’t. The only thing that took my attention was something called BPEL Unit. I never heard of it and found interesting that such a thing exists. But I couldn’t find any good references…

Alejandro on BPEL

Alejandro on BPEL

Cloud Computing Panel

To close the event, a panel on Cloud Computing, featuring the main speakers that were present. This is a trendy topic nowadays, full of buzz words, but interesting, it was!

Ed Burns started talking that Sun have something (I forgot the name…) since 2000. Makes sense… very tipical of Sun: great products, terrible marketing. He also mentioned Zembly.com. If you are insterested, go to the site now. I just went there and found out that they are closing the service permanently from November 30th. Nice… (no, not really).

From Rod Johnson, we learnt that Springsource have their hand on Cloud Computing in the form of CloudFoundry. Also, he made sure to say how important it is to have multiple players in the market. Agreed.

Some points were easily agreed by the panelists:

  • private clouds will have big importance in the future;
  • a good thing of the cloud is the economy;
  • but a bad thing is the loss of control in a lot of senses, but probably mainly data;
  • we need easy of migration between cloud providers.

Someone asked about cloud computing and peer-to-peer. The panelists didn’t seem to believe too much in this possibility. Well, who knows…

A lot of gurus on Cloud Computing

A lot of gurus on Cloud Computing

Last picture, to change the mood a litle bit:

Relaxing between presentations

Relaxing between presentations

And so it ends this year’s event. I’m already waiting for the one next year! =D

Posted in java, web development | Tagged , , , , , , , , , , , , , | Leave a comment

TDC – The Developers Conference 2009 – day 1

So, one more Java event happened this last weekend down here in Brazil. The Developers Conference, organized by Globalcode, took place on the 6th and 7th of November in São Paulo, and it is going also to Florianópolis (9th) and Rio de Janeiro (11th).

Like last year, the event featured international speakers, and was really nice. In this and two other posts, I’ll be talking about what happened in São Paulo, since this is the location I attended.

Lets start off saying that this edition was the best one until now. Among the international speakers, we had Rod Johnson (Springsource), Ed Burns (Sun) and Mike Keith (Oracle).

Opening

The event started with Vinicius Senger’s (Globalcode) dancing robots. They started some music and turned the robots on, which started to dance. The dance was programmed by themselves into the toys. Really funny =)

dancing robots

dancing robots

Fast forward to a break that happened later, here is a closer picture of the robots in the stage above:

robots!

robots!

For the music, they used a parody they made themselves. They created a new music, based on an existing one, with lyrics related to software development. As soon as I have the link, I’ll post it here. That was really really funny.=D

One thing that always grab my attention at those events are how much some people are excited about their stuff. You could see this clearly about Vinicius in the entire event; but special was his scream at the end of the opening: “I love what I do!”

Rod Johnson

Rod Johnson was the first international speaker. He talked about how things are evolving in the software development world, and mentioned things like the fact that different kinds of data storage might be interesting, instead of using relational databases for everything; cloud computing and how Springsource (and VMware) might be involved (CloudFoundry). It also seemed that he likes Groovy and Grails a lot.

rod johnson at tdc day 1

rod johnson at tdc day 1

The talk was a little bit philosophic but interesting nonetheless.

Career Panel

Next we had a career panel, featuring the three international speakers. They basically told us some stories about how they started their careers, and things like what would they expect in interviews and the like.

career panel

career panel

Lightning Talks

Spread during the day, we also had lightning talks, with subjects like GWT, Google Guice, Agile Developement and Software Architecture, EJB 3.1 (samples, available on Kenai) and ScrumToys (which is available as a NetBeans sample project and a Glassfish sample application). Two pictures of those:

agile and architecture

agile and architecture

ejb 3.1 samples

ejb 3.1 samples

And in-between presentations, Vinicius appeared again with one more toy. Now, a robotic balloon:

robotic baloon

robotic balloon

Mike Keith

Following we had Mike Keith talking about J2EE 6. He talked a little bit about the timeline of the past releases, and about a few new features coming. Note-worthy, although not that new, is the definition of JEE Profiles – different versions of the application server, with different sets of libraries, for different scenarios.

For some odd reason, I don’t have a picture of this… so lets move on.

Ed Burns

Finally, Ed Burns talked about JSF 2.0 components. Some quick highlights: development of components should now be really easy; components can be built in groovy and can be packaged together with CSS and JS files; support for EL inside CSS files and CSS can be put anywhere in the page – JSF takes care of moving them to the page head tag later.

JSF 2.0 Components with Ed Burns

JSF 2.0 Components with Ed Burns

And that was all for day 1 of the event! The next post will be about the second day, which was as busy as the first one. Stay tuned!

EDIT: Click here for the coverage of the second day of the event.

EDIT 2: Here is the link for the video.

Posted in agile, java, web development | Tagged , , , , , , , , , , , | 2 Comments