Tuesday, January 25, 2011

Migrating to Joomla 1.6

I carried out a quick test to establish the issues in migrating to Joomla1.6 on my local PC. The simple answer is that one shouldn't jump into it if one is not willing to do a considerable amount of work oneself. I used a basic site which used rhuk_milkyway template. Here are the findings:

The JUpgrade actually works quite smoothly if you are converting from Joomla 1.5.22. It successfully creates a new working environment for Joomla1.6 and preserves the 1.5 installation. Basically a new directory is created to hold 1.6 code and the MySql database gets the additional Joomla tables with j16 prefix. In ideal world it should just be required to drop the old tables and directory and point to the new installation. However the life is not that simple.

Firstly, the default templates which Joomla1.6 comes with are not production quality and rhuk_milkyway is not supported. Originally it was envisaged to include this particular template in the production release but the idea was shelved. The net effect is that various menus just disappear as one has to place them in new positions manually. Also the menu items had a value of -1 set in line Link Type Options/Link Image for various menu items. All these had to be manually set which is annoying and cumbersome.

After spending around an hour I had a functional site but it was a crude replica of the 1.5 version. I was not too fussed about extensions at this stage but obviously their availability is a critical decision in choosing to migrate. To get the site fully working I would have been forced to spend a considerable amount of time on CSS. So the bottom line is : "Don't rush in! Access control lists are great but the effort required to migrate is too much at this point in time".

Saturday, January 15, 2011

Estimating project delay just from the quality of requirement specification

I was privileged to attend a course by Tom Gilb recently on quality and he produced a wonderful way of estimating project delay from just the quality of its requirement specification. Those who are not familiar with Tom should know that he is the pioneer of iterative development method. His Evo methodology with emphasis on weekly deliverables and feedback was produced in the 60s, a long before Agile and Scrum appeared on the horizon. Also he can be credited with introducing software metrics in the 70s which were incorporated as Capability Maturity Model level IV. People who have grown up in quality movement are familiar with the fact that the quality is something which has to be designed within a process and cannot be gained through mere inspection. So just by checking the number of defects in a random page of the specification we can estimate the probability of project success.

A logical page of around three hundred words is inspected for deviation from the rules like testability, ambiguousness and no-design by 3-5 people. It is no good saying that a quality like usability should be dramatically improved unless we numerically quantify it. We take the figure for the highest number of major defects discovered by a team member, D. We multiply this by a factor of two to establish the discoverable defect density (source: experience). Now any inspection only captures a third of the potential defects (source: Capers Jones) so we multiply the discoverable defect density by a factor to generate potential major defects. Now the likelihood of a major defect turning into a downstream bug is one third. Each of this downstream bugs will cost 10 hours to resolve. This gives the formula for project slippage as:

Hours slippage = D * 2 * 3 * 1/3 * 10 * number of non-comment logical pages in the specification

Now this is pure magic as it has been empirically validated on a number of projects in the field. If you don't believe it then carry out the test on a project on which you have worked in the past and see whether the slippage provided by the formula is not within plus or minus 10% of the actual slippage.

Sunday, May 23, 2010

PHP essentials for Java programmers

I recently had to do a project in PHP and being from Java background one notices enumerable similarities. Obviously the whole knowledge about object-oriented programming and the procedural constructs like assignments, statements, conditions, loop etc are totally transferable. However the key difference I noticed was in the function calls. In Java all the arguments are passed by value, even for the objects, ie we pass the copy of the address for the object. But in PHP we are allowed to pass arguments by value or reference. Thus we have a simple function

function writeName($name) { echo $name; }

it passes the $name argument as value. However, by just prefixing $name with an ampersand we pass the argument by reference to give

function writeName(&$name) { echo $name; }

The other clever thing about PHP function is that we can return a value by reference too. Take the example from Joomla! library:


function &getLanguage()
{
static $instance;

if (!is_object($instance))
{
//get the debug configuration setting
$conf =& JFactory::getConfig();
$debug = $conf->getValue('config.debug_lang');

$instance = JFactory::_createLanguage();
$instance->setDebug($debug);
}

return $instance;
}

Preceding the getLanguage() function by an ampersand indicates that the function will return a value by reference, thus the return is a pointer to $instance.

The another line which will puzzle Java programmers above is

$conf =& JFactory::getConfig();

=& the syntax simply means that $conf is being assigned reference to the object created by getConfig() method of JFactory class. :: notation indicates that we are invoking a class method rather than an instance method. The normal Java dot notation of object.method() for invoking an instance method is changed in PHP to object->method()

Armed with the knowledge in this article a Java programmer is ready to do a PHP project. The only other thing to bear in mind is that the class constructor is defined by function __construct(). Obviously one will have to come to grips with various PHP functions but this should be no different from understanding a new Java API.

Friday, April 23, 2010

Selectors in Cascading Style Sheets

The indispensable tool  in every web developers portfolio is Cascading Style Sheets (CSS). Once HTML has been used to organize the contents, the presentational brilliance stems from using CSS rules. Syntactically the rules have a selector followed by a declaration containing various properties separated by semicolons:

p {color:blue; font-weight:normal;}

This simple tag selector rule colours all the contents of
tags in the HTML document. Also noted that the property-value combination is defined by separating the property from its value with a colon.  Instead of p we could have used any of the html elements like h1, h2 etc. To apply the rule to a group of elements we simply use a selector with comma separated the elements. For example, if we want to override the h3, h4, h5 and h6 header elements default definition of the browser, we can just use group selector:

h3, h4, h5, h6 {color:black; font-size:1.2em;)

The commonest way of formatting content is to use the class selector in conjunction with <div> block element or <span> inline element.

.myClass {color:black; font-size:1.2em;) class selector has a period prefix. Currently it will apply to any tag which has attribute definition of class="myClass". For example, if we have the following in our document:

<p class="myClass">...</p>
<div class="myClass">...</div>

then the .myClass selector will apply the declaration formatting to both these elements. To just restrict the formatting to
element, we change the selector to p.myClass in our rule.

Along with class, id is another attribute which can be placed on most elements. Indeed, javascript uses id to get the elements. So if we have <p id="myID"> then the hash prefixed selector for this element becomes:

#myID {color:black; font-size:1.2em;)

We also have pseudo-classes and pseudo-elements available as selectors. The anchor pseudo-classes are used to invariably define link interaction with a:link, a:visited, a:hover and a:active selectors. We know that these stages happen with links. Similarly, the first line of a paragraph or a first letter of the paragraph doesn't have a tag but it is easily identifiable pseudo-element so we can have a selectors like:


p:first-letter {color: blue;font-size:1.5em;}


or

p:first-line {color: blue;font-size:1.5em;}

Similarly there are pseudo-elements after and before for auto-generated content. To prefix a paragraph with a class="intro" with 'Thought of the day!' auto-generated content, we have the selector syntax:

p.intro:before {content: "Thought of the day!" }

or to give the text after the paragraph:

p.intro:after {content: "Thought of the day!" }

To style tags within tags we have descendant selector. For example, to highlight emphasis within a paragraph we may use the selector:

h1 strong { color: red; }

Here sub-element <strong> within element <h1> is coloured red. Similarly if we wanted to select the ordered lists which are direct children of body element the syntax is body > ol for the rule. Note the angle bracket is used for the child selector. Or to get to an adjacent sibling we use the plus ('+') sign instead of the angle bracket.

We can also select on the attributes. These selectors allow us to select element which have a certain property. For example to select all the images with title attribute we will have a selector img[title]. Or to just select text boxes in a form we can have the attribute selector

input[type="text"]

There are some further refinements to these selector but the knowledge is acquired by experimentation. The aspects covered are more than adequate.

For a good source for understanding the selectors visit here.

CSS: The Missing Manual is a very useful resource which you should have in your collection.




 

Wednesday, April 14, 2010

Delight of w3schools

Like countless other people I have used the tutorials at w3schools to become familiar with various technologies at different stages in my life. It is impossible to be not familiar with this site for anyone who has taken delight in learning new things. I recall learning about ASP, XPath etc on this site a number of years ago. Indeed a career in IT is impossible without constantly updating ones skill base so a comprehensive training resource is a real boon. The site invariably appears in the top searches whenever 'Ajax tutorial' or 'jquery tutorial' type terms are used in google so cannot escape the radar of any technology aficionado. For last couple of years I had been hearing good things about jquey so decided to take the plunge and become familiar with the framework yesterday. Needless to say that w3schools gave me a couple of hours of real pleasure. There tutorial seem basic but they get to the heart of the matter. Their examples were lucid and their jquery engine for practising is great. So here is a public thanks for being so useful. W3schools, you rock!

Wednesday, March 31, 2010

The brave new world

The pressure on IT has always been there to deliver. I recall the 80s when the business-IT alignment was on everybody's lips, the 90s when the IT-facilitated business process re-engineering and kaizan were talk of the town and the new economic order was proclaimed by the web-based companies at the turn of the century. IT was always deemed indispensable in these initiatives but adjudged to be slow to meet the business needs. The bursting of the dotcom bubble and the y2k experience tarnished the IT image but did not abet the pressure on IT to facilitate inter-organisational processes in a globalised world. IT's role was still at the heart of 'making it happen'. One assumed that the ERP systems had taken care of all the transactional needs at the operational level and the datawarehouses and business intelligence tools had enamoured the business executives by adding value to strategy formulation. Now comes the frightening reminder that all is not well in the wake of global financial meltdown.

"Capital expenditure priorities are shifted into IT from other high-payback projects" just to perform necessary ERP changes, claims one executive. Whilst another bemoans: "Change to ERP paralyzes the entire organization in moving forward in other areas that can bring more value."

An Accenture partner sees rising tide of operational flexibility on daily basis and proclaims "strategy, as we knew it, is dead." A paradigm shift in IT's execution is expected and demanded in this new world order. Yet the top priority for 2009 was "modernizing key legacy applications" and the SOA, the pre-requisite for flexibility, seemed fatally wounded.

It is a challenge to all the IT professionals to acquire a mindset attuned with business imperatives and successfully deploy disruptive technologies to make a quantum change. The decade ahead of us is full of potential and we must not fail.

Tuesday, March 30, 2010

SOAP with Attachment API for Java (SAAJ) example

SAAJ is an indispensable tool for manipulating SOAP messages, especially if they have got attachments. We have illustrated all the steps in creating a SwA (SOAP Messages with Attachments) in the short self-explanatory example which can be adapted for all purposes.

package saajexample;

import java.awt.Image;
import java.awt.Toolkit;
import javax.xml.soap.*;

public class Main {

public static void main(String[] args) throws Exception {
// Factory needed to create SOAP message
MessageFactory msgFactory = MessageFactory.newInstance();
SOAPMessage message = msgFactory.createMessage();
// illustrate the story so far by dumping out the message
message.writeTo(System.out);
// detach the header from the SOAP Envelope
message.getSOAPHeader().detachNode();
System.out.println("");
message.writeTo(System.out);
// manipulate the body of the SOAP message
SOAPBody body = message.getSOAPBody();
SOAPElement getStockPrice = body.addChildElement(
"getStockPrice",
"rt",
"http://www.rajeev.com/jws/StockQuote");
System.out.println("");
message.writeTo(System.out);
getStockPrice.setEncodingStyle(SOAPConstants.URI_NS_SOAP_ENCODING);
System.out.println("");
message.writeTo(System.out);
SOAPElement code = getStockPrice.addChildElement("stockCode");
System.out.println("");
message.writeTo(System.out);
code.addTextNode("IBM");
System.out.println("");
message.writeTo(System.out);
// attach an image
Image image = Toolkit.getDefaultToolkit().createImage("raj.jpg");
AttachmentPart jpegAttach = message.createAttachmentPart();
// use setDataHandler method below if connecting to FileDataSource object for pdf file
jpegAttach.setContent(image, "image/jpeg");
// add the mime type for the image
jpegAttach.addMimeHeader("Content-Transfer-Encoding", "binary");
jpegAttach.setContentId("xxx");
message.addAttachmentPart(jpegAttach);
System.out.println("");
// message.writeTo(System.out); // cannot stream image
// check attachment created successfully
System.out.printf("Number of attachments: %d%n", message.countAttachments());
// remove the attachment and verify
message.removeAllAttachments();
System.out.printf("Number of attachments: %d%n", message.countAttachments());

}
}