25/05/2012

Book: Good Old "Peopleware"

One more book worth reading - "Peopleware: Productive Projects and Teams" by Tom DeMarco and Timothy Lister. It's essentially a Holy Bible for every manager!

Book: "Continuous Delivery..." by Jez Humble and David Farley

This book may help to make a product releasing and delivery to be more frequent and less painful.

05/10/2011

Builder Pattern Usage: Rule of Thumb

Builder Pattern is a creational design pattern. It is good in:

  1. Creating complex immutable objects
  2. Preventing objects being created to be used before initialization is complete.

Complex Immutable Objects

It's important that object being created should be Complex enough and Immutable. Overwise it may be an overkill to use a Builder for simple cases.

  • If object is not complex enough — you may use more simple ways of creating new object, e.g. use static factory method.
  • If object is not immutable — use setter methods

What kind of object are complex? Much depends on context, of course. But if object has less than than 2-3 constructor parameters is unlikely to be complex enough to use the Builder. I.e, if object can be created with factory method with up to 3 parameters, than object is simple and using Builder pattern is overkill.

One more pattern should be recalled here is Value Object or Data Transfer Object (DTO). Value objects or DTOs may be passed as a constructor parameters to simplify object creation.

Preventing early object access

Builder may be used to create an object which should not be used unless fully initialized. Initializing object using setter methods does not prevent client from calling other object business methods. To handle this incomplete state correctly you normally should perform object state check in the beginning of every business method and throw IllegalStateException... or just prevent object to be created in inconsistent state. One of the way to to this it is to use Builder. But anyway, you should check if all the parameters are initialized inside builder.build() method or inside object constructor:

import org.apache.commons.lang3.Validate;
public class PingResponseBuilder {
    private String serverName;
    private long timestamp;

    public void setServerName(String name) {
        this.serverName = name;
    }

    public void setTimestamp(long millis) {
        this.timestamp = millis;
    }

    private void validate() {
        Validate.notBlank(serverName, "The serverName must not be blank");
        Validate.isTrue(timestamp>0, "The timestamp must be greater than zero: %s", timestamp);
    }

    public PingResponse build() {
        validate();
        return new PingResponse(serverName, timestamp);        
    }
} 

Please keep in mind, that although memory is cheap and processors are fast, creating the new Builder instance for every created object instance is not very efficient. You may re-use single builder object (in a thread-safe manner!!!) for creating multiple object instances by setting differing properties, e.g.:

PingResponseBuilder builder = new PingResponseBuilder();
builder.setServerName("A Test Server");
...
PingResponse firstResponse = builder.setTimestamp(System.currentTimeMillis()).build();
...
PingResponse nextResponse = builder.setTimestamp(System.currentTimeMillis()).build();

25/02/2011

Connecting to Facebook Chat

Some time ago, Facebook has provided a public XMPP service. It makes possible to connect to Facebook chat server via any XMPP client (e.g. Pidgin or Adium) and send messages to your Facebook contacts.


Adium already has a built-in support for Facebook Chat. You may add Facebook Chat to Pidgin as generic XMPP service.

To configure your jabber client use the following recommended settings:

Protocol: XMPP or Jabber
Username:
Domain: chat.facebook.com
Jabber ID: @chat.facebook.com
Password:

Enter the following server info, as requested:

Port: 5222
Server: chat.facebook.com
Use SSL/TLS: no
Allow Plaintext Authentication: no

When you connect to Facebook account you'll see your Facebook friend groups in roster.
Friend groups (friend lists) can be edited only from Facebook site, not from the XMPP client.
Only your confirmed friends can contact you through Facebook Chat.

Currently, Facebook Chat does not support SSL and message encryption, but supports secured authentication using MD5.

For information about integraitng with Facebook Chat see here.

17/11/2010

Installing GWT Development Plugin in FF3.6 on OpenSuse 11.2x64

Compiling the plugin works for me on Arch Linux x86_64 or OpenSuse 11.2 x86_64 & FF36:

"
mkdir gwt-source
cd gwt-source
svn checkout http://google-web-toolkit.googlecode.com/svn/trunk/ trunk
svn checkout http://google-web-toolkit.googlecode.com/svn/plugin-sdks/ plugin-sdks
cd trunk/plugins/xpcom
export BROWSER=ff36
export DEFAULT_FIREFOX_LIBS=/usr/lib/xulrunner-devel-1.9.2/sdk/lib/
make clean
make
"

This shoulds create "gwt-dev-plugin.xpi" in prebuild directory, open it with FF and
may the force be with you.


Update: This reciept also works under Ubuntu 10.10 32bit (you don't need to export DEFAULT_FIREFOX_LIBS)

See original comment:
Issue 4141 - google-web-toolkit - Various compatibility problems with OOPHM Firefox plugin on Linux distros - Project Hosting on Google Code

30/09/2010

How to Set JSON Response Data Locale for Facebook Graph API

To make Facebook server return JSON responses in specified locale, you need to add parameter locale to the query, e.g.: https://graph.facebook.com/me?access_token=xxx&locale=en_US
The result is:
{
...
"gender": "male",
"meeting_for": [
"Friendship"
],
"relationship_status": "Married",
...
}


If you want to get results in russian, then add locale=ru_RU to query:
https://graph.facebook.com/me?access_token=xxx&locale=ru_RU
and you'll get result in russian (UTF-encoded):
{
...
"gender": "\u043c\u0443\u0436\u0441\u043a\u043e\u0439",
"meeting_for": [
"\u0414\u0440\u0443\u0436\u0431\u0430"
],
"relationship_status": "\u0416\u0435\u043d\u0430\u0442/\u0437\u0430\u043c\u0443\u0436\u0435\u043c",
...
}

redirect