terça-feira, 29 de junho de 2010

CSS Blue prints

Today let's talk about something lighter than code, numbers, database. Let's talk about CSS and page layout.

The page layout normally is a pain even to web designers with a lot of experience, imagine for the poor developers worried about their code. But there is some CSS frameworks around the web that could be used to reduce quite a lot the effort to create a prototype or even the final page layout.

As you need to have a good foundation at Java to use any Web framework around, you should have a good foundation at CSS and page layout to use those kinds of framework. The good point is that even if it is not your case you can still use those frameworks as a start point to learn about it.

One of those CSS frameworks is the Blueprintcss:

Blueprint is a CSS framework, which aims to cut down on your development time. It gives you a solid foundation to build your project on top of, with an easy-to-use grid, sensible typography, useful plugins, and even a stylesheet for printing.


First we need to understand what is a CSS framework. Let me say that it is not: it is not a magic box that everything renders magically, it is not a code generator for CSS, it is not a component that you plug into you HTML page and the page is rendered automatically. A CSS framework is just a pattern that you should follow to develop your web page, elements and CSS styles, and provide the foundation for a fine and consistent layout.

The first step of those CSS frameworks is to define how the elements will be displayed into the page. Blueprint, as many other CSS frameworks, divides the page in fix size columns which are used to place the component elements. For an example: imagine that you divide your page in 24 columns of 10 pixels each. You can say like, my header will be a box that will take over 24 columns, my left menu is a box that takes over 10 columns and at the side of it my body will take over 14 columns. So basically with this kind of layout style you just need to create boxes and say how much columns does it takes.

As this column division is not produced using tables but using divs and styles to make it as big and the amount of columns that you expect, you will end up with a tableless layout too.

The second characteristic of the Blueprint is to define the fonts, there is a basic set of fonts to guarantee that you page looks like the same in all the browsers. Not that it is not just the font familt, but also the size, space and etc.
And finally it provides you with a set of other styles that can be applied to your forms, tables and so on.

There is much more there so far I recommend you to take a look at this example (you will understand much better how the column layouts work): A Closer Look At the Blueprint CSS Framework.

Using those kinds of frameworks (Blueprint is not the only one) is a good step to simplify the page layout, but it for sure do not replace a good layout and user interface analysis. Take a look, you may not use the framework, but I am quite sure that you can take some ideas over there.

For those that wants to go further the project wiki page as really good material: http://wiki.github.com/joshuaclayton/blueprint-css/.

And as usual the sidekick, today I recomend the song Ya no sé qué hacer conmigo, from the Uruguayan band Cuarteto de Nos.

quarta-feira, 23 de junho de 2010

Let's calculate

Everyone knows that float point numbers are far from been precise. In fact they are as precise as any other number, the problem is that they work in a different base (2 instead of 10).

Let's take an example to illustrate that: the number 0.01, it is a quite simple and clear number in base 10 notation. Now let's add to it 0.09, which is the expected result? 0.1 right? Well doing it using floating point numbers we will get: 0.09999999999999999.

But why? We it is because altough 0.01 and 0.09 can be easily represented in a base 10 notation it doesn't have a real representation in the base 2 notation. It is something like 1/3 it is 0.3333334, the same with those number. What we have at the end is a periodic number, which is rounded to provided the expected number, but when we do a calculation this number cannot be rounded anymore.

Basic stuff, and I guess everyone faced it before, expecting the right result is the same of someone (yes it is a true story) that wants to divide the 100% by 3 and sum it back and expect to have 100%. Well it is not going to happen, 100% by 3 is 33,333333% and it sum back is 99,99999999%.

Sure that there is nice ways to work around this problem, in most of the languages. But all this introduction is to say about this ways, it is just to present a really nice calculation component/program that you can use in your Java programs: Frink.

"Frink is a practical calculating tool and programming language designed to make physical calculations simple, to help ensure that answers come out right, and to make a tool that's really useful in the real world. It tracks units of measure (feet, meters, kilograms, watts, etc.) through all calculations, allowing you to mix units of measure transparently, and helps you easily verify that your answers make sense. It also contains a large data file of physical quantities, freeing you from having to look them up, and freeing you to make effortless calculations without getting bogged down in the mechanics."
You can use it to calculation with the right precision your nice mathematical stuffs (no more error in 0.01 + 0.09), but you can do even more with that. You can virtually convert any unit to any unit.
The possible calculations goes from the normal phisical stuffs like, energy to temperature to crazy examples like how much time Superman should recharge his energies at the Sun to save Lois Lane and some kids, or even further how much weight Lois should loose to help Superman saving some kids (check the examples here).

Take a look at the main website, it worths and can be really helpfull for you, when you need to do some nice calculation in your application.

And finally for those that want to go further in floating point theory: What Every Computer Scientist Should Know About Floating-Point Arithmetic.


A good sidekick for this post is The Magic Numbers - Forever Lost.

Enjoy it ;-)

quarta-feira, 9 de junho de 2010

Apache Pivot and news

It has been a while since the last post. Unfortunetely the time is still short to continues with the DOD posts, in this meanwhile I will talk with a relatively new Apache project: Pivot.

As stated in the project main page the purpose of Pivot is to:
Building rich internet applications (RIA) in Java by combining the enhanced productivity and usability features of a modern RIA toolkit with the robustness of the Java platform.
The first issue that should be clarified, it is not a HTML+CSS+Javascript solution like ExtJs or JQueryUI or any other framework around. It is in fact a framework for build application in the old and good JVM.
It means that to run this RIA application you still need the Applet (or webstart), a JVM in client and all the stuff for this kind of application.

The first question is: so not why Swing? First of all the Pivot UI classes provide a lighter implementation than Swing, something like Thinlet. All the UI elements are rendered using Java2D and it also provide some nice effects (over the tradicional Swing).

On the top of it the interface can be created with a declarative language, so you don't need to use that huge amount of code. They have choosen to use the WTKX, which is a XML that you can specify the interface (acording to the project website: "A nice and open XML for declaring graphical user interfaces in Java"). This fact is already a great advantage over Swing.

And finally why RIA? Is it not just another UI framework. Well in fact no, it also comes with a set of classes and libraries that makes the comunication with a webserver much easier, thinks like http calls, web service integration and so on.

I think it as a good alternative for traditional Swing app, maybe not just for RIA application, even for your Java desktop app. Such kind of integration with the webservices is really usefull.

What I still miss there is a better way to deploy your application over the web. Using applets and webstart is still a pain.

By the way, before saying see you next time, I would like to introduce a new session in the posts, a part that can be used even if the post is really boring or not usefull at all. For example, tip for a song, movie, a cake receipt, a joke, whatever. Today I will go for a music, so...

A good sidekick for this post is Dropkick Murphys - Johnny, I Hardly Knew Ya.

segunda-feira, 31 de maio de 2010

Agile development and how people are using it.

Are you interested in Agile Development? There a quite interesting Scott Ambler webcast that you could be worth listening to it.
This webcast is a IBM presentation, so you could expect some IBM view and products for Agile, but at the same time it is based in a survey distributed across many organizations, so you also could expect some real information (like what happens when the teams are distributed and not collocated as the initial ideas, agile only works for small teams and so on).

Any way as Scott say in the webcast, there isn't any new in Agile Development compared with other kind of developments. So don't expect magic words to make everything start working from day to night, but I recommend you to spend some time listening to it and put some extra color in the big picture of Agile Development.

Here is the link to the webcast: Busting the Myths of Agile Development: What People Are Really Doing.

Have a nice week!

quinta-feira, 20 de maio de 2010

segunda-feira, 17 de maio de 2010

Thoughts about Document Oriented Databases - part 3

In the last post I presented the first Use Story and the base classes for the problem, now I will walk into the service layer.

Let's make our example a little bit more complete with others user stories:
NEWTON: As a nerd, I want to be cool having the possibility to have a specific night for a specific day.
I can have a night for a specific day that differs from the normal night for that day of the week. It is a special night occasion.
PASCAL: As a friend of a nerd, I want to know when a night happens.
Based on the name of the night I want to know when it happens.
Based on the day of the week I want to know what is the night of that day <(I don't want to avoid those nerd guys)>.
I want to know which night of a specific day.

We have based your class diagram on the PYTHAGORAS use story, now with the addition of the NEWTON and PASCAL user stories we have enought information to create our first service interface (based on the Night) and your test case for the further service implementations.

So your first service will look like this:

public interface NightService {

/**
* Add a new night to the store. If the night is supplied with an ID it will be replaced.
* After the call to the registerNight method the Night object will have the ID filled.
* @param night night to be added.
*/
public void registerNight(Night night);

/**
* Replace the night stored. The provided night should have the id filled in order
* to have the date replaced correct.
* @param night night to be replaced.
*/
public void changeNight(Night night);

/**
* Returns the night by its unique identifier
* @param nightId identifier of the night.
* @return
* Night object, null if there isn't any night for that id.
*/
public Night findById(String nightId);

/**
* Returns the list of nights of the specified day of week.
*

    *
  1. The order returned by the find week day should be from the first include to the last one.

  2. *

* @param dayOfWeek
* @return null when there isn't any night for the specified day of week, otherwise a list with the nights.
*/
public List<Night> findWeekDayNights(DayOfWeek dayOfWeek);

/**
* Returns the list of nights of the specified name, the name match is not case sensitive.
*

    *
  1. The order returned should be from the first include to the last one.

  2. *

* @param dayOfWeek
* @return null when there isn't any night for the specified name, otherwise a list with the nights.
*/
public List<Night> findNightWithName(String nightName);

/**
* Returns the corresponding night for a specific day.
* @param date date of the night
* @return
* Night corresponding to the date, if there isn't any night for that day then returns null.
*/
public Night nightOf(Date date);
}


Based on this service let's created a test case to test all your service implementations. This test case is to make sure that all the services methods are working properly, after that we will be able to start executing your desired tests.


public class NightServiceTest {

private NightService nightService = null;
private TestUtils testUtils = null;

//... Code removed for simplicity

@Test
public void testRegisterNight() {
Night movieNight = testUtils.createNight(DayOfWeek.MONDAY, "MOVIE_NIGHT");
nightService.registerNight(movieNight);
Night movieNightRead = nightService.findById(movieNight.getId());

assertEquals(movieNight, movieNightRead);
}

@Test
public void testChangeNight() {
Night gameNight = testUtils.createNight(DayOfWeek.TUESDAY, "GAME_NIGHT");
nightService.registerNight(gameNight);

gameNight.setName("Man this is the really the GAME night");
nightService.changeNight(gameNight);

Night gameNightRead = nightService.findById(gameNight.getId());

assertEquals(gameNight, gameNightRead);
}

@Test
public void testFindNightById() {
Night wOwNight = testUtils.createNight(DayOfWeek.WEDNESDAY, "WOW_NIGHT");
nightService.registerNight(wOwNight);

String validId = wOwNight.getId();
String invalidId = "invalidId";

Night validNight = nightService.findById(validId);
assertNotNull(validNight);
assertEquals(validId, validNight.getId());

Night invalidNight = nightService.findById(invalidId);
assertNull(invalidNight);
}

@Test
public void testFindWeekDayNights() {
//Create the nights
Night bownlingNight = testUtils.createNight(DayOfWeek.FRIDAY, "BOWNLING NIGHT");
Night arcadeNight = testUtils.createNight(DayOfWeek.FRIDAY, "ARCADE NIGHT");
Night kartNight = testUtils.createNight(DayOfWeek.FRIDAY, "KART NIGHT");
Night pizzaNight = testUtils.createNight(DayOfWeek.THURSDAY, "PIZZA NIGHT");

nightService.registerNight(bownlingNight);
nightService.registerNight(arcadeNight);
nightService.registerNight(kartNight);
nightService.registerNight(pizzaNight);


List<Night> mondayNights = nightService.findWeekDayNights(DayOfWeek.MONDAY);
List<Night> tuesdayNights = nightService.findWeekDayNights(DayOfWeek.TUESDAY);
List<Night> wednesdayNights = nightService.findWeekDayNights(DayOfWeek.WEDNESDAY);
List<Night> thursdayNights = nightService.findWeekDayNights(DayOfWeek.THURSDAY);
List<Night> fridayNights = nightService.findWeekDayNights(DayOfWeek.FRIDAY);
List<Night> saturdayNights = nightService.findWeekDayNights(DayOfWeek.SATURDAY);
List<Night> sundayNights = nightService.findWeekDayNights(DayOfWeek.SUNDAY);

assertNull(mondayNights);
assertNull(tuesdayNights);
assertNull(wednesdayNights);
assertNotNull(thursdayNights);
assertNotNull(fridayNights);
assertNull(saturdayNights);
assertNull(sundayNights);

assertEquals(thursdayNights.size(), 1);
assertEquals(fridayNights.size(), 2);

assertEquals(pizzaNight, thursdayNights.get(0));

//The order returned by the find week day should be from the first include to the last one.
assertEquals(bownlingNight, fridayNights.get(0));
assertEquals(arcadeNight, fridayNights.get(1));
assertEquals(kartNight, fridayNights.get(2));
}

@Test
public void testFindNightWithName() {
Night surprise_Surprise_Night = testUtils.createNight(DayOfWeek.MONDAY, "SURPRISE SURPRISE NIGHT");
Night big_Surprise_Night = testUtils.createNight(DayOfWeek.MONDAY, "BIG SURPRISE NIGHT");
Night surprise_surprise_Night = testUtils.createNight(DayOfWeek.MONDAY, "suprise surprise NIGHT");
Night double_Night_one = testUtils.createNight(DayOfWeek.TUESDAY, "DOUBLE NIGHT");
Night double_Night_two = testUtils.createNight(DayOfWeek.TUESDAY, "DOUBLE NIGHT");

nightService.registerNight(surprise_Surprise_Night);
nightService.registerNight(big_Surprise_Night);
nightService.registerNight(surprise_surprise_Night);
nightService.registerNight(double_Night_one);
nightService.registerNight(double_Night_two);

List<Night> nightsRead = nightService.findNightWithName("SURPRISE");
assertNull(nightsRead);

nightsRead = nightService.findNightWithName("SURPRISE NIGHT");
assertNull(nightsRead);

nightsRead = nightService.findNightWithName("SURPRISE SURPRISE");
assertNull(nightsRead);

nightsRead = nightService.findNightWithName("SURPRISE SURPRISE NIGHT");
assertEquals(nightsRead.get(0), surprise_Surprise_Night);
assertFalse(nightsRead.get(0).equals(big_Surprise_Night));
assertFalse(nightsRead.get(0).equals(surprise_surprise_Night));

nightsRead = nightService.findNightWithName("BIG SURPRISE NIGHT");
assertFalse(nightsRead.get(0).equals(surprise_Surprise_Night));
assertEquals(nightsRead.get(0), big_Surprise_Night);
assertFalse(nightsRead.get(0).equals(surprise_surprise_Night));

nightsRead = nightService.findNightWithName("suprise surprise NIGHT");
assertFalse(nightsRead.get(0).equals(surprise_Surprise_Night));
assertFalse(nightsRead.get(0).equals(big_Surprise_Night));
assertEquals(nightsRead.get(0),surprise_surprise_Night);

nightsRead = nightService.findNightWithName("DOUBLE NIGHT");
assertEquals(nightsRead.size(), 2);
assertEquals(nightsRead.get(0), double_Night_one);
assertEquals(nightsRead.get(1), double_Night_two);
}

@Test
public void testNightOf() {
//24.12.2010 is a friday
//29.02.2012 is a wednesday
//15.05.2010 is saturday
//22.05.2010 is saturday
Night gameNight = testUtils.createNight(DayOfWeek.FRIDAY, "GAME NIGHT");
Night thaiFoodNight = testUtils.createNight(DayOfWeek.WEDNESDAY, "THAI FOOD NIGHT");
Night feverNight = testUtils.createNight(DayOfWeek.SATURDAY, "FEVER NIGHT");

nightService.registerNight(gameNight);
nightService.registerNight(thaiFoodNight);
nightService.registerNight(feverNight);

Calendar _15_05_2010 = Calendar.getInstance();
_15_05_2010.set(Calendar.DAY_OF_MONTH, 15);
_15_05_2010.set(Calendar.MONTH, Calendar.MAY);
_15_05_2010.set(Calendar.YEAR, 2010);

Calendar _22_05_2010 = Calendar.getInstance();
_22_05_2010.set(Calendar.DAY_OF_MONTH, 22);
_22_05_2010.set(Calendar.MONTH, Calendar.MAY);
_22_05_2010.set(Calendar.YEAR, 2010);

Calendar _24_12_2010 = Calendar.getInstance();
_24_12_2010.set(Calendar.DAY_OF_MONTH, 24);
_24_12_2010.set(Calendar.MONTH, Calendar.DECEMBER);
_24_12_2010.set(Calendar.YEAR, 2010);

Calendar _29_02_2012 = Calendar.getInstance();
_29_02_2012.set(Calendar.DAY_OF_MONTH, 29);
_29_02_2012.set(Calendar.MONTH, Calendar.FEBRUARY);
_29_02_2012.set(Calendar.YEAR, 2012);

Night night_24_12_2010 = nightService.nightOf(_24_12_2010.getTime());
Night night_29_02_2012 = nightService.nightOf(_29_02_2012.getTime());
Night night_15_05_2010 = nightService.nightOf(_15_05_2010.getTime());
Night night_22_05_2010 = nightService.nightOf(_22_05_2010.getTime());

assertEquals(gameNight, night_24_12_2010);
assertEquals(thaiFoodNight, night_29_02_2012);
assertEquals(feverNight, night_15_05_2010);
assertEquals(feverNight, night_22_05_2010);
}
}


Next we will make our first implementation of this interface, using a relational database.

See you soon!

terça-feira, 11 de maio de 2010

High availability: defining the terms

It is quite common to see a lot of places talking about availability, how to make your website, program, web service, etc, 24x7.

Even here I talked few times about this subject, but what I miss is some papers discussing the meanings of the terms in this area. A kind of a common language that we can talk about, I know that it depends a lot of your environment, company, software and so on. So in this post I would like to put some light in this subject.

Last month IBM release one of their famous Redbooks (I remember a time that an IBM Redbook was a kind of: "OHHHH really do you have one!, but those times are over with the floppy disks): High Availability in WebSphere Messaging Solutions.

No, I am not doing advertisement about the IBM products, it has an excellent part about concepts, so it really worths reading the Chapter1. Introduction to Availability and Chapter2. Application Design for Availability.

There is a lot of concepts and therms definition that will help you a lot, doesn't matter if you are implementing something in your own software, designing an application, for general knowledge. For me it is a must read for developers, architects, software development support team and so on.

Hope you enjoy the tip!