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;
Android is a dirty phone

Android has been regarded as a savior to those who hate to be controlled and tied down by Apple’s strictly guarded iPhone. It is also one of the competitors closest to iPhone. While Apple’s latest iPhone 4 has a new feature called “FaceTime”, the Android on the other hand gets Sex.
FaceTime is a feature to make video call from iPhone 4 to iPhone 4 over Wi-Fi. No special account or screen name is required to make video calls. Therefore, users can forget about Skype and Apple’s iChat AV. Certainly, FaceTime is a great aide for people with hearing impairment and mute to communicate using sign language.
There are plenty of sex/porn apps for Android devices. There is even an adult-exclusive app store called MiKandi to cater such need. Now the store has reached a new milestone, introducing the first live adult web-cam streaming app for mobile devices called Sex Live Chat. You can read the story here. With live sex chat, you can watch the party on the other side engaged in some actions, and vice versa, if you like to. I will let your imagination run wild.
It is pathetic for a brilliant mobile platform to resort to sexual elements to promote its use. This greatly contrasts with Apple’s iDevices where you can find a wild variety of education apps along with useful business and productivity apps, etc, more than you can imagine.
As a parent, I will invest in iDevices for my kids and never an Android device. The latter is well analogized to the pest in our household.
iOS 4.0.1
Yesterday, Apple released iOS 4 update, which was one day before its press conference. The iOS 4.0.1 has obviously made the signal bar look taller. According to various media and blogs, the update is reportedly to have new software (new formula) to calculate the signal strength and to display it more accurately. Read here and here.

The above screenshot shows the signal bar on my iPhone 3GS with iOS 4. By comparing with the screenshot below, it is obvious that the signal bar (especially bar 1 and 2) has become taller.

At the same location (my desk), I covered the back of my iPhone 3GS with my palm, the signal would drop 1 to 3 bars after about 22 seconds. After updating to iOS 4.0.1, I repeated the test. The signal bar would reduce 1 bar after more than 25 seconds.
Well, this is a very low tech test and is not accountable to conclude that the new software in iOS 4.0.1 has displayed the signal strength more accurately. Anyway, there is a huge difference before and after.
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.

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.
iPhone 3.0 Software Update
A couple of weeks ago, the iPhone 3.0 software update was official launched. I connected my iPod Touch to iTunes 8.2 and clicked Update. Unfortunately, iTunes said that the update wasn’t available at iTunes Malaysia store. I wasn’t very happy with the service Apple has provided. The update was supposed to be free but it would cost me US$9.95 to upgrade my iPod Touch to iPhone 3.0.
Here’s the screenshots (click to enlarge): Read more
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.
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.
Discover your iPod touch
One of my most desired applications on iPod touch is to be able to take PDF and source code anywhere I go for discussion without taking a MacBook with me. The good thing about iPod touch is its ability to sneak into my shirt pocket or in a carrying pouch on my belt. Sometimes taking a MacBook along just for the purpose of viewing a PDF or some source code is deemed to be cumbersome. One obvious problem is that I have to carry my MacBook in the bag anywhere I go, for example, shopping. It is risky to leave the MacBook in the trunk. Many theft cases have been reported.
Discover is the best application that allows me to wirelessly transfer my files to iPod touch and view it. It is free and secured. Unlike other free applications of the same class, Discover is only limited to physical storage available on your iPod touch. It supports many file formats such as PDF, Office document formats (which I don’t use), and Unicode support (C/C++, Objective-C and more). Unfortunately, it does not recognize Ada source files. I hope BBase will support Ada in coming release.
Download Discover from iTunes store and install into iPod touch. Just launch Discover and connect (using any WebDAV enabled browser) to iPod touch with the IP address provided on the iPod screen. You can setup secured access with passwords to protect your iPod touch from unauthorized access.
iPod Touch
I received my 2nd generation iPod Touch 16GB today. I tried to make unboxing video but the result was not as good as I expected. Sorry guys. May be next time.
After I took it out from the box, I put it on screen protector film and soft silicon skin right away. I have heard and read about scratching screen, drops and oily finger marks on iPod Touch and iPhone. I think it is good to protect my investment.
I have an iPod nano which my sister gave me more than a year ago. I seldom use it but most often I use it to listen to podcasts and some music. The reason for me to acquire an iPod Touch is to explore some ideas and to develop some useful software for it.
iPod Touch is a very powerful device besides music and video playing. It is in fact a powerful PDA for many applications in my opinion.
A good head start
Happy New Year 2009 buddies!
It seems like a good head start for me. Everything I planned for today seems to be smooth sailing although I am having one problem which I do not know why it happens. I guess I will need to toy with it and/or hack it to learn why it isn’t behaving as it supposed to be. If everything is running perfect before end of this month, I will acquire an iPod Touch to proceed further. This will be my first wish on this very first day of 2009.
Finder hang in Leopard
When I returned home this evening, LA told me her applications had hung. I checked and found not only that, the Finder was not responsive too. I had no choice but to power off and to restart the Mac Mini again. This had also affected my user account. The Finder had failed to launch after login and the Dock did not appear as well. But fortunately root user account was not badly affected.
I Googled and found some articles and solutions here, here and here. I exhausted all the methods and I did not have DivXNetworks and ApplicationEnhancer.bundle in the directories mentioned in these links. I decided to go my own way.
What I did was to delete everything that was related to DivX. Since I did not have DivXNetworks, so I removed DivX folders in “/Library/Application Support” and “~/Library/Application Support” and also the DivX programs in Applications.
After the deletion, Finder still could not launch properly. I launched Console.app to examine system logs and found some errors in cache files com.apple.LaunchedServices*. I removed everything with com.apple.LaunchedServices in /Library/Caches.
Viola! Everything is back to normal again. DivX is a third party enhancement software and is not very stable. It seems like DivX has messed up with the system caches and somehow prevented Finder to launch.
I have spent two and half hours mingling with this problem. I hope my experience will save some of your time if you have the same problem as mine. I am going to take my supper.
Good luck!
Butterworth low-pass filters
I was reading about Butterworth low-pass filters since two weeks ago. Signal processing was not my favorite but this particular linear analog electronic filter had somehow captured my attention. I have interns working on some projects. One project uses Butterworth low-pass filters to process signal acquired from some sensors.
I have to verify their works using Mathematica on Mac OS X for data modeling. But there is a problem with this software. It does not have a built-in function of Butterworth low-pass filter so I need to build one.
The gain G(ω) of an n-order Butterworth low pass filter is given in terms of transfer function H(s) as:

where ωc is break frequency.
The Mathematica code with break frequency normalized at 1 rad/s:
butterworth[w1_, w2_, o_] = 1/(1 + (w1/w2)^(2*o));
LogLinearPlot[
Evaluate[Table[
10*Log[10, butterworth[w1, 1, order]], {order, 5}]], {w1, 0.01, 100},
PlotRange -> {-100, 0}, PlotPoints -> 100, ImageSize -> 400]
Export["butterworth.jpg", %]

Plot of the gain of Butterworth low-pass filters of the n-order 1 through 5.
Ada Obsession
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.


Listen to my podcast