PersistentMap, PersistentList etc. Should toString return JSON or the standard Collections toString format?

5 views
Skip to first unread message

Daniel Worthington-Bodart

unread,
Apr 28, 2014, 4:34:51 AM4/28/14
to utterlyidle, total...@googlegroups.com
Okay so as I said in the other thread about Model, PersistentMap and List are replacing the model class. The question is should I make the default toString return JSON?

Pros:
  • Batteries included
  • Same as Model class
  • Utterlyidle will default to rendering JSON if no renderer is specified (but no content-type would be set)
Cons:
  • Won't always produce valid JSON (If Map or List contains types not supported by JsonWriter)
  • Not reversible (Because of above won't be able to parse back)
  • Not the same as the standard collections classes which produce {x=1} instead of {"x":1}
  • Will make debugging harder as the JSON format adds a lot more quotes.

Currently I'm thinking toString should primary-illy be used for debugging and so you should be explicit if you want it to be in JSON format. 

We could still have a catch all renderer in Utterlyidle for Maps and Lists that returned JSON with the correct content tyoe.

What say ye?

Dan

Daniel Worthington-Bodart

unread,
Apr 28, 2014, 4:59:42 AM4/28/14
to utterlyidle, total...@googlegroups.com
In fact currently the toString format helps me debug the underlying datastructure which might not be that readable to users of the library!

For example an

AVLTree("C", 1, "B", 2, "A", 3).toString() 

produces 

(( A=3 ) B=2 ( C=1 ))

To show that the tree is balanced

So assuming that you guys think the JSON idea sucks, should toString show the standard format or the dan format?

Matt Savage

unread,
Apr 28, 2014, 7:38:32 AM4/28/14
to total...@googlegroups.com, utterlyidle
+1 to requiring explicit conversion to Json.

Which one is the standard format?


--
You received this message because you are subscribed to the Google Groups "totallylazy" group.
To unsubscribe from this group and stop receiving emails from it, send an email to totallylazy...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Raymond Barlow

unread,
Apr 28, 2014, 7:48:20 AM4/28/14
to total...@googlegroups.com, total...@googlegroups.com, utterlyidle
What Matt said
Reply all
Reply to author
Forward
0 new messages