Feature Oriented Programming – I

16 09 2007

Introduction

Few questions that have always drawn attention of the Software Engineering community

1. Is there any simpler way to explain the functionality of software to a layman? -Simpler then UML diagrams?

2. Can we start with a single representation and use it to generate the program as well as generate the test cases and documentation? – Can the representation x applied to a function f i.e. f(x) produce the desired program, generate the documents, and test cases?

3. Can we produce an optimized version by working on the original representation of software? Can O (n^2) explicit complexity of the representation x be reduced to O (n)?

4. My mom doesn’t know programming; can she still be able to write software? Can she just say -”I need a calculator to multiply two integers” and the calculator is before her screen?

Everyone in the IT industry would be happy to have all these in place. The main reason would be a huge reduction in the software development cost. And yes, recent research in Software Engineering is just focusing on them. Some major research in this area is going on product-line architecture in Department of Computer Science in UT Austin. They are working on feature-refinement techniques and almost covering all of the challenges 1-4 .

What is a feature?

A feature is a unit of functionality provided by a program. e.g. let’s take an example of calculator. The normal features of the calculator are addition, subtraction, multiplication and division of integers. Features can be added and removed and replaced just like different software to and from an OS. Product line architecture mainly deals with developing software by incrementally adding features to a product. The paradigm of software development using features as building block is called feature oriented programming.

FOP implementation

AHEAD or Algebraic Hierarchical Equations for Application Design is one of the pioneering work in FOP by the product line architecture group. It represents a program or a set of programs using a nested set of equations. It uses constants (a feature), a function (a feature refinement) and a few operators to write the equations. The equations are ideal for code generators and can be interpreted by different generators to produce codes, as well as documentations and test cases etc (2). They are simple enough to explain. Since they are based on algebraic equations, they are susceptible to optimization (3)

The main operator is called composition and it’s represented by a solid dot (•). Lets take an example of the use of this operator – let f is a program with features bf ,af ,cf and h with features bh ah and dh.

Then the composition of f and h is given by

f•h = { bf ,af ,cf }•{ bh, ah , dh}

= { bf• bh , af• ah , cf , dh }

Note that the constants with same name but different subscription are recursively composed to produce the final product f•h. The operator • is polymorphic so you are free to implement the operator as you like and produce your own implementation. E.g. it can be javac to produce the java codes from the equations, may be javadoc to produce the html pages.

I would include the other operators in my next post.

AHEAD Tool Set

ATS is the software kit that can be used to develop software in a feature oriented way.

You can download the latest version of AHEAD tool set from this link. AHEAD is developed in Java, so you will need JAVA. It is also preferable to download ANT as well. ATS comes with a composer. I have used it for refinement of Jak features. Jak features are written in a Java like languages that conforms to Jakarta Tool Set. Typically you pass the Algebraic equation to composer and the composer produces the desired product for you. Let’s try out your first programming in AHEAD using the FOP concepts.

 

Hello World in AHEAD

Aim : To generate a program that writes “Hello World” in three languages English, Hindi and Assamese.

Features –

  1. Base : that writes “Hello World” – English
  2. Hindi : That writes “Namaste India” – Hindi
  3. Assamese : That Writes “Namaskar Axom” – Assamese

 

Toolset version:

Runs in Linux

ahead-v2007.08.28

 

Steps:

1. Create the following hierarchy of directory in your $HOME

Hierarchy

 

2. Copy the following files to the appropriate directories

a. HelloWorld/Base/hello.jak

 

public class hello

{

String str = “Hello World”;

public void print()

{

System.out.println(str);

}

}

 

b. HelloWorld/Hindi/hello.jak

 

refines class hello

{

public void print()

{

str += “\n Namaste India.” ;

Super().print();

}

}

Note that we are using Super().print() to refer to the definition of the print() of the super class in the hierarchy. In this case Base->Hindi->Assamese

 

c.HelloWorld/Assamese/hello.jak

refines class hello

{

public void print()

{

str +=”\n Namaskar Axom”;

Super().print();

}

}

 

3. Create a file called composer.properties to set the following property –

unit.file.jak: JamPackFileUnit

It says when composing Jak files use the tool “jampack”. jampack is shipped with ATS.

4. Now in our case we want a composition comp = Base • Hindi • Assamese so that we can print something like

 

Hello World

Namaskar Axom

Namaste India.

 

So we run the composer inside HelloWorld as follows

$ composer –target=comp Base Hindi Assamese

 

5 . The composer creates a directory called comp in the same level.

The resulting composition will be the same “hello.jak” with the following modification –

 

layer comp;

public class hello

{

String str = “Hello World”;

public final void print$$Base()

{

System.out.println(str);

}

public final void print$$Hindi()

{

str += “\n Namaste India.” ;

print$$Base();

}

public void print()

{

str +=”\n Namaskar Axom”;

print$$Hindi();

}

}

 

You can see the tool is very intelligent to replace every Super().print() is replaced by a function with name as print$$[base class] . So finally when we call hello.print it should print the desired result .

 

6. The java code for the corresponding jak code is generated by jak2java tool comes with ATS.

 

So

$ jak2java hello.jak

will result in hello.java with

 

package comp;

public class hello

{

String str = “Hello World”;

public final void print$$Base()

{

System.out.println(str);

}

public final void print$$Hindi()

{

str += “\n Namaste India.” ;

print$$Base();

}

public void print()

{

str +=”\n Namaskar Axom”;

print$$Hindi();

}

}

7. Just write a test program to test it . I am using the following test program to do so .

 

import i3.*;

class test

{

public static void main(String args[])

{

hello c = new hello();

c.print();

}

}

~

 

And you should see something like

Hello World

Namaskar Axom

Namaste India.

 

On the screen.

A FEW MORE POINTS

If you want to install AHEAD from the source code – you must used the latest versions of Jdk and Ant , javaCC.

I am using the following version

JavaCC 4.0

jdk1.6.0_02

apache-ant-1.7.0

Be sure to set the env variable JAVA_HOME, ANT_HOME, AHEAD_HOME, PATH and LD_LIBRARY_PATH. I am still having some issues with compiling “reform” so I am using the executables instead.

In any case feel free to drop me your thoughts, queries. I would happy to discuss.

In my next post I would try to describe one more approach of FOP that I have used recently.

 

Just a point to ponder – “Compositor is polymorphic. What kind of polymorphism it supports? Dynamic or Static?”





Parallel Programming – the Open Source way

12 09 2007

In July 2007 gnu releases itslatest version of gcc (4.2.1 ). This release includes some of the bug fixes as usual – but the most significant part of it is that gcc is now openMP compatible. openMP though the name sounds like a standard open source software it was not really open. The standard was devised in Silliocon Graphics and many vendors including Intel and Microsoft was shipping with their propriority dev tools. openMP is now a standard for writing parallel programs that takes advantage of computing power of multiple processors or multicore processors. As the multicore processors become cheaper the parallel programming paradigm gains its popularity and reaches out to more people. But the hurdle was that it was not available freely – intel and microsoft was selling their compiler at a price that is more than the multicore processors itself. Finally it was released under GPL this july.
So I am happy.. I did a few stuff long back on openMP in my college on an intel compiler I guess. I am evaluating the version of openMP ( GOMP) with gcc 4.2.1 .. I think this link will be simple enough if you want to start programming in openMP.

Let me write you the first few steps to run your first program in gcc as well.

1. Download gcc 4.2.1 (aprox 50 MB) from this mirror

2. You need to have gcc 3.x in your box prior to compile gcc 4.2.1

3. Unzip the package using bunzip if the extension is *.bz or by bunzip2 if its *.bz2

4. Untar it usinf tar -xf [gcc-4.2.1].tar

5. then run ./configure –enable-languages=c,c++ ( i use C/C++ so …)

6. make and then make DESTDIR=[install dir] install

7. all the above process will take 30mins – 2hrs depending on the CPU you have

8. change your PATH to point to DESTDIR/usr/local/bin

9. change your LD_LIBRARY_PATH to point to DESTDIR/usr/local/lib

10. Now try gcc –version . It should give you the vesrion as 4.2.1

11. You can compile your program using g++/gcc as

g++ -otest -g -fopenmp insort.cpp

12. Run ./test

You will find some sample simple program in the tutorial i have mentioned. For some advanced issues like handling recursion and busy waits etc you may refer to this.

Happy programming .. You may leave your comments if you find trouble in some case .. I would happy to help..





A $1200 million software crash

10 09 2007

    I have read somewhere that the costliest  bug in   software  is out-of-range error where software produces unexpected results due to  inputs out of the expected range. In the trading software as well this is the erroneous conversion of price. Almost every exchange uses different format to represent price of stocks, bonds etc they deal with. So there were always special considerations needed  to convert price. This is not quite straight forward. We need to take care of almost all possible boundary conditions without compromising the time complexity. You cannot trust even the widely used boost::lexical_cast . (  boost trims some of the decimal points while converting double to string and it created a serious  issue once ).  Morgan Stanley was once fined $300,000 for sending a wrong price to NYSE. 

That was a descent $0.3 million bug. But unbelievebly  a bug in a program segment for converting a floating point number to a signed 16 bit integer cost $1200 million. “This out of range error which arose in both the active and the backup computers at Ariane 5 launcher at about the same time, was detected and both computers shut themselves down. This resulted in the total loss of attitude control of the launcher. The Ariane 5 turned uncontrollably and aerodynamic forces broke the vehicle apart. This breakup was detected by an on-board monitor which ignited the explosive charges to destroy the vehicle in the air. Ironically, the result of this format conversion was no longer needed after lift off.. “  And the cost was $1200 million.

Lesson learnt .. But  can we write a bug free software ? Not easy  I belive .. A few more disappointing statistcs -

—Windows 2000, 35 million lines of code ,63,000 known bugs at the time of release, 2 per 1000 lines

software errors cost the U.S. economy about $59.5 billion annually
Any thoughts ?





Backing up your coLinux

7 09 2007

coLinux root file system is just another windows file. This introduces the convenience of backing up your data in coLinux. Just copy the file to another partition in the windows now do as much experiment with the installation till coLinux crashes( i managed to crash it twice ;-) . If it doesnt boot up – just copy the root file to the desired location.

Now how do we find the root file system. The coLinux that I am using uses a txt file for setting up the environment. ( other coLinux distribution uses an xml ). The file is called settings_static.txt .

A typical settings_static.txt may be like this —

mem=128
root=/dev/cobd0
initrd=initrd.gz
kernel=vmlinux
#exec0=”xming\Xming.exe”,”:0 -ac -bs -clipboard -notrayicon -c -multiwindow -reset -terminate -unixkill -emulate3buttons 30″
exec0=”xming\Xming.exe”,”:0 -ac -clipboard -notrayicon -c -multiwindow -reset -terminate -unixkill -logfile Xming.log”
exec1=”sound\esd”,”-tcp -public”
cobd0=Drives\base.drv
cobd1=Drives\swap.drv
cobd2=Old\base.drv
cobd3=Devs\gp2x.drv
cobd4=\Device\Cdrom0
cobd5=\Device\Floppy0
cobd6=\Device\HarddiskVolume10
hda4=:cobd6
cobd7=Drives\new.drv
eth0=slirp,”",tcp:5901:5901/tcp:7100:7100/tcp:22:22/tcp:21:21/tcp:137:137/tcp:138:138/tcp:139:139/tcp:1000:1000/tcp:5000:5000/tcp:1001:1001/tcp:5001:5001
eth1=tuntap,”TAP-Colinux”,00:11:22:33:44:55
cofs0=C:\Linux\andLinuxPreBeta

From the file you can easily figure out that the root file system is  /dev/cobdo  which inturns  mounts  C:\Linux\andLinuxPreBeta\Drives\base.drv  at its point.

Now you have to make a copy of base.drv  to any other partition in windows.  Backing up is now complete !!
/dev/cobd0





অসমীয়া – Assamese

6 09 2007

An interesting article about the origin of my mother tounge .. This has appeared in a post in assam_in_bangalore yahoo group ..

 

” …To start with, the earliest form of Assamese appeared in the form of Chharyapadas. Chharyapadas were hymns written by traveling Buddhists in what is called an intentional language. According to what I believe, they are a variation of the Magadhi Prakrit language. Much later when they were translated by Tibetan and Buddhist scholars alike, it was seen that the Assamese language draws negatives, participles, verb forms, etc. from few of the Chharyapadas. This is 7th century that I am talking about. The Chharyapada manuscripts are now at the National Archives of Nepal. Coming to your question about the script: in the 7th century, the Assamese by far remained a variation of Prakrit and Apabhrahmsa. Modern Assamese script draws from the Eastern Nagari script, like Bengali. What you heard is not hearsay. From the Assamese language, there were four dialects: Eastern, Central, Kamrupiya, and Goalparia. Christian Missionaries started work in the Sibsagar area in the middle of the 19th century and the Eastern dialect spoken here came in focus of the British (as this was the documented local language). The British then made Eastern Assamese dialect the official language of the state. It was used in courts and offices. This is how we speak today, although traces of Kamrupiya Axomiya have been found as early as the 5th – 6th century in the writings of Xuanzang, a Chinese Buddhist monk. Almost all Indian and South-East Asian language trace their roots to the Brahmi script. Tibeto, Sino, Tai, etc. scripts all belong to the Brahmic family of scripts. The Brahmic family includes Devanagari (for Hindi, etc.), Eastern Nagari (Bishnupuriya Manipuri, Assamese, Bengali), etc.So you are correct that the modern Assamese we speak today came into force sometime in the middle of the 19th century. The Assamese script follows from Eastern Nagari (a variation of Brahmi) and not Tibeto-Sino- Tai; even when the British wrote it, it was in the Eastern Nagari script. (As someone pointed) Srimanta Sankardeva’s script was a variation of the Eastern Nagari script. …” Zeeshan





Common libtool errors

3 09 2007

1.libtool: link: warning: `libxxxx.la’ seems to be moved
2.libtool: link: `libxxx.la’ is not a valid libtool archive

This are errors reported by libtool when it references either a wrong location or a wrong *.la file .
The culprit is another *.la file in the libtool link path . eg

In the following case –
/bin/sh ../libtool –mode=link g++ -g -O2 -fpermissive -Woverloaded-virtual -Wsign-promo -m32 -O2 -g -L/projects/xdirect/ext/Linux-AS3-x86_32/AMI/lib -L/projects/xdirect/ext/Linux-AS3-x86_32/mlems-0.6.6/lib -L/opt/tibco/ems/clients/c/lib -L/home/adeka/svn/trunk/ma-gateway/MILAN/../../ma-framework/src/ -pthread -o libgtwy_milan.la -rpath //lib -export-dynamic -version-info 3:2:0 MilanGateway.lo MilanSession.lo precompiled.lo -lmaframework -lAMI2

You might checkout the culprit in
a./projects/xdirect/ext/Linux-AS3-x86_32/AMI/lib
b./projects/xdirect/ext/Linux-AS3-x86_32/mlems-0.6.6/lib
c./opt/tibco/ems/clients/c/lib
d./home/adeka/svn/trunk/ma-gateway/MILAN/../../ma-framework/src/





CoLinux : Alternative to vmware ?

2 09 2007

Most of my friends uses vmware to run linux on windows machine. Given enough memory , vmware is pretty cool tool as an emulator. But my friend still uses a laptop , 128 MB RAM , a 1.3Ghz Celeron – and wanted to use linux on the Windows Xp he has.

An option could be CoLinux (Cooperative Linux ) – It runs as a single process and uses a wrapper to interact with the hardware. You can run almost any executable that runs on Linux as it uses the same binary format as that of other Linux OS. A simple easy to install package is available at AndLinux.

Installation is pretty simple -

1. Download the andLinuxPreBeta.exe

2. Extract it to any drive in your machine

3. Run run_to_install.bat

4. Run startup.bat to start coLinux

Step 4 will start XMing Server, the coLinux daemon on your box , it will also start displaying the control panel on top of all windows. Click on any icon on the panel and start using your own linux …





Semantic Web

29 08 2007

What is web semantic ?Can the content and view be separated in web design ?
What is Image Replacement ? A detailed audiocast on Internet Archive.





Call for Papers

29 08 2007

Wanna know details of upcoming conferences in computer science ?You will find a lot about the forthcoming technical conferences in the following website

http://www.nas.its.tudelft.nl/~alex/CFP/





gdb tips for uncooperative cores

22 08 2007

Running GDB on a core and get a stack trace with all ‘??’ calls

Here is how to get around it.

If you get a core for the app test.

Run:

gdb test

(ie. do not specify the core file).
Then (inside gdb) set solib-search-path to the location of your libraries

THEN type (inside gdb) core-file core.X

This will make sure the library path is known before the core is loaded, and should then keep the stack trace, but already be able to resolve the symbols so you should see what you really need.