4 ms·
Use whatever you like. There’s not one data format that will be perfect in all situations. While S-expressions are more explicit, they also make it more likely
by mbostock 8y ago
Use whatever you like. There’s not one data format that will be perfect in all situations. While S-expressions are more explicit, they also make it more likely that you’ll get a syntax error because of mismatched parentheses. The purpose of this format is to make syntax errors almost impossible (at the expense of possible ambiguity), to favor interactive editing as in the Treemap-o-Matic example I’ve linked.
- dreamcompiler 8y agoAgreed, if you're using a non-paren-matching text editor. I've been exclusively using paren-matching and paren-formatting editors so long I sometimes forget that non-assistive editors exist.
- kgwxd 8y agoSignificant whitespace is syntax. Errors will happen, a lot, and the parser will have no chance to catch it.
- mbostock 8y agoThe parser has well-defined behavior for malformed whitespace, and it’s not to throw a syntax error: if you advance the indentation by more than one space on a following line, the extra spaces are ignored.
- munk-a 8y agoWait so... a ..b ..c Would be interpreted as (a (b (c)))
- mbostock 8y agoThat was the initial behavior, but I’ve changed it to ignore missing intermediate parents. Your example would be (a (b c)). See the “Handling ambiguity” section I added to the notebook. The nice property of this design is that you can use whatever indentation style you prefer (tabs, 2x spaces, 1x space, etc.) and it will do what you expect as long as you are consistent.
- munk-a 8y agoOh neato. I still think there's something for the philosophy of developing tools that expect a strict format and fail if that format is violated. I've worked in a variety of settings and with a variety of tools, as time goes by I am finding the value of tools that are strict about expectations to provide a more maintainable product over the long haul. If I were writing a project using this style I'd prefer to receive a parse failure in the case of ambiguity, rather than carrying on and hoping it is correct. If data correction needs to happen (i.e. one file that should be single-space indented is triple space indented) I'd prefer to explicitly pre-process the data rather than have a tool that can handle it gracefully.
- kgwxd 8y agohow is it supposed to know you put an item at the wrong level? thats not syntax now that i think about it, just an example of how syntax can help visualize.