Monday, May 17, 2010

Ant Script for Blackberry Development in IntelliJ Idea

To say that developing Blackberry J2ME applications is a nightmare is an understatement, especially is you wish to setup a comprehensive build and test environment for the team. It is possible to do things in bits and pieces, but having a single integrated development environment handle it all gracefully looks like a distant dream, forcing us to move to Ant and use its build scripts to get a build environment that is not only independent of the IDE but can also be used in continuous builds. Many thanks to Andrew for helping us to get this far. I have compiled the steps needed to set up the Ant environment in IntelliJ Idea.

1. Install Sun's Java ME SDK

2. Install Ant such as its path does NOT have a blank space in its installation path name

3. Install the relevant version of RIM JDE and emulator

4. Create an ordinary Java project. Change SDK to ME in project settings (Project Settings->General, you can bring up the dialog from File->Settings)

5. Check the folder in which the project has been created. Create the following sub-folders inside it: application, bin, lib, src, test, test_build, test_results. Within "test_build" create a "classes" folder

6. Even though you could link jar files from anywhere in the system, it may be a good idea to put following jars for following projects at one place in the lib directory:

Blackberry Ant Tools
JMUnit and Hammock
JDOM
J2MEUnit
Microemulator

Additionally, to make your life easier while coding, copy the net_rim_api.jar from the lib folder of the installed RIM JDE

7. In project setting (Project Settings->Modules), set "src" as the source folder and "test" as the test folder. In dependencies, add jars for RIM, JMunit, Hammock and J2MEUnit.

8. Expand the "Ant Build" panel and open properties dialog. Under execution, use custom ant and point to the intallation that does not have any blank spaces in its path. Under Additional Classpath, add all the jars that we had put in step 6. Be sure to have the ant tasks for JMUnit and Blackberry Ant Tools.

9. You are all ready to start coding under your "src" folder and write tests under your "test" folder. Now we need a build file that can enable you to actually build and test your code. For that, make a "build.xml" file, which will be your ant script, and place under the root folder. Use this script provided for you. Don't forget to adjust the paths as per your installations. With some luck, this should bring up 8 tasks on your pane: build, build_and_deploy, build_deploy_and_launch_simulator, launch_simulator, test, test_compile. Note that the build task will not launch test task in the current script, but you could change it if you please.

These tasks will accrue you the following benefits:

1. You can write your blackberry development code in Idea
2. You have an ant script that can be used to make contunuous builds and tests. The test also generates reports that are stored under the test_results folder.

My team has still not found a satisfactory answer to debugging, but current set-up helps us to develop using a more effective tool and get our automated build systems to run effectively for the wretched J2ME. Moreover, this Ant script can be run from any IDE (with similar configuration for the ant used). It is still not 100% perfect, but we are getting there: constantly thinking about testability, logging and sustainability of build environment. I will keep updating the build file so as it gets more comprehensive.

PS: We were able to build and test using Ant and Netbeans, but the build/deploy part was tightly coupled with Netbeans, which was not encouraging for automated build tasks.

Wednesday, April 14, 2010

An Ode To Testing

Even though I am all for quality, testing can get torturous at times. So here is a fun take on the perils of testing by yours truly :)

"O Horrible testing, in ways so many of thee
You take pleasure in tormenting me

Test cases are many, JUnit is one
And these useless stubs under the sun
Trying to focus my eyes water
As my head starts feeling hotter
And I yawn and I fall
Horribly sleepy one and all
In search of quality I seek thee
But a JMocking venomous smirk is all I see
Murderously as you try to JRun me
Yes, you take pleasure in tormenting me"

Tuesday, April 13, 2010

Thinking Quality: Basic Thumb Rules

Quality of code is often a critical issue in a development team. Ensuring the quality can get complicated for a variety of reasons, so let us explore the possible ways to ensure code quality.

First, it is important to get the programmer to think how he can keep improving the quality of his code. Bugs are inevitable, but that is no excuse for shabby programming. However, it is difficult to get most developers to take this seriously without antagonizing them. Nevertheless, making unit testing integral to development can check many if not all bugs. People can also be encouraged to develop a customized check-list for themselves to help them avoid common mistakes. Having a "company-wide" check-list may prove to be both counter-productive and bureaucratic.

Second, code reviews can be useful. However, it can cause antagonism within the team and people may be reluctant to criticize each other. Moreover, it can be done effectively only by senior and more experienced people in the team. Anonymous, time-bound reviews is one potential answer to use this tool.

Third, using Agile and related development technologies will help the manager to leverage the full experience of the team, get them closer to the requirements and avoid many bugs related with misunderstanding specifications.

Finally, the productivity of the team is the function of morale. Morale for different people can mean different things. The best way, however, to build it is by having a clear vision for the company and being able to percolate it meaningfully in every aspect of work. Further, focus on the strengths and interests of each team member instead of focussing on their weaknesses.

Thursday, February 4, 2010

Nested Table Component for Blackberry

Based on our last Simple Table component, I have put together a Nested Table as well. The main features are:

-Each row can be rendered like an irregular table
-Each row is backed by an object
-Possibility to add a popup to row click

These classes demonstrate how to use the component:
SampleApplication.java
SampleRowBackingBean.java
SampleBean.java

You would need the following classes to make this work:
BNestedTable.java
BMultiRowBackingBean.java
BGenericTableCallback.java
BAbstractRowRenderer
BNestedRowRenderer.java
BSimplePopupScreen.java
FieldCreatorUtility.java
UiProperties.java

Possible improvements:
-implementing varying row heights
-implement table header, table footer and column header

Wednesday, February 3, 2010

A Simple Table Component for Blackberry

Just worked on making a J2ME based prototype for a Blackberry (JDE 4.7+). The documentation, the website and the API are horrible, to say the least. We are using the Eclipse Plugin for development. One of the prime difficulties we faced was the absence of a well-defined table component. "ListField" is horribly designed and the example that is given in their documentation does needs serious improvement. Moreover, to make a flexible component that renders a list of messages (like the SMS message list) with each composite row selectable as a whole, no example could really help. So, I have made two components that you can improve upon and use as you please.

The first one, that is given in this post, is a simple table. It takes a 2-D array of fields and converts it into a visual table. It simply improves upon ListField. You would need the following three classes:

BSimpleTable.java
BSimpleTableCallback.java
BSimpleRowRenderer.java

Then in you code, use a similar code snippet to make and add a table (here we use it to create the title of the screen):

Field[][] titleContent = new Field[1][];
titleContent[0] = new Field[3];
titleContent[0][0] = new LabelField("S.No.",
DrawStyle.ELLIPSIS);
titleContent[0][1] = new LabelField("Message",
DrawStyle.ELLIPSIS);
titleContent[0][2] = new LabelField("Time",
DrawStyle.ELLIPSIS);
int[] widthPercent = {10,63,27};
int[] paddings = { 5, 0, 0 };
setTitle(new BSimpleTable(titleContent,
widthPercent, paddings,
Field.NON_FOCUSABLE));

If you don't want to sign the application, hard code the total screen width instead of using Display.getWidth()

Also, see: Version Specific Developmnet Guides (3.6 to 5.0 beta)

Wednesday, December 16, 2009

Marketing Triumphs Technology?

I have heard quite a few business leaders implying that marketing always triumphs technology. I do not dispute the importance of marketing. Nevertheless, working in technology business myself, I have no doubts that in the long-run technology is as important as marketing. Putting one above the other is to disparage one at the cost of other.

It is possible to use logic to exhalt any department. For example, the Business Development department can as easily assert that it is the sales force that gets in the money and is truly in touch with the truths at the ground level, unlike marketing managers that make a sweet sounding theoretical plans in their ivory towers. Technology, Marketing and Sales have their own place in the company structure. Comparing one with the other is absurd, unwarranted and potentially destructive.

Many technology guys are more interested in developing and creating. Innovation cannot come to them easily unless they are given a chance to interact with customers and involved with the business side of things. Barricading engineers & scientists in laboratories and complaining about lack of innovation is ironic, to say the least. Without customer interaction innovation is difficult to achieve. Marketing itself can be highly destructive if it operates in isolation from the customer. Sales without customer focus will kill the product eventually. Some people talk of innovation as if it is a commodity or a God given gift. My experience tells me that innovation is a result of closeness to customer and willingness to experiment.

Innovation may not be about wearing white coats, but it is not about wearing a tie and a suit (with a marketing hat) either. Innovation is an attitude born out of a company's culture and its people. Period.

Thursday, September 10, 2009

Speeding Up Technology: Thinking People

In the previous two articles I have talked about the need for a vision with an ambition and the need to cultivate leaders. I have talked about the importance of policy. It, however, strikes me that who will make policy? Policy is the product created by people. So we have read about the importance of hiring the right people. But who will hire the right people? Only somebody who believes in it as a concept and is willing to implement it in practice. Moreover, it does not end here and the company needs to be ready with at least ambition-vision + cultivate leadership mindset so as it can make full use of the right people and retain them. Bottom-up changes are generally painful and often viewed with suspicion by almost everybody at top. Top-down changes without getting people involved are viewed similarly by people who are not party to it. The next pre-requisite, then, is a lot of communication and flexibility within the limits of the clearly defined vision/ policy.

The organization is defined by its people. Nevertheless, people cannot operate in a vacuum. Having a leader that nurtures such people and inculcates a sense of pride and ownership in them without duping them is a rarity, and can be a supremely powerful force in the growth of a company.

What has to be remembered, though, is that no policy, no vision can be immutable. If there is one certainty in this universe, it is change. More so in the technical world. The playing field can change completely in few years at best and few months at worse, such is the speed of change. The only defence can be having the right people and cultivating in them a spirit of learning and leadership. I would call it a "nursery" of leaders, hiring brilliant people and preparing them to rise