Strong typing

 

A frequently requested feature in VFP has been the ability to use strong typing as provided in other languages like Java, C, C#. Well VFPCompiler now has this as an optional feature.

While in VFP the type specification was merely decorative, for Intellisense purposes, in the .NET Compiler you can optionally use strong typing, gaining so, Compile time checking and faster performance than dynamic typed. The performance improvements can be dramatic in the range of 5x-10x faster than the untyped version

The compiler recognizes as intrinsic types almost the same types that display in VFP when you type the keyword AS

byte System::Byte A byte
integer System::Int32 An integer, in 32 bits is 4 bytes wide
long System::Int64 A long integer, in 32 bits is 8 bytes wide
single System::Single An arbitrary precission single (4 bytes)
double System::Double An arbitrary precission double (4 bytes)
decimal System::Decimal Has a integer part and a fractional part. Provides extra precission. Useful for financial calculations
In addition for the integer types you can prefix the declaration with unsigned to specify an unsigned type.
date System::DateTime A date time with both Date part and Hour part.
string System::String A string (char) variable like the VFP ones
logical / boolean System::Boolean A logical value containing .T. (true) or .F. (false)
object System::Object Any type
variant System::Object any type
array System::Array An untyped array
classid System::Guid Typical GUID used in OLE

 

Return Types

To declare a strong typed return type in a method:

PROCEDURE SomeProcedure AS <type> 

Example to declare this method as returning an integer:

PROCEDURE SomeProcedure AS Integer

Parameters

To declare Strong typed parameters:

PROCEDURE SomeProcedure
TPARAMETERS aParam [as <type1>], bParam [AS <type2>]

Example to declare a method requiring two parameters one of type string and the other of type integer:

PROCEDURE SomeProcedure
TPARAMETERS tcParam AS String, tnParam AS Integer

Local variables

This syntax also applies to Local variables, they are similar in concept to the VFP LOCAL in that they are only visible in the method that declares them. But once declared with a type only assignment from compatible types can happen.

TLOCAL aVar as Integer
aVar = 5 && ok
aVar = "some string" && error because is an integer

A nice use for this optional feature is to speed your apps. You can easily reach speeds of 5-10 times (500 - 1000 percent) faster than a VFP version with dynamic typing. Don't believe us:

Run this in VFP and in a compiled app

LOCAL nValue, i

LOCAL nSeconds

nSeconds = SECONDS()

FOR m.i = 1 TO 5000000

m.nValue = m.nValue + 1

ENDFOR

? nSeconds - SECONDS()

TLOCAL nValue as long, i as long

LOCAL nSeconds

nSeconds = SECONDS()

FOR i = 1 TO 5000000

nValue = nValue +1

ENDFOR

? nSeconds - SECONDS()

This is not meant to bash VFP performance, it is a good one. But to let you know what you can achieve with the VFPCompiler which still is not optimized but already is performant..