On 20 October 2012 00:26, Dale Henrichs <dhenrich@vmware.com> wrote:
Ah,
So you are asking whether I think this:
{1:[1,2,3],'foo':'bar',3:{1:2,3:[1,2,3]}}
is more readable than this:
#(#Dictionary 1 #(#Array 1 2 3) 'foo' 'bar' 3 #(#Dictionary 1 2 3 #(#Array 1 2 3)))
My answer is that I find the JSON style more readable.
With JSON, I can look a sequence from the middle of the character sequence and recognize the syntactic elements:
'foo': bar', 3
as a key/value pair (foo/bar) and that 3 is probably a key ... while the following sequence is not recognizable as anything:
'foo' 'bar' 3
is it 3 elements in an array? is foo, bar or 3 a key? To get it right I have to count the key value pairs from the beginning of the dictionary, something that only a machine can do or a human presented with a small list of elements to look at.
This readability is important when looking at larger structures that may span a screen full of items in a text editor.
The {} delimiting a dictionary allows me to recognize the following sequence:
3]}
as the end of an array and a dictionary whereas the following sequence could mean anything in the literal Smalltalk array world:
3))
I can use a text editor to find the terminator for a dictionary or an array. With a smalltalk literal array it isn't possible..again the human must resort to careful counting.
I wouldn't think that I would need to point out that the #Dictionary and #Array also introduce quite a bit of visual noise... and the JSON sequence is about half as long as the literal array sequence and still quite readable...
So, yes I find the JSON format more readable than Igor's suggested format.
Frankly i do not see any difference between those two. I think, if you ask an outsider who don't knows neither JS nor Smalltalk syntax (to have unbiased opinion), i bet he will not be able to easily interpret any of them. Apart of that , is of course, being able to tell the class of object literal. Try to express that with JSON: #(IdentityDictionary 1 #(#OrderedCollection 1 2 3) 'foo' 'bar' 3 #(WeakKeyDictionary 1 2 3 #(#Set 1 2 3))) maybe you don't need that. But i think there's plenty of others who may find it very useful. I didn't wanted to turn this discussion into anti-JSON war. So sorry for that. (But you know, sometimes it is hard to stop fighting ;) So, as i already demonstrated, this format, while maybe not best for humans having clear advantages comparing to have NOTHING at all: - you can use it for expressing literals in methods (and even easily extend compiler to pre-evaluate them at compile time) - you can easily extend it to use for many different classes, without breaking anything. - and finally, it is fairly small, and simple, because of code reuse (smalltalk parser)
Dale
-- Best regards, Igor Stasenko.