• Thread:1822538#9

    I am moving the conversation here so that it doesn't derail the other thread too much if this discussion continues.

    I am aware that if you don't know which is which then you need iterate but sometimes that doesn't matter. Knowing which is which only matters if you are trying to traverse them in a certain order or access a specific one but not the others. In that case, if you happen to already have the pageid, then the keys are helpful. However, there are at least just as many ways to get the response object without knowing pageids; so you need to extract them from the object. Then if order doesn't matter, you still need to extract the keys to access the data. I guess the way I see it is that using pageids as the keys is useful in some situations but there are just as many if not more in which using an array makes more sense.

    So perhaps the API designers had a specific use case in mind and using pageids as keys makes sense for that. Okay, fine. At least that reason is better than "why not?". I would also like to point out that I said "site/program". I am green when it comes to websites but I have worked with a lot of code for scientific analysis for a while. For some reason, in that community, people still like using objects over arrays when it makes no sense at all. Perhaps that isn't the case for the web devs and I am just incorrectly transferring my knowledge about how JSONs are used in one field to a different field.

      Loading editor
    • Andrewds1021Thread:1823995
      At least that reason is better than "why not?"

      for a programmer, "why not?" includes future uses and changes: you have some data to return, you can use different types for the return value (plain obj or array) and you have to decide what type you will use. if you have suspicion that the return value will be changed (expanded, keys added, etc), then you will use most flexible type, that will allow to you to do more changes and leave consumers untouched simultaneously.

      associative arrays, objects and other key-value based collections are no-brainers in most cases: if you can use friendly names, you will use them; named lists has so much pros, that even if you don't have particular reasons to use them, eventually, somebody will find a way to enjoy them.

        Loading editor
    • A FANDOM user
        Loading editor
Give Kudos to this message
You've given this message Kudos!
See who gave Kudos to this message
Community content is available under CC-BY-SA unless otherwise noted.