Roku Developer Program

Developers and content creators—a complete solution for growing an audience directly.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
EnTerr
Level 11

roAssociativeArray.append() with duplicate keys [solved]

Documentation is laconic
Append(aa as Object)
Append an AssociativeArray to this one.

It is unclear what happens if the same keys are present in both dictionaries? E.g. a={k:"a"} and b={k:"b"}, after a.append(b), should that be:
a) error during update
b) a.k = "a" (a prevails)
c) a.k = "b" (b prevails)
d) behavior undefined (can change in the future)

I tested and current behavior seems to be (c), as if a loop over b has been ran, doing a.AddReplace(). Roku*, can you state if this will be the behavior to rely on and document it?

PS. method probably should have been named "update()" since this implies new values win, compare to python's

PPS. there is a bug in ".append()" in that if one passes non-roAssociativeArray argument, nothing happens (not even an error). That does not sound meaningful by design. Currently by the doc it is "Append(aa as Object)" but i can feed it number, string, bool, function... with no apparent effect. So seems to be more of "dynamic" type
0 Kudos
16 REPLIES 16\
EnTerr
Level 11

Re: roAssociativeArray.append() with duplicate keys

Bump.

Somebody from RokuCo, can you confirm this is guaranteed behavior?
It seems logical but can i rely on it.
0 Kudos
RokuJoel
Roku Employee
Roku Employee

Re: roAssociativeArray.append() with duplicate keys

Hi Enterr, I filed a bug on the last part of your posting (the lack of type checking) the day after you initially posted it.

Documentation - I can point that out to the documentation people.

- Joel
0 Kudos
EnTerr
Level 11

Re: roAssociativeArray.append() with duplicate keys

"RokuJoel" wrote:
Hi Enterr, I filed a bug on the last part of your posting (the lack of type checking) the day after you initially posted it.
Documentation - I can point that out to the documentation people.


Thanks Joel -
bump was regarding answer to my question. I guess the implication of what you are saying is that the new values are supposed to override old values for overlapping keys?

By the way, here is another one for reporting: roArray.append() acts the same way as append for roAA. For example, pop-quiz: what does this do:
a = [1,2,3]
a.append(4)
print a
a) print 1 2 3 4
b) error message

People coming from other languages (like python) will guess (a). The ones who have read the documentation and programmed only a little (like me) will expect (b). But the reality right now is
(c) none of the above, it will print 1 2 3
0 Kudos
EnTerr
Level 11

Re: roAssociativeArray.append() with duplicate keys

So what does it take to get an answer?
Am i asking too difficult of a question? Or is it my poor command of English.
0 Kudos
RokuJoel
Roku Employee
Roku Employee

Re: roAssociativeArray.append() with duplicate keys

Hi, as you noted "b" prevails. That would be the standard behavior that I don't think we would want to change. Of course, its software, so everything can change if someone decides to make it so as a matter of policy, or accidentally breaks something...

- Joel
0 Kudos
EnTerr
Level 11

Re: roAssociativeArray.append() with duplicate keys

"RokuJoel" wrote:
Hi, as you noted "b" prevails. That would be the standard behavior that I don't think we would want to change. Of course, its software, so everything can change if someone decides to make it so as a matter of policy, or accidentally breaks something...

Hi - appreciate an answer but since you don't seem certain, please run this by "a higher power" and get definitive answer that it will not in fact change.

It is customary to fix such details in the API and document that too. As i pointed out this is the guaranteed behavior in other languages (although there they use more fortunate name like ".update()" which just by name implies the behavior).

I will give you a reason so my question does not seem capricious: i intend to use this for (home-grown, class-less) object inheritance, so that new methods override parent's existing methods.
0 Kudos
TheEndless
Level 10

Re: roAssociativeArray.append() with duplicate keys

"EnTerr" wrote:
I will give you a reason so my question does not seem capricious: i intend to use this for (home-grown, class-less) object inheritance, so that new methods override parent's existing methods.

I'm already using it like this as a fundamental feature of my framework, so I'm counting on it not changing! Looping through the keys individually is significantly slower (which, incidentally, can have a huge impact on the framerate of 2D API implementations).
My Channels: http://roku.permanence.com - Twitter: @TheEndlessDev
Instant Watch Browser (NetflixIWB), Aquarium Screensaver (AQUARIUM), Clever Clocks Screensaver (CLEVERCLOCKS), iTunes Podcasts (ITPC), My Channels (MYCHANNELS)
0 Kudos
RokuJoel
Roku Employee
Roku Employee

Re: roAssociativeArray.append() with duplicate keys

There will never be a definitive answer that something will not change. Anything that is likely to break channels, the way changing this would break channels, is unlikely to change, but that doesn't mean it won't change if there is a pressing reason to do so.

- Joel
0 Kudos
EnTerr
Level 11

[Solved!] roAssociativeArray.append() with duplicate keys

I notice that documentation has been updated to say
"ifAssociativeArray.Append(aa as Object)" wrote:
... If any key in aa are already associated with a value in this AssociativeArray, the current value is discarded and is replaced with the value in aa.
So it is behavior (B), the new AA overrides old AA content in case of overlapping keys. As any experienced developer would expect but now is in the RTFM and can be relied upon.

My gratitude goes to the forum's patron saint, RokuMarkn - thank you!
0 Kudos