New Data Type for Variables: 'Object' (=Associative array)

Idea created by mrwatson-gbs on Feb 21, 2016
    Active
    Score20

    Idea

     

    A new variable type 'Object' which can contain multiple properties.

     

    It would be similar to existing indexed variables, except:

     

    • it could accept number-indexes
      • $MyObject[1] = "a"
      • $MyObject[2] = "b"
      • $MyObject[3] = "c"
    • AND it could also accept text-indexes
      • $MyObject["mrw"] = 22
      • $MyObject["bev"] = 64
      • $MyObject["jbante"] = 33
    • or mixed indexes:
      • $MyObject[1] = "davidthorp"
      • $MyObject["davidthorp"] = 1
      • $MyObject[2] = "mrw"
      • $MyObject["mrw"] = 2
    • Deleting $MyObject deletes its ENTIRE contents, e.g. Set Variable[ $MyObject[*] ; "" ]
      • You can pass an object as a script parameter:
      • You can return an object as a script result
        • Exit Script[ $MyObject ]
      • You can store objects in objects in order to make multidimensional arrays:
        • $ScatterGraph[5][6]["data"] = 23
        • $ScatterGraph[5][6]["mark"] = "x"
      • or hierarchies of data:
        • $result["data"]["mainDetail"]["article"]["prices"][1]["pseudoPrice"]=23.99 // example from Shopware
      • You can create an object from JSON
        • GetJSON( "{\"MyObject\":123} ) // or similar
      • Or create JSON from the object
        • GetAsJSON( $MyObject )
      • It could also be possible to develop functions and script steps to transfer data between records and object variables - but I'll leave that for discussion and future ideas.

       

      We may need to think about slightly different syntax to distinguish it from existing variables, (see my first comment below)... unless of course it REPLACED existing variables?...hm...It needs however to be backwards compatible!

       

       

      Benefits

       

      • Such an object could solve the problem of not being able to pass multiple script parameters.
      • It too could be created directly from JSON text using the Built-in JSON Functions
      • It will make it easier to tidy up variables
      • One data structure solves many problems
      • By providing a single de-facto method of passing multiple script parameters via object structure, code  would become much more modular and  interchangeable - WITHOUT any tweaking

       

      Use Cases

       

      • Passing multiple parameters to scripts
      • Returning multiple results from scripts
      • Transferring data to/from JSON Interfaces
      • Multidimensional arrays

       

      What do you think?