Ada and Multiple Inheritance

July 28th, 2011 at 5:24 · Filed Under Ada, At Work, Call Me a Geek, Days in My Life, Software Development · Comment 

When developing an information system which computes real-life data, one of the most common problems a software developer may encounter is multiple inheritance. Inheritance is one of the four aspects in Object-Oriented Programming (OOP).

What is Object-Oriented?

Object-oriented technique organizes software as collection of discrete objects incorporate with data structures and behaviors. Take a software that keeps records of professors and students in a university for instance. Both professor and student are person. These three entities – professor, student and person are objects. A person has data structure such as name, gender and date of birth to make things simple. Both professor and student share the same data structure of person. A professor has employee number, salary, and room number. And a student has student number, courses and grades. Both professor and student have different behavior: to lecture and to learn respectively. We can let professor and student to inherit the same data structure and behavior from person. Person is superclass. Both professor and student are subclass. Now both professor and student can derive data structure and behavior from superclass person but at the same time, both can preserve their own data structure and behavior as professor and student respectively.

Multiple inheritance is where a subclass inherits from more than one super class. One of the most common problems with multiple inheritance is symmetry. Let subclass D inherits from superclasses B and C which inherit from another superclass A. This is called symmetric multiple inheritance.

Multiple inheritance is rather problematic at linguistic level. Many object-oriented programming languages support multiple inheritance and solve the problems in such a way that usually they cause surprises to their users. In the above example, the operations in A can be derived to B and C and overridden in any other ways by any one of them in D.

Ada provides different approach to implement multiple inheritance by simply not allowing user to get into such problem in the first place and to force the user to break the symmetry.

While I slip deeper into my software design, symmetric multiple inheritance occurs. I have two classes A and B where both of them inherit from object List.Node. Another subclass C inherits both superclass A and B. Ada forces me to break the symmetry by letting C to have a direct inheritance from A plus indirect secondary inheritance of B.


package List is
   type List is limited private;
   type Access_List is access List;

   type Node is tagged private;
   type Access_Node is access all Node'Class;

private

   type Node is tagged record
      Previous : Access_Node;
      Next       : Access_Node;
   end record;

   type List is limited record
      Head    : Access_Node := null;
      Tail       : Access_Node := null;
      Current : Access_Node := null;
      Count   : Unsigned := 0;
   end record;
end List;

   type A is new List.Node with private;

private

   type A is new List.Node with
      record
         Id   : Integer;
         Str  : String ( 1 .. 20 ) ;
      end record;

   type B is new List.Node with private;

private

   type B is new List.Node with
      record
         Precision : Float;
      end record;

   type C is new A with private;

private

   type C is new A with
      record
         Magic : B;
         Plate   : Integer;
      end record;

The waking of a sleeping beauty

September 10th, 2010 at 15:18 · Filed Under Ada, At Play, Blogging, Days in My Life, Software Development · 2 Comments 

I wrote a board game called AdaOthello way back in 2001 using Ada (of course) and GtkAda. AdaOthello is quite a beautiful piece of GUI that I had created for the first time using GtkAda on Linux. Unfortunately, I don’t have the time to improve the game engine and port it to Mac OS X. It became a sleeping beauty!

On August 27, Gustaf Thorslund contacted me about his wish to use my code and continue the development of AdaOthello. Today, I received another email from Gustaf informing me that he has revived the project.

First, I would like to express my gratitude to Gustaf to take my code, make a second home for it, and taking it to a new height. I originally released AdaOthello under GPL 2.0 or later and I continue to wish to keep it that way.

You can find AdaOthello at its second home here.

A hot Sunny affair

March 26th, 2009 at 3:03 · Filed Under Ada, Computing, Linux, Mac OS X, Solaris · 5 Comments 

I have been hesitating for another hot Sunny affair since the last one about three years ago. This is just another one I have been longing since then. The recent eclipse of Sun resurrects my overwhelming but sleeping desire. Although this happened near the time when Sun is setting, but it is never too late to do it again because Sunset is beautiful and romantic.

Will Sun set and never rise again? Here is my encounter of the hot Sunny affair.

Read more

Objectively Boolean

February 11th, 2009 at 2:34 · Filed Under Ada, At Work, Cocoa, Objective-C, Software Development · 2 Comments 

I was introduced to Objective-C in a workshop organized by Apple Malaysia about 3 years ago. Read my posts here and here. No real development using Objective-C after that.

One plain reason for me to pick up Objective-C again recently is to develop Cocoa and Cocoa Touch applications for the Macs and iPhone (and iPod Touch). Trying to having nonpartisan mind after so many years of using Ada (and away from C/C++ and variants) is a difficult task to comprehend. As an individual Ada developer (having my own opinion) I am finding C/C++ very compromising in many ways, for instance, readability of codes and safety. Although Objective-C has many improvement over C/C++, it is still lacking what Ada offers.

By syntax, Objective-C is still very much like C. A few obvious clues to tell if it is an Objective-C are the use of #import, instead of #include; the @ sign; the Smalltalk-like message passing syntax and several others.

The #include statement in C/C++ has many drawbacks. One which seriously affecting compilation efficiency is the repeating includes of same header files. With #import, header files are included once only throughout entire compilation.

One deadly pitfall I have encountered so far is the way Boolean type is implemented in Objective-C. C supports Boolean data type, bool, which takes on the value of either true or false. Objective-C has similar data type, BOOL, which is 8-bit number that takes on YES as 1 and NO as 0. If you unwittingly assign a 2-byte integer to a BOOL type, the result can be catastrophic. Only the lowest byte will be used for the value of BOOL. If the lowest byte is zero, for example, 4608 which its hexadecimal value is 0×1200, BOOL will be zero or NO.

Ada’s strong-typing disallows this to happen and thus saving, possibly countless hours of debugging. Personally, I like neither bool nor BOOL. I prefer Ada’s Boolean.

Unlike the dreaded C++, Objective-C does not support operator overloading and multiple inheritance. In Ada95, a restricted form of multiple inheritance is supported. In Ada2005, multiple inheritance is supported by new form of type called the interface type, similar to abstract tagged type with no components.

归零

September 30th, 2008 at 1:44 · Filed Under Ada, Blogging, Chinese, Days in My Life, Essay, General · 2 Comments 

读了成彪登在新华网作者文集,我对“归零”有很大的回响,也让我心中再次涌现了她的影子。读完文集,我热泪盈眶:

Read more

Ada tasking on multi-core

July 17th, 2008 at 0:37 · Filed Under Ada · 12 Comments 

With a multi-core processor such as the Intel’s Core Duo, the Ada tasking can be easily demonstrated compared to single core Pentium processor. Consider the following Ada code:


with Ada.Text_IO; use Ada.Text_IO;

procedure Tasking is

   task A;
   task B;

   task body A is
   begin
      for I in 1 .. 10 loop
         Put_Line ("A");
      end loop;
   end A;

   task body B is
   begin
      for I in 1 .. 10 loop
         Put_Line ("B");
      end loop;
   end B;

begin
   Put_Line ("Begin parallel tasking...");
   Put_Line ("The end!");
end Tasking;

The above program produces the following result which easily reflects the parallel execution.


A
B
Begin parallel tasking...
A
B
The end!
A
B
A
B
A
B
A
B
A
B
A
B
A
B
A
B

Hello? What is Ada?

July 9th, 2008 at 23:46 · Filed Under Ada, At Work, Blogging, Days in My Life, Seminar · 4 Comments 

I was giving an Ada talk this afternoon. The room was quite packed with students although not full. They were mainly 3rd year sem 1. Most of them were looking at technologies that they could work with their FYP (Final Year Project).

While I regaled them with fascinating true facts of Ada, I could see various reactions on their innocent and ignorant faces. Almost half of them gave an expression of “What is Ada going to do with my project?”, “What is Ada? Never heard of it.” or “Ada is old technology and is unpopular.” It was years of experience telling me not to waste too much time with such audiences. I quickly skimmed through some technical facts which they wouldn’t understand and continue regaling them with some interesting facts.

Finally, I had come to the end of the talk. It was the questions and answers session. No one had asked any questions except a girl who asked me about C# after the talk session was over. I explained to her the benefits of Ada over C# but she said she would have to start all over again. Again, my instinct told me not to waste time with such attitude and I turned my focus onto the two students whom I am supervising now. I continued with them a discussion of their project.

Unlike a couple of years back, I was too over-enthusiastic about Ada. I would talk regardless of audience reactions. After a few talks and a seminar this year, I find that I have changed. My enthusiasm is parallel to audience reaction.

Ada Obsession

June 17th, 2008 at 21:25 · Filed Under Ada, At Work, Blogging, Call Me a Geek, Software Development, Web · Comment 

Well, well, well. Kazeserver alpha RC1 has to be delayed due to some design issues and I am rewriting most part of the software so that the source can be understood easily. For the past two weeks, I was troubled by the old design but I have got a new picture now.

Isn’t Ada code easy to understand? Well, yes. But I was using a lot of Unbounded_String in records which made my code hard to read and understood. While Unbounded_String is compatible with database operation, it lacks the understandability and readability if compared to String (1 .. 10) for example.

Today, I am totally obsessed in Ada and am feeling the strongest Ada obsession after a couple of years. The feeling is still burning. If my Ada obsession keep burning, I believe I can release KazeServer for alpha testing before of June. Hopefully.

Patched a security hole in KazeServer

June 4th, 2008 at 14:46 · Filed Under Ada, At Work, Software Development, Web · Comment 

While I was at Honda waiting for the technician to reprogram the ECU, I found a security hole in the authentication part of KazeServer. An unrecognized user id with a null password would grant access to KazeServer but without any significant usability but posed a potential risk.

I quickly identified the cause and rectified the problematic logic in the program design. One down and many to do. One of the other critical problem is that KazeServer will get over with initialization and execute even without the MySQL server is running. A serious bug though.

Another 3 more days to release Alpha RC1 and yet so many problems and unfinished parts. I feel the release will have to be postponed then.

Pre-Alpha RC1

June 2nd, 2008 at 22:46 · Filed Under Ada, At Work, Blogging, Days in My Life, Software Development, Web · Comment 

I am in the midst of getting the KazeServer to roll out. During this pre-Alpha RC1 stage, works have been a little pressured especially cleaning up parts of the codes to make it neater and more efficient. A number of factors are also affecting during pre-Alpha stage.

One of them is the gnat Ada compiler issue on Ubuntu Hardy Heron or 8.04. Hardy comes with gnat-4.1 with a number of packages not added. Without these packages, I can’t build AWS-2.3. So, I have to roll out Alpha RC1 on Mac OS X until Ubuntu Intrepid or 8.10 with gnat-4.3 is released (hopefully with gnat-4.3 by October). I have another option which is I have to move to Debian Etch with gnat-4.1 but including the libaws-2.2.

libaws-2.2 is a pre-built library for AWS on Debian Etch. I am developing using gnat-4.4 and AWS-2.3 on Mac OS X. Moving to Debian Etch means I am downgrading the version of gnat and AWS and I feel a little skeptical about it. This is one thing I hate most, version inconsistency among the Linux distro.

After talking to my friends on this matter, it looks like I have few choices but to target on Mac OS X for the moment considering the tasks of installing and get the Debian Etch up and a whole lot of uncertainties in gnat-4.1 and AWS-2.2.

Entering Alpha stage

June 1st, 2008 at 22:35 · Filed Under Ada, At Work, Days in My Life, Software Development, Web · 1 Comment 

Finally, after weeks of experimental development, KazeServer is entering Alpha development stage. I expect to roll out Alpha RC1, hopefully before this weekend.

KazeServer is a web-enabled membership management system that allows registered members of an organization to login to review their membership data and other membership related transactions or records. KazeServer is developed 100% with Ada and AWS (Ada Web Server). The application itself is a web server. No web server, e.g. Apache, is needed to run KazeServer. It is a totally stand-alone independent application with a built-in web server (AWS).

Can’t build AWS in Ubuntu

May 26th, 2008 at 9:44 · Filed Under Ada, Computing, Linux, Software Development · 1 Comment 

About two weeks ago, I installed Ubuntu Hardy Heron in VMware Fusion on my MacBook (running Leopard). After some playing around with Ubuntu on my MacBook, I began to install software components such as the Ada compiler so that I could do testing on my MacBook without switching to the Ubuntu box.

I am working on a web-enabled application developed with AWS (Ada Web Server). This application is developed on Mac OS X. Building and testing on mac OS X has no problem at all. To compile the source on Ubuntu, I need AWS. So, I tried to install AWS packages from Ubuntu but found only broken dependencies. Then I decided to build one myself. The build has failed because the gnat (Ada compiler) from Ubuntu is 4.2. It lacks two Ada packages, a-calfor.ad[sb] (Ada.Calendar.Formatting) and a-catizo.ad[sb] (Ada.Calendar.Time_Zones). AWS depends on these to build.

I posted to comp.lang.ada and AWS list. It looks like I have no choice but to bootstrap gnat-4.3 myself or install from Ubuntu Intrepid or wait for the next Ubuntu release of gnat-4.3.

Mathematics – The Systematic Reasoning

May 21st, 2008 at 1:50 · Filed Under Ada, Call Me a Geek, Computing, Mathematics, Pascal, Software Development · 4 Comments 

I remembered the way my mathematic teachers taught maths in class. Although none of them explained why we must learn maths, as it was the way supposed to be, they taught me systematic problem solving. I began to appreciate the beauty of mathematics when I started immersing myself in programming. The algorithm development and language constructs which are based on mathematics fascinate me with its beauty.

A good programming language teaches us systematic discipline and systematic reasoning. The first programming language which I learned was Commodore BASIC. I hated that. I learned half way (as the matter of fact, 2 days) and I switched to Apple Basic. In the mid 1980s, Apple II was the most popular home computer after Commodore VIC 20. Apple II that ran Apple DOS caught on the wagon very fast. The most common programming tool on Apple II was of course Apple BASIC. That was my first programming language and I had written many programs with it.

Then I was exposed to FORTRAN 77. The language construct was pretty much like Apple BASIC. I caught on with FORTRAN pretty fast. Then under some influences from friends whom I met at the computer center, I learned Apple Pascal. We challenged one another to increase the boot speed of Apple DOS. We rewrote Apple DOS with Apple Pascal and evidently increased the booting speed of Apple DOS.

Pascal is a very structured language (compared to Apple BASIC and FORTRAN 77) invented by Professor Niklaus Wirth to teach students programming and systematic reasoning. The structural construct of the language enable the programmer to think of the problem in a structural approach. Pascal cultivates structural discipline in solving programming problems. Pascal has provided me most of the necessary training in systematic discipline and systematic reasoning in solving problems.

When CP/M was introduced on Apple II, I was able to use UCSD Pascal on CP/M enabled Apple II machines. It won’t be long before IBM and IBM compatibles (8086) stirred up a turmoil with MS-DOS. Then, Turbo Pascal (by Borland) emerged. Turbo Pascal was the lightest and fastest compiler at that time. I became addicted in writing computer programs with Turbo Pascal.

Then I caught on with C and C++ and began to develop software with Borland’s Turbo C/C++ compiler. When MS Windows became a de-facto standard on every desktop computers, I dwelled into Borland’s Delphi (based on Object Pascal) to develop GUI applications.

During Apple CP/M era, I was exposed to Ada. I discovered Ada compiler by accident in another computer shop. I bought the program without thinking twice. Of course, it was a pirated copy. There was no copyright law then. But thanks to the pirated Ada compiler, otherwise I would not know such beautiful programming language has ever existed!

In 1995, I started to learn Ada when books were available. In no time, I fell in love with Ada until today. Whenever I was told or perhaps requested to look at computer programs written in any other languages, e.g. PHP, Visual Basic, C/C++ and etc., I feel that represent an insult to mind trained in systematic reasoning as in Pascal papers which Professor Wirth wrote.

Ada and Pascal are very alike because Ada developers had adopted Pascal’s structural language construct. Both Ada and Pascal clearly represent logical expression without any difficulties. Both languages are constructed heavily based on mathematic concepts and thus enforce systematic discipline and systematic reasoning.

China’s proven world class competency

April 13th, 2008 at 13:20 · Filed Under Ada, China, Computing, Humanity, Linux, Software Development, Web · Comment 

During the snow hazard in China this February, the Chinese government had successfully managed the natural disaster and crisis with much professionalism in such a short period of time. According to an unconfirmed source, the Chinese government managed to develop a Disaster Management System in just 5 days. 75 software engineers from the Chinese military worked around the clock for 5 days to bring up a web based Disaster Management System to collect, manage, disseminate, coordinate, and to provide command and control to the military disaster relieve team during the recent snow hazard.

The system was developed using Ada, AWS (Ada Web Server) with a little of PHP and Perl. The system deploys a MySQL database running on Linux. The system is hooked up to air-borne SAR (Synthetic Aperture Radar) for real-time acquisition of landscaping information in snow hazard affected area to help assessing the damage of rail ways, roads, housing and forest. The Chinese army engineering company was dispatched by the system to areas in need of assistance.

I have yet to receive further details of how the system works and probably will not. Anyway, that shows the Chinese ability and responsiveness in dealing with natural disaster. Hail China!

Talking to a wall

March 8th, 2008 at 1:53 · Filed Under Ada, At Work, Blogging, Conferences, Software Development · Comment 

I had two talks about Ada at MMU (February 25) and UTAR (March 5). Among the local universities I had given talk about Ada, UTAR was the only university where I had given more than 5 talks over the years. According to my previous experience at UTAR, the response from the students were quite good.

On March 5, the talk at UTAR was the worst as if I was talking to walls or stone sculptures. The students were acting very rude by ignoring my talk. They were doing their assignment at the computers instead of listening to my talk. The talk was rescheduled to another venue which was in a computer lab. Nonetheless, I wrapped up the talk quickly. I skipped many parts to take it to the end and at the end of the talk, no one had asked any questions. I asked them some questions instead and of course, they did not know to answer. Obviously, they did not pay any attention at all.

In contrary, the talk at MMU on February 25 received better responses from the students.

Next Page »