I created this thread because I wanted to discuss a main concern of mine:
what should happen when getting the TYPEOF a generic field? As the structs evolved I figured I wanted to include generic fields---fields which can contain any datatype (int, float, or string.) The inspiration came from Java; unlike Java, however, the types don't need to be defined at declaration time and it isn't a compiler feature. The nature of these structs allows these fields to maintain any data type at any given time. To provide an example:
@STRUCT_GENERIC
DATA "GENERIC","FIELD"
DATA "END"
This declares a struct type GENERIC with a generic-type field named FIELD. When this struct is instanced, you don't need to provide a type; the standard procedure for declaration holds true. At first, the field simply has no type defined besides "generic.' Let's say you set it to an int, for example:
'here STRC contains a GENERIC struct
SET STRC,"FIELD",1
The field will now contain information stating that it's generic, but also keeps a data type of int inside. If we tried to set the field to a string it would work. The type of the generic field just depends on what data type it's storing. It can store any type at any time.
Since we have information that the field is both generic and what data type it holds, what is returned when we do
TYPEOF(STRC,"FIELD")? I wanted to ask what you guys would find useful.
- Return just the type of the data inside the field.
- Return just "GENERIC".
- Return some mixture of both.
The issue with the first option is that it doesn't tell the programmer that it's a generic field. It also won't have anything to return if the field hasn't been set yet. The second option tells the programmer that it's generic, but doesn't tell what type the data it holds is. This is the less useful option, because knowing the type of a generic field lets the programmer anticipate its contents. This doesn't provide that. The third option seems like the best of both worlds, but what format will the return be?
TYPEOF returns the typename as a string, so if you can come up with a good format that's also easy to use I would be glad to hear it.
Another issue is that a generic field contains *nothing* until it's set. If you try to read it there will be nothing there. With the other types it contains the default value. This is less of a problem because I can just make it an error condition, but it's worthy of mentioning.