7 points · by jacquesm · 17y ago · 15 comments
I'm busy building a small social network, it will have an API as its main component, in fact most of the site itself will be built using the API.
If you have experience with both these techniques which do you think is the best way to go.
Eventually the API will be made public, power users will be able to write plug-ins for the site in javascript using a 'development' field in their profiles, these will be loaded after the 'default' code for the site loads and should enable the developers to modify the way the site works as much as possible.
Once a user has tested a plug in on their own account and has verified that it works properly they can submit it for general availability after an inspection to make sure that they are not doing anything nasty.
The resulting plug-in is then 'versioned' (cloned and given unique id) and made available to other users.
All the code will be served up by our server, so unlike facebook or other heavyweight APIs there will be no external servers involved (for now at least, who knows where this will lead...).
Has something like this been done already ?
Thanks for any and all information :)
That in mind I'd say both. If for some reason you insist on choosing I'd probably say JSON. XML's only real advantage over JSON, imho, is it's human readability. That makes it great for stuff like configuration files. But for machine to machine communication JSON is faster and less prone to conversion errors. Plus it's easier to accept JSON in Javascript which you defined as your target audience.
The server side code for the project is going to be in PHP.
Think of it as HN on steroids, custom filtering and alternative user interfaces, tweaks and so on by adding chunks of javascript to the site, either just for yourself or if you think your stuff deserves a greater audience as a switchable plug in for others. If something is very well thought out we might make it default to 'on'.
Greasemonkey allows you to do some of this for a single user, but you normally wouldn't have access to the 'raw' data that builds up a site, in this case you would, all the rendering comes from the javascript. Another part of the configurables is custom stylesheets.
The general idea is that you can completely overhaul the front end of the site from a plug-in on the assumption that more than one person will want to make those changes we make those changes available to the rest of the users.
I got the idea a while ago while browsing HN, it's one of the things that made me wonder how far you can push customization of a website and my conclusion is very far if you are willing to give up control.
So the only criteria I would attach to public distribution of an extension would be that the extension is not malicious in intent. Beyond that it is 'anything goes'.
A 'hackable' social network. Very simple in basis but extremely extensible.
You're obviously being sarcastic here.
While there may be cases where this is true, I've never encountered any and I find this difficult to believe without some specific examples.
Nothing beats YAML for configuration files.
For everything else, use JSON.
Your plugin system sounds a bit like AppEngine.
But sending markup along would make the whole thing considerably easy to implement, I think (but this could be just a wrong gut feeling, I'll have to figure that one out).
In practice I have noticed that where I work we tend to have complex data structures but not very deeply nested ones. We wrote a simple find function that recursively traverses the JSON structure looking for keys. Not anything nearly as powerful as XPath but sufficient.
It tends to be highly useful in my experience to create a list of objects. For example instead of a list of phone numbers a list of phone number objects. One may then easily add attributes to the phone number. Primary, cell phone, home phone etc. This tends to be highly flexible in that attributes may be later added that were not at all considered up front.
Of course all of this can be done with xml as well. JSON just seems more convenient. If I add an attribute in Javascript or Python I can just use it and get on with it. No messing with my SaxParser or building up some new XPath. Again I am not bashing xml at all, this is just my take.
In practice we use JSON exclusively in the core services for input and output. When we need to use xml we convert it to JSON and then back to XML as a filtering process rather than fool around with our core services. This adds overhead but keeps us flexible and loosely coupled.
It makes for a significantly smaller payload (especially important in that in most cases, you're transmitting a great number of smaller chunks) and I don't buy the readability argument — especially when it's almost a no-brainer to employ a function to display to "pretty" indent JSON represenstation — print_r in PHP, pp in ruby, etc.…)
I believe just about every language used in web development includes a library for shuffling JSON in and out of native data structures.
Another rule of thumb is that the deeper the nesting of complex data structures, the easier XML will be to manipulte. With XPath I can quickly get a list of all the foo/bar/baz where haha=true, whereas with JSON I would have to have three nested loops to extract that data.
Give developers freedom to choose either of them...