Wiki Home

Weakly Typed

Namespace: Wiki
A Weakly Typed language (like VFP, BASIC and Smalltalk) allows a variable to change type at runtime.
uTest = "test" && now I'm a string
uTest = 123    && now I'm a number

I think a side effect of this is the ability to change the name of an object at runtime. I guess this is due to the fact that because we don't have to declare variables for the compiler, the interpreter must be able to resolve a name as it is used, so the name had to have been stored. Change what was stored, and you change the name. The last line causes "error#1925 Unknown member CMD1".
of = newobject("form")
of.newobject( "cmd1", "commandbutton" ) = "cmdx" = "cmdx"

I don't agree that this is due to weak property typing. For example you can not change the type of the Name property to numeric of.cmd1.Name = 27. VFP internally enforces the type of the properties of it's BaseClasses. The above code works because VFP does runtime containership hierarchy name resolution. The WITH/ENDWITH construct was added to the language to speed up multiple PEM access of an object. It does this compute expensive resolution only once.

Personally I can't think of too many good reasons to ever change the name of an object. It would completely break any mediation code in the container. This is also related to the fact that VFP will not let you rename a contained object of a class in a subclass or instance. This is to prevent the failure of method code in the class.

Like variables custom properties added to a class are always weakly typed, unless an Assign method is used to enforce strong typing.

define class MyClass as Custom
cMyProperty = ""

ox = createobject( "MyClass" )
ox.cMyProperty = "this is ok"
ox.cMyProperty = 123       && this is also ok

-- ?df

I see your point, and now that I think about it, you're right. VFP could still maintain variables on the fly, but not allow the type to change once a type had been assigned. -- CFK
See also: Strongly Typed
Category Computer Terms
( Topic last updated: 2004.12.22 05:36:01 AM )