Web Design Service
Are you looking to create a unique website for your business? Do spend a little time to visit my company, AdaStar Informatics, website and see how we can help. We specialize in custom web design and branding-oriented content creation. We can provide services for businesses in Malaysia, Singapore, Indonesia and Hong Kong. If you’re interested to learn more about our services, you can also contact me here.
Ada and Multiple Inheritance
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
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.
Catching HTML bugs with Safari 5
A bug in a seemingly harmless HTML code had been bugging me for almost 2 weeks. I was sort of yanking my hair while trying to trace the bug which messed up the HTML page. The debugging task was even harder because I work on a HTML template with an extension .THTML. The template does not only contain standard HTML but also tags which are only recognized by AWS (Ada Web Server) . This template file is parsed by the web application (I am developing), which has AWS library, before it is dispatched as raw HTML code to a browser.
In my design, I break down the HTML template into header, body and footer so that I can reuse the common codes in header and footer. That means, all the body templates are without <html> tag. This missing <html> tag disables the syntax-coloring feature of code editor, leading to a more laborious code reading.
Before this, I had gone through every line of html source code in the template file umpteen times. This “obscure” bug, if not removed, would throw a monkey wrench in my works. I browsed the Internet and read articles in hope that I would get some clues. So, I was reading a few articles about Extensions in Safari 5. Extensions are not really impressive to me as I do not need to add missing functionalities to my browser. Safari itself is more than enough for my daily browsing activities. Somehow, my curiosity had driven me to enable the Develop menu in Safari 5. After activating it, I noticed some debugging tools in the menu. I enabled the web inspector by selecting Show Web Inspector in the Develop menu (Figure 1) then navigated to the web page I wanted to debug. To use these debugging tools, the Develop menu must first be activated. Here is a simple guide to enabling the menu.

Figure 1
Safari 5 immediately detected two error messages as shown in Figure 2. These two errors were easily corrected. After removing these unmatched </div> tags, my web page still did not show up properly with the intended layout.

Figure 2
Then I selected the Elements tab and it showed me the page source in debugging mode as shown in Figure 3. I instantly spotted the <div class=”data-base-layer”> tag which was supposed to be in the <div id=”container”> tag.

Figure 3
I clicked on the little grey triangles in the left pane to expand the <div id=”container”> tag and the <form> tag. There were two <div class=”data-base-layer”> tags (labelled as “1″ in Figure 4) and the one in label “2″ was supposed to be right after them.

Figure 4
I checked the source file again and they seemed to be in the correct place. Further investigation finally reviewed that there were two very tiny typos lurking somewhere within the second <div class=”data-base-layer”> tag as shown in Figure 5.

Figure 5
The web inspector in Safari 5 has helped me to identify errors effortlessly. If only I had such inquisitiveness two weeks ago, I would have saved so much time and efforts in debugging my HTML codes. An proverb says: “Curiosity killed the cat.” It is not always true, at least in this case. I will say: “Curiosity saved the donkey.”
Enable Develop menu in Safari 5
One of the new features for Safari 5 is the Develop mode. It allows web developers to debug HTML code on Safari. Before you can use this feature, you must enable the Develop menu first. Here’s how you can do it:
Click on Safari menu and select Preferences. In the preferences window, select the Advanced tab and then click the checkbox for Show Develop menu in menu bar.

The Develop menu will then appear in Safari menu bar. Select Show Web Inspector to inspect your HTML code. You can also activate extensions support by selecting Enable Extensions in Develop menu. Extensions let you add those missing features.

Flash of the titans
Apple’s decision for not to implement Adobe’s Flash into iPhone OS has turned Adobe-Apple relationship sour. In an open letter from Steve Job, he has written clearly about Flash’s weaknesses and a firm stance against Adobe’s Flash. I absolutely agree with Steve based on my experience with Flash. I would say: “Flash is nice to look at, but is a nightmare to have it!”
A week or two before Apple published Job’s open letter, I learned about an open source Flash project called Gnash from Twit. You can listen to the podcast here.
I really don’t believe in develop-once-deploy-everywhere development concept. I am more a native application guy because I only believe in native performance without relying on third party software components to run the applications. My experience with Tweedeck served as a wonderful example.
Tweetdeck was developed using Adobe’s AIR and Flash technology and is a develop-once-deploy-everywhere kind of application. Its user interface on the Mac really sucks. It looks more like a Windows application rather than Mac’s native Cocoa application. One thing annoyed me was that I had to upgrade Adobe’s AIR whenever it became available. I feel happier for not running Tweetdeck now.
A Java application has its downsides as well. It too depends on Sun’s JVM (Java Virtual Machine). Java has never become an implementation language in my software development career. Only recently when I began to involve in web application development, I have to work with JavaScript. The experience is awful, in my experience.
It is understood why Adobe is so furious about Apple’s decision not to allow Flash on its mobile platform. The reason is obvious: Adobe loses its grip on Apple’s mobile devices and has been discounted in Apple’s mobile computing gameplay. But Apple is not an easy-to-squeeze apple, it is huge and capable.
Apple has been working on an open web standard HTML5 and Apple’s own version of Flash, Gianduia. With HTML5, Apple’s computing platform becomes even more open, unlike otherwise as Adobe claimed. Both are exciting new technologies which I would like to implement to the web application I am developing.
I will write more about HTML5 and Gianduia when I have found time to research more about these two.
I got an iPhone
If you have followed my blog, you must be aware of how I criticized about iPhone and Apple’s aggressive strategy with mobile carriers in my article, “iPhone is in Malaysia!” I have also been going around telling customers and friends that iPhone is not as useful as it seems and is more a toy to attract young generation.
Well, I admit that I was wrong. I am developing a cloud/web-based MIS (Medical Information System) which enables patient to be able to view certain information and interact with the clinic/doctor from anywhere. Likewise, it also provides doctors greater mobility and still are able to care for their patients while they are away.
After reading articles (on Apple’s website) how iPhones help hospitals in the U.S. to provide better healthcare at lower cost, I decided to build the MIS with iPhone support. I based my decision on these reasons:
- Ease of use. I have been toying/using around with an iPod Touch for a few months and I find that it is easy to navigate/use. iPod Touch is essentially an iPhone without the phone. You get what I mean.
- Beautiful UI. Apple is well known for its brilliant UI (User Interface) in Mac OS X and iPhone OS. Nothing else comes closer to it.
- Security. All applications must be approved by Apple and be signed with license keys issued by Apple. Apple’s iTunes Store is the only place to download applications. I can be rest assured to have less (or none) headache about spooky applications from unreliable sources. Of course, there are jail broken iPhones which do not play by the rules but I am not too worried about that.
So, I went ahead ordering one last week. Last night, I went to Maxis center to collect my 32GB Black iPhone. It is such a beauty.
Give me a couple of weeks mingling with it and I promise you I will write about my experience.
Automated backup
Since August 18, my software development work has been picking up its pace and I have checked in more works more often, at least five times on single productive day. Ever since, I have been manually backing up Subversion directory using tar. My project server is fornax.
Fornax is a 6-year old PC running Ubuntu. It wasn’t working properly due to the cooling fan in its power supply unit. Until about two weeks ago, I replaced the old fan. I am not very confident about the replacement because it is a third party part and the replacement isn’t as good as expected, but it works. I have to shut it down every night before going to bed.
So, the last thing before I go to bed is to backup the svn directory and then shutdown the server. I am quite fed up with this extra manual works. Last night, before going to bed, I decided to automate this process. And I did it this morning.
I wrote a simple bash shell script to do the backup. I cron it so that the process will start automatically at 2300 hours and then shutdown.
#!/bin/bash
BACKUPFILE=/tmp/backups/svn-$(date +%Y%m%d).tar.gz
rm /tmp/backups/svn-*.gz
tar -cj /svn > $BACKUPFILE
for COMPUTER in host1 host2
do
scp $BACKUPFILE user@$COMPUTER:Desktop/
done
/sbin/shutdown -h +5
UPDATE (05/10/2009): I setup a password-less ssh login so that no password is required for scp (secured copy). Now, after the backup, the backup file will be copied automatically to two other computers for safe keeping.
Making my dad proud
Perhaps this is the most difficult post ever for me to write. A mixture of emotion makes it even harder to start and it is impossible to write this post without shedding tears and touching emotion.
Backup your Mac with AppleScript
All programmers are lazy. They want to automate tasks as much as they can. Because of this uniquely great habit, they have developed countless of useful software.
Ok. I am lazy. I have been using rsync to sync folders I am working on between my Macs. I have been using command line scripts in Terminal for almost two years and finally I have gotten lazy over the task.
The thing is, I need to execute the scripts in Terminal every time I want to synch my folders. Of course, I could simply use cron to automate the tasks at specific time but I ran the risk to cause havoc between the folders on different Macs. It is best not to cron the task.
So, I learned up AppleScript and after a ten-minute hack, I wrote a nice AppleScripts to do the job. It is quick and dirty.
set debug to false
with timeout of (30 * 60) seconds
tell application "Terminal"
set Window_Title to "Sync Documents"
set Rsync_Cmd to "rsync -acrtv --delete
/Users/username/Documents/
username@xxx:Documents"
set output_doc to do shell script Rsync_Cmd
choose from list paragraphs of output_doc with prompt
"Result:" with title Window_Title with empty
selection allowed
end tell
end timeout
Copy the script to ~/Library/Scripts/Applications/Finder and save it as “sync documents.scpt”. Then launch Script Editor to edit username to your login name and xxx to your Mac IP address or computer name. This script will sync your Documents folder under your user home directory. To execute this AppleScript, at Finder, click on the script icon on the menu bar and select the script to launch.
rsync uses ssh. If you have not setup a password-less ssh login, you will need ssh-askpass in /usr/libexec. Unfortunately, it does not ship with Mac OS X. You can get it at Joe Mocker’s weblog.
A hot Sunny affair
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.
The new WordPress
Just finished upgrading WordPress to 2.7.1 with a totally new user interface. I still prefer the one in 2.6.x so I guess I need a little time to get use to the new UI.
The upgrade is inevitable because some of my sites were affected by Yahoo! Counter malicious malware. It is a nasty injection of script. I could not locate where it was injected and my web host wasn’t very helpful. I decided to upgrade, hopefully, to wipe out the code injection.
Now, I have to file a request to Google to clear the malware listing of my sites.
Objectively Boolean
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.
归零
读了成彪登在新华网的作者文集,我对“归零”有很大的回响,也让我心中再次涌现了她的影子。读完文集,我热泪盈眶:
Nassi-Shneiderman Diagram
I came across a highly influential graphical representation method of stating algorithm while I was reading books of system analysis and design. This method is called Nassi-Shneiderman Diagram or NSD. It was developed by Isaac “Ike” Nassi and Ben Shneiderman in 1972. Isaac also helped design the Ada programming language.
Many people claimed NSD to be very easy to read and understand, especially for beginners. This is probably quite true but maintaining NSD can be a problem for system designers. Unlike flowchart, NSD lumps all the symbols into one large block and does not use connectors between the symbols.
Contrary to flowchart which uses connectors, NSD provides a better structural approach of design where Goto should be avoided in structured programming. NSD provides simplicity and a compact overview of a program that can show some relationship nicely. NSD, in particular, provides visual aid and guides thinking about nested conditional structures.
Personally, I find that NSD is useful for rapid prototyping. It is quite simple and easy to draw a conceptual design before expanding into a flowchart. Modifying a stage or symbol in NSD is rather tedious compared to flowchart. On the other hand, after a careful and thorough investigation, I find NSD most suitable for structured system analysis, design and programming. NSD was designed with structured system analysis and design in mind as mentioned in the above paragraph, it has many advantages over flowchart despite of problem maintaining it. I think it is worth to study and to use it.
Here is an example of NSD and flowchart stating an algorithm to find a summation given by the equation:
If S > 100, then display k and tell the user that k is in range.


Listen to my podcast