Objectively Boolean

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

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.

Comments

2 Responses to “Objectively Boolean”

  • dragon on February 11th, 2009 10:25 1

    That’s a great piece!

    Native Cocoa is certainly having better GUI than X11. Have you done any Obj-C to Ada interfacing? Would like to read on this topic.

    dragon

  • Adrian Hoe on February 12th, 2009 16:03 2

    On the way. Can’t wait for the first iPhone app and a Cocoa-Ada app. Too many things to do right now.

    While Gtk/GtkAda allows me to develop GUI applications on Mac with X11, Cocoa is certainly the best GUI on the earth right now. It is exciting to see my app running in native Cocoa.

Leave a Reply