Tuesday, December 8, 2009

HATEOAS (Hypermedia as the Engine of Application State)

HATEOAS requires that each server response must contain not only the requested data — but also control information (in the forms of specially tagged URLs) describing the next set of permitted interactions with the server .....
Craig McClanahan's post on advantages of using HATEOAS - reduced client' coding errors, avoid invalid state transitions, fine grained evolution of the api's.
Jim Webber's

Thursday, November 26, 2009

SSH X11 Forwarding

SSH X11 fowarding allows X11 connection to be tunneled from the remote system (client) to the local system (display server). Here is how to set it up to work on a Mac OS.
Open a X11 terminal
Start an ssh session: ssh -X -l username server-ip
xclock &
It should display on your Mac screen.

Friday, October 9, 2009

Maven

There is a lot of discussion on the net about issues with using Maven for builds. Fairly old post by Howard Lewis (Tapestry creator).
Read this Infoq Maven debate Another post worth reading is Don Brown's

The key problems with Maven seem to be:
  1. Poor documentation leading to a somewhat steep learning curve
  2. Inconsistent builds due to fact that repository metadata is not properly maintained and newer broken versions of plugins can be released. Maintaining transitive dependencies is a hard problem! This issue can be addressed by using very specific versions of plugins in the Maven pom.xml and by caching dependencies in a local metadata repo and configuring your Maven build to look there first before going to general repos like Maven or ibiblio.
  3. Verbosity of the pom.xml- this is primarily due to XML language choice itself. One way to address this is to use inheritance and put most of common stuff in a parent pom so that a project's pom is limited primarily to dependencies.
  4. Dealing with large multi-module projects - even Ant builds I suspect will have a problem here.

Thursday, September 10, 2009

Sharding

The best discussions I have come across is here (http://www.startuplessonslearned.com/2009/01/sharding-for-startups.html) and
here
http://blog.maxindelicato.com/2008/12/scalability-strategies-primer-database-sharding.html

Wednesday, September 2, 2009

MVC in the browser

Web applications should be architected with a RESTful API on the server side (using frameworks like Jersey or Restlet talking with a Javascript client UI. Libraries like JQuery and associated plugins make it easy to build sophisticated UIs and allow you to implement MVC concepts in Javascript. I see this approach becoming more common over the "traditional" web application, where the MVC framework is server-side and generated HTML UI (with javascript mixed in) is rendered in a browser client.
Pros of writing web apps this way:
1. RESTful service api is accessible to multiple clients - not just the browser, any desktop client (e.g. Java Swing app) or even external third-party consumers.
2. The size of "data" exchanged between client/server is less - compare to entire HTML page generated by traditional web app which is sent over the wire from server to client.
3. There is a clean separation between the client UI and the server which makes testing the UI in Javascript that much easier (you can stub out the RESTful services).

Monday, August 17, 2009

Using JQuery's dataFilter option to plugin parser for json

In a JQuery ajax call, when the data type is set to "json", JQuery uses the "eval" function to convert the response from the server into a valid Json object. There are some security concerns with using eval. As mentioned in the post, the alternative to using eval is to use a json parser. The downside is that javascript parsers are not going to be as performant as using eval. An easy way to plugin your parser is to use the dataFilter option in JQuery ajax call. For example:

$.ajax({
type: method,
url: url,
data: data,
dataFilter: function(data) { <<<<<<<<
return jsonParse(data);
},
timeout: 20000,
cache: false,
success: success,
error: error
});
Notice the dataType parameter is omitted since we handle the parsing ourself.

Wednesday, May 27, 2009

Selenium and firefox-3

http://www.spacevatican.org/2008/9/27/selenium-and-firefox-3
Beta-2 fixes this bug.

Monday, May 4, 2009

Cleanup in Selenium HTML tests

Selenium is a great testing tool. One drawback when writing HTML based tests using selenium is that there is no support for cleaning up after a test. So, if a test fails it may leave things in an inconsistent state which causes problems for subsequents tests in the suite or even for the same test to run repeatedly. One solution is to have a "special clean up test" that runs after each test. I have been thinking of introducing a cleanup section in a selenium test which is demarcated by the word: "cleanup." This requires changes to how HtmlTestCase parses commands in selenium-testrunner.js. When it encounters the special "cleanup" keyword, the rest of the commands are interpreted as being part of the cleanup portion of the test case. Also, modifications need to be made to the HtmlRunnerTestLoop , so that the testComplete function runs the cleanup portion of the test, before running the next test.

Sunday, January 25, 2009

Sequence Points

Sequence points map between IL (intermediate language) and C# source elements. A statement in C# may be implemented by several IL instructions. Several of these IL instructions may map to a single native instruction. They are essential for supporting source-level debugging as explained here.
NDepend uses sequence points to compute lines of code as explained here.
NCover uses sequence points to determine code coverage.

Sunday, January 11, 2009

Cyclomatic complexity - class vs method level? Chidamber & K

Cyclomatic complexity is useful to look at the method level. At the class level it mayb e useful to look at the sum of CC's of all the methods in the class - this is a different measure referred to as Weighted Method per Class.

This is a good article that looks at cyclomatic complexity of methods in a codebase developed using TDD approach.

This article looks at the correlation between defects and complexity measures.

The Chidamber & Kemerer metrics are worth taking a look at:
- WMC: Weighted methods per class
- DIT: Depth of Inheritance Tree
- NOC: Number of Children
- CBO: Coupling between object classes
- RFC: Response for a Class
- LCOM: Lack of cohesion in methods

Sunday, January 4, 2009

RhinoMocks Constraints with IsMatching() using Predicate

var mocks = new MockRepository();
var repository = mocks.StrictMock();
var controller = new AController(repository);
List items = new List {"foo"};
var modelObj = new ModelObj(items);

Predicate compareModelObjs =
delegate(ModelObj m) { return m.Items.AsEnumerable().SequenceEqual(items); }

repository.Expect(r => r.SaveModelObj(null)).Constraints(Is.Matching(compareModelObjs)).Return(true);
mocks.ReplayAll();
controller.Save(items);
mocks.VerifyAll();

Of course, you should probably write an Equals() method on the ModelObj.