GithubHelp home page GithubHelp logo

Hash instead of array about json-api HOT 6 CLOSED

json-api avatar json-api commented on May 22, 2024
Hash instead of array

from json-api.

Comments (6)

GavinJoyce avatar GavinJoyce commented on May 22, 2024

Some context from HN : https://news.ycombinator.com/item?id=5654116

from json-api.

lukfugl avatar lukfugl commented on May 22, 2024

I understand the momentum of the existing tools for keeping it array based, so I don't expect it to change. That said, I think alexkcd made some good points in the HN thread that could also provide some assistance around the "primary document among others of the same type" problem being discussed in issue #8. So there may be more motivation for reconsidering...

from json-api.

mahmoudimus avatar mahmoudimus commented on May 22, 2024

@lukfugl - One of the main reasons that a list is used is because of order. Using a hash indicates that the response is not necessarily ordered. This is subtle, but very important.

from json-api.

paddycarver avatar paddycarver commented on May 22, 2024

Beyond order, I'd argue for performance. Array operations and hash operations have wildly differing performance characteristics. If people are interested (or think I'm wrong--I may be) I'll write and run some quick benchmarks to illustrate my point.

from json-api.

steveklabnik avatar steveklabnik commented on May 22, 2024

Ultimately, there are pros and cons to each side, and we made a choice towards arrays. There's nothing super bad about hashes, but this really boils down to a bikeshed.

from json-api.

wycats avatar wycats commented on May 22, 2024

In particular, looping over an Array is much faster than looping over an Object in JavaScript. Since a main use-case we have in mind is for a smart client to load the objects into a local store, it's easy for the loading code to index by ID, which will then produce fast lookup by ID later, but fast load initially.

from json-api.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.