Sunday, May 8, 2011

Eliminating Type Clutter in RealBasic

RealBasic is a great no-nonsense platform for writing personal software that can run with very minor modifications on Windows, Mac OSX and Linux. Its coding language is very close to the Basic in Microsoft's Visual Basic and different from Javascript or C in that each command cannot extend multiple lines.

So, for example, what in Actionscript 3 can be written as:

var a:Number = aClass.myFunction(myVariable1,
myVariable2);


in RealBasic has to be written as:

Dim a As Double = AClass.MyFunction(MyVariable1,MyVariable2)

A problem is that if the line becomes too long, it will extend beyond the width of the editor and be harder to read. Many times this occurs because you have to add CType tags to avoid compilation warnings. For example, if MyFunction accepts only Single type variables and MyVariable1 and MyVariable2 are Double type variables, your line will look like:

Dim a As Double = AClass.MyFunction(CType(MyVariable1,Single),CType(MyVariable2,Single))

which makes the code slightly less readable.

Hence, a solution is to modify AClass adding an intermediate function that accepts Double variables and then calls the original function.