Hi,
I'd like to offer an observation and make a request for the future development of Phrogram. In the recent program I wrote (Space Junk -- see elsewhere) I wanted to create new objects dynamically. I know that there's the "New" keyword (as yet officially unsupported), but I wanted to play completely by the rules, so I used the following kind of pattern:
Function NewObject() As MyClass
Define result As MyClass
Return result
End Function
This does what I needed. However, as I've worked more with Phrogram I've realised that one of the concepts that seems to be missing is that of the "null" (or "nil", or "undefined") object. In some ways I can understand why, because if you have "null" then you'll have to handle things returning it, which adds some complication. That's why a variable definition in Phrogram (implicitly) calls a constructor to initialise the variable. But sometimes null is indispensible --- for example when you wish to indicate that a function that returns an object is returning an invalid value. The alternative is ugly -- having to add some kind of "I'm not really a valid object" member into class defintions, that then has to be explicitly set or reset.
What we need is a value that you can set variables to, and compare variables against, but which is otherwise invalid. I believe that especially when (if?) the "New" keyword is introduced, some concept of null will become essential.
Now, I have experimented a bit, and the following bit of code almost does what I need:
Program PseudoNull
Define NULL As Any
Method Main()
Define s As String = "hello"
s
= NULL
If IsNull(s) Then
PrintLine("s is null")
Else
PrintLine("s is NOT null")
End If
Define a As Integer[10]
a
= NULL
If IsNull(a) Then
PrintLine("a is null")
Else
PrintLine("a is NOT null")
End If
End Method
Function IsNull(x As any) As Boolean
Return x = NULL
End Function
End Program
This compiles OK, but when you run it you get "Runtime error at line 8: Object reference not set to an instance of an object". That's true --- and is in fact exactly what I want ... but not to complain about it!
So, what does anyone else think? Are you with me in asking for the addition of "nothingness" to the Phrogram language?
Neil