Str(Instance.MyType)

Archives Forums/BlitzPlus Bug Reports/Str(Instance.MyType)

_PJ_(Posted 2014) [#1]
I apologise if this is not technically a bug, but I thought it is worth mentioning just in case.

In Blitz3D It is possible to output Type object instance data as a string by using the Str() command with the actual object instance as the parameter.

i.e.

Local AnInteger%=1
Local AFloat#=0.5
Local AString$="Text"

Type MyType
Field MyField1$
Field MyField2%
Field MyField3#
End Type

Local Instance.MyType=New MyType
Instance\MyField1$=AString$
Instance\MyField2%=AnInteger%
Instance\MyField3#=AFloat#

Local OutPut$=Str(Instance.MyType)

Print OutPut$

In Blitz3D OutPut$ would be
["Text",1,0.5]


However, if this is used with Blitz+ the returned string is instead simply
[OBJECT]
Regardless of the fields.

I haven't (and am not currently able to) test what is returned in BlitzPlus when Instance=Null. Blitz3D returns
[Null]



Yasha(Posted 2014) [#2]
That looks annoying if anyone was relying on it being the same.

Note however that even in B3D this is only really useful for debugging. The printing of fields is restricted to about three levels of nesting, making this feature not particularly useful for complex compound types, and completely useless for recursive data structures like lists. It's also effectively useless for serialization, as it helpfully doesn't actually include the type of the object being printed.


Since we're trading language quirks, another interesting feature of Str is that it's an operator, not a function: this means that you can drop the parentheses and write `Str Instance`. Looks weird until you get used to it.

Since Blitz can't express overloading on functions, this actually applies to every overloaded builtin: Object, Handle, Before, Int, Sgn, ...


_PJ_(Posted 2014) [#3]
Yeah, it's not really anything of a big deal, and indeed it doesn't help a great deal (I only noticed this error due to my own debugging although it doesn't actually make much difference. Knowing it's not null at least is helpful enough!

Overall it doesn't accomplish anything that cannot be done by other means and which can be tailored to provide more useable information!


I'd not known about Str and the others being operators, but I prefer to keep in the habit of using parenthesese when expecting a return value.

It is interesting to note though!


GaryV(Posted 2014) [#4]
It does no good to post bug reports for a dead and unsupported language. The bug forums for B+ and B3D need to be permanently locked.


_PJ_(Posted 2014) [#5]
I think it is important to identify and notify such things for other users so they are aware of unexpected behaviours.
When debugging a program it may make all the difference to be aware that such occurrences are a 'fault' or otherwise some form of 'unexpected/atypical issue' with the language rather than a coding error - regardless of whether or not there is any possibility of the matter being addressed.