Announcement

Collapse
No announcement yet.

Array declarations

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Array declarations

    Is there any functional difference between these two array declarations? If NOT is there any benifit to using one over the other?

    Code:
    <MvASSIGNARRAY NAME = "l.all_settings:orders" VALUE = "{ l.temp_records }">
        <MvDIMENSION INDEX = "{ l.pos }">
        <MvMEMBER NAME = "shipments">
    </MvASSIGNARRAY>
    Code:
    <MvASSIGN NAME="l.all_settings:orders"
      INDEX="{ l.pos }" 
      MEMBER="shipments"  
      VALUE="{ l.temp_records }">
    Last edited by RayYates; 10-24-10, 12:34 PM.
    Ray Yates
    "If I have seen further, it is by standing on the shoulders of giants."
    --- Sir Isaac Newton

    #2
    Re: Array declarations

    Hi Ray,

    I have never seen any functional (or performance) differences other than ease of reading/writing the code. When designing complex arrays of structures, I usually prefer the first way of writing it, even though it's a pain to write.

    Best,

    Markus
    Last edited by mvmarkus; 10-25-10, 01:04 AM.
    Emerald Media, Trade & Technology USA/Germany
    Professional Miva Programming since 1998
    Home of the Emerald Objects Application Server (EOA)
    Multi-dimensional CRM, CMS & E-Commerce

    http://www.emeraldobjects.com
    http://www.sylter-seiten.com

    Comment


      #3
      Re: Array declarations

      Personally, I hate breaking the tags out. I long ago adopted a style that just builds the name inline.
      Code:
      <MvASSIGN NAME="{'l.all_settings:orders[' $ l.pos $ ']:shipments'}" VALUE="{ l.temp_records }">
      It may seem a bit cryptic at first, but I find it a lot easier to read, and a lot easier to rearrange my structure when needed.

      I did some benchmarking years ago, and there were some differences, but I don't recall which method was the fastest. Whatever the differences were, they didn't change my coding practices.
      Last edited by aGorilla; 10-25-10, 11:05 AM.
      Bill Guindon
      [email protected]

      Comment


        #4
        Re: Array declarations

        I also use the inline style of assignment in some cases. It's shorter than using a lot of tag and attribute names. Also, you can use it to reach deep into a structure, e.g. to change the value of something with a name like
        Code:
        l.items[l.i]:options[l.j]:price
        .
        Last edited by Kent Multer; 10-25-10, 11:31 AM.
        Kent Multer
        Magic Metal Productions
        http://TheMagicM.com
        * Web developer/designer
        * E-commerce and Miva
        * Author, The Official Miva Web Scripting Book -- available on-line:
        http://www.amazon.com/exec/obidos/IS...icmetalproducA

        Comment


          #5
          Re: Array declarations

          Thanks for the response gents. It's as I suspected.

          I too use the MvASSIGN syntax, often in combination with MvREFERENCE

          For a complex structure like this

          Code:
          l.products[l.prod_index]:attributes[l.attr_index]:options[l.opt_index]
          You could use this
          Code:
          <MvREFERENCE NAME = "l.option" VARIABLE = "{ 
            'l.products[' $ l.prod_index $ 
            ']:attributes[' $ l.attr_index $ 
            ']:options[' $ l.opt_index $ ']' }">
          
          <MvASSIGN NAME="l.option:code" VALUE="{ g.code }">
          <MvASSIGN NAME="l.option:prompt" VALUE="{ g.prompt}"> etc.
          Last edited by RayYates; 10-25-10, 01:06 PM.
          Ray Yates
          "If I have seen further, it is by standing on the shoulders of giants."
          --- Sir Isaac Newton

          Comment


            #6
            Re: Array declarations

            Originally posted by RayYates View Post
            Thanks for the response gents. It's as I suspected.

            I too use the MvASSIGN syntax, often in combination with MvREFERENCE

            For a complex structure like this

            Code:
            l.products[l.prod_index]:attributes[l.attr_index]:options[l.opt_index]
            You could use this
            Code:
            <MvREFERENCE NAME = "l.option" VARIABLE = "{ 
              'l.products[' $ l.prod_index $ 
              ']:attributes[' $ l.attr_index $ 
              ']:options[' $ l.opt_index $ ']' }">
            
            <MvASSIGN NAME="l.option:code" VALUE="{ g.code }">
            <MvASSIGN NAME="l.option:prompt" VALUE="{ g.prompt}"> etc.
            Hi Ray,

            That's exactly what I try to do as often as possible. When dealing with large arrays, this can really bring a significant performance advantage en lieu of assigning the structure to another variable (just to make it easier to read).
            Emerald Media, Trade & Technology USA/Germany
            Professional Miva Programming since 1998
            Home of the Emerald Objects Application Server (EOA)
            Multi-dimensional CRM, CMS & E-Commerce

            http://www.emeraldobjects.com
            http://www.sylter-seiten.com

            Comment


              #7
              Re: Array declarations

              Yeah, MvREFERENCE is very handy.

              Another good tip to enhance performance is to use VAR on function parameters, even when you don't need it, if the parameter will have a lot of data in it. Using VAR means that Empresa won't copy the whole thing into a local variable every time it calls the function.
              Kent Multer
              Magic Metal Productions
              http://TheMagicM.com
              * Web developer/designer
              * E-commerce and Miva
              * Author, The Official Miva Web Scripting Book -- available on-line:
              http://www.amazon.com/exec/obidos/IS...icmetalproducA

              Comment


                #8
                Re: Array declarations

                That's a very good point.
                Ray Yates
                "If I have seen further, it is by standing on the shoulders of giants."
                --- Sir Isaac Newton

                Comment


                  #9
                  Re: Array declarations

                  I must have missed this release note:

                  What exactly does this tag do? <MvREFERENCEARRAY>

                  Code:
                  <MvWHILE EXPR = "{ l.attribute_pos LE l.attribute_count }">
                          <MvREFERENCEARRAY NAME = "l.attribute" VARIABLE = "l.attributes">
                              <MvDIMENSION INDEX = "{ l.attribute_pos }">
                          </MvREFERENCEARRAY>
                  Ray Yates
                  "If I have seen further, it is by standing on the shoulders of giants."
                  --- Sir Isaac Newton

                  Comment


                    #10
                    Re: Array declarations

                    Originally posted by RayYates View Post
                    I must have missed this release note:

                    What exactly does this tag do? <MvREFERENCEARRAY>

                    Code:
                    <MvWHILE EXPR = "{ l.attribute_pos LE l.attribute_count }">
                            <MvREFERENCEARRAY NAME = "l.attribute" VARIABLE = "l.attributes">
                                <MvDIMENSION INDEX = "{ l.attribute_pos }">
                            </MvREFERENCEARRAY>
                    Wow! I have never seen this before (in the "docs" ). Where did you find it?

                    I guess it's the array/structure version of MvREFERENCE. Very good to know.

                    MvREFERENCE basically creates a pointer to a variable. The advantage is that very little memory is needed and the original var is updated when you update the referenced variable (unlike a regular MvASSIGN).

                    MvREFERENCEARRAY makes the syntax easier, since sometimes assigning variables inline to a referenced array becomes quite tedious and error-prone (at least for me...).
                    Emerald Media, Trade & Technology USA/Germany
                    Professional Miva Programming since 1998
                    Home of the Emerald Objects Application Server (EOA)
                    Multi-dimensional CRM, CMS & E-Commerce

                    http://www.emeraldobjects.com
                    http://www.sylter-seiten.com

                    Comment


                      #11
                      Re: Array declarations

                      I found it referenced first in Miva Merchant * Empresa 5.07 - Release Notes.txt

                      Then found more by searching the LSK source files.

                      I have all the release notes except those from 5.03 through 5.06. (Please send them if you have them to ray.yates AT pcinet.com)

                      I recently (just last week) had to parse an flat inventory file to create this structure for an XML data feed.

                      Code:
                      l.all_settings:products[x]:code
                      l.all_settings:products[x]:name... etc.
                      l.all_settings:products[x]:colors[y]:code
                      l.all_settings:products[x]:colors[y]:name
                      l.all_settings:products[x]:colors[y]:sizes[z]:code
                      l.all_settings:products[x]:colors[y]:sizes[z]:name
                      l.all_settings:products[x]:colors[y]:sizes[z]:quantity
                      Inside the While loop I used MvREFERENCE to create a reference to each sub structure.

                      Code:
                      <MvASSIGN NAME="l.products" INDEX="{ l.data_ndx }" MEMBER="code"  VALUE="{ l.this_code }">
                      ... more assignments ...
                      
                      Later...
                      
                      <MvREFERENCE NAME = "l.colors" VARIABLE = "{ 'l.products[' $ l.product_ndx $ ']:colors' }">
                      <MvASSIGN NAME="l.colors" INDEX="{ l.color_ndx }" MEMBER="code"  VALUE="{ l.this_color }">
                      ... more assignments ...
                      
                      <MvREFERENCE NAME = "l.sizes" VARIABLE = "{ 'l.colors[' $ l.color_ndx $ ']:sizes' }">
                      <MvASSIGN NAME="l.sizes" INDEX="{ l.size_ndx }" MEMBER="code"  VALUE="{ l.this_size }">
                      I'm thinking I could have used something like this, if I had know about it, but I don't think I have it exactly right.

                      Code:
                      <MvREFERENCEARRAY NAME = "l.colors" VARIABLE = "l.products">
                         <MvDIMENSION INDEX = "{ l.product_ndx }">
                         <MvMEMBER NAME= "colors">
                      </MvREFERENCEARRAY>
                      
                      <MvASSIGN NAME="l.colors" INDEX="{ l.color_ndx }" MEMBER="code"  VALUE="{ l.this_color }">
                      Last edited by RayYates; 11-01-10, 07:11 AM. Reason: More information
                      Ray Yates
                      "If I have seen further, it is by standing on the shoulders of giants."
                      --- Sir Isaac Newton

                      Comment


                        #12
                        Re: Array declarations

                        Originally posted by RayYates View Post

                        [code]<MvREFERENCEARRAY NAME = "l.colors" VARIABLE = "l.products">
                        <MvDIMENSION INDEX = "{ l.product_ndx }">
                        <MvMEMBER NAME= "colors">
                        </MvREFERENCEARRAY>
                        Hi Ray,

                        I just tried the MvREFERENCEARRAY and it works indeed. Great find!

                        Interesting little twist with MvREFERENCE:
                        By mistake I MvREFERENCEARRAY (l.colors) to another reference with the same name: And guess what. Empresa caused a timeout!

                        Code:
                        <MvASSIGN NAME = "l.this" VALUE = "LALALALALA" >
                        
                        <MvREFERENCEARRAY NAME = "l.colors" VARIABLE = "l.this">
                           <MvDIMENSION INDEX = "1">
                           <MvMEMBER NAME= "colors">
                        </MvREFERENCEARRAY>
                        
                        <BR>COLORS: <MvEVAL EXPR = "{ l.colors[1]:colors }" >
                        
                        <MvREFERENCEARRAY NAME = "l.colors" VARIABLE = "l.colors">
                           <MvDIMENSION INDEX = "2">
                           <MvMEMBER NAME= "colors2">
                        </MvREFERENCEARRAY>
                        
                        
                        <BR>COLORS: <MvEVAL EXPR = "{ miva_array_serialize(l.colors) }" >
                        -> Empresa timeout.

                        This here works just fine:

                        Code:
                        <MvASSIGN NAME = "l.this" VALUE = "LALALALALA" >
                        
                        <MvREFERENCEARRAY NAME = "l.colors" VARIABLE = "l.this">
                           <MvDIMENSION INDEX = "1">
                           <MvMEMBER NAME= "colors">
                        </MvREFERENCEARRAY>
                        
                        <BR>COLORS: <MvEVAL EXPR = "{ l.colors[1]:colors }" >
                        
                        <MvREFERENCEARRAY NAME = "l.colors2" VARIABLE = "l.colors">
                           <MvDIMENSION INDEX = "2">
                           <MvMEMBER NAME= "colors2">
                        </MvREFERENCEARRAY>
                        
                        
                        <BR>COLORS: <MvEVAL EXPR = "{ miva_array_serialize(l.colors2) }" >
                        RESULT:

                        COLORS: LALALALALA
                        COLORS: [2]:COLORS2[1]:COLORS=LALALALALA



                        Markus



                        Markus
                        Emerald Media, Trade & Technology USA/Germany
                        Professional Miva Programming since 1998
                        Home of the Emerald Objects Application Server (EOA)
                        Multi-dimensional CRM, CMS & E-Commerce

                        http://www.emeraldobjects.com
                        http://www.sylter-seiten.com

                        Comment


                          #13
                          Re: Array declarations

                          You should post the bug. http://bugzilla.mivamerchant.com/
                          Ray Yates
                          "If I have seen further, it is by standing on the shoulders of giants."
                          --- Sir Isaac Newton

                          Comment


                            #14
                            Re: Array declarations

                            FYI, MvREFERENCEARRAY, like MvASSIGNARRAY, is not needed. I often use statements like these when operating on items in the basket:

                            Code:
                            <MvREFERENCE NAME="l.item" VARIABLE="{ 'l.items[' $ l.i $ ']' }">
                            <MvREFERENCE name="l.option" VARIABLE="{ 'l.items[' $ l.i $ ']:options[' $ l.o $ ']' }">
                            I haven't had any timeout problems.
                            Kent Multer
                            Magic Metal Productions
                            http://TheMagicM.com
                            * Web developer/designer
                            * E-commerce and Miva
                            * Author, The Official Miva Web Scripting Book -- available on-line:
                            http://www.amazon.com/exec/obidos/IS...icmetalproducA

                            Comment


                              #15
                              Re: Array declarations

                              Most likely, what happened is that you made a circular variable reference (child pointed to something in its parent), which caused miva_array_serialize to enter an infinite loop.

                              This isn't necessarily a bug in MvREFERENCE/MvREFERENCEARRAY, because there are cases where you may want to create such a circular reference. We do this ourselves in the upgrade code.

                              It's also not really a bug in miva_array_serialize(), because no matter what it does it could never generate a serialized string that reconstructs into the original variable. About the best thing it could do is detect a loop and terminate with an error or truncated output.
                              Last edited by burch; 11-01-10, 01:05 PM.

                              Comment

                              Working...
                              X