Ask HN: File format for declarative language?
I'm in the process of developing a pure declarative language. The source consists of simple JS-like data structures that would be at home in a JSON file. I have two questions ...
- I'm naturally considering using JSON, but I don't think it is great for writing original code. It has too much visual clutter like quotes. My next thought was YAML but it seems kind of obtuse and overly-complex. Any thoughts on this would be appreciated. Am I overlooking any?
- Assuming I have a format chosen, can I use a new custom file suffix matching my language or must it be `.yml`, `.json`, etc.? One could argue that the suffix should match the syntax (`.json`) or one could argue it should match the semantics (my language). There are languages than match C syntax but don't have the `.C` suffix (if I'm not mistaken).
6 comments
[ 5.6 ms ] story [ 24.2 ms ] thread2)It can be whatever you want. It's your language. If you are reusing a current format it will be easier for devs and sysadmins to keep the current syntax
The only advantage I can think of that accrues from using the more common extension is editor support: a user's favorite editor may well provide syntax highlighting and checking, auto-indenting, etc. for `.json` or `.yml` files, but not for `.mdl` files out of the box. You might want to develop `.mdl` profiles (sic) for popular editors.
Any decent parser for the 'true' format will accept either a string or a full filename (including extension) and shouldn't expect a fixed file extension.
Regrettably I can't think of a single example right now, but I know I've encountered many programs that use custom file extensions which have turned out to be just some familiar format after all.
That said, it's another question whether either JSON or YAML is a great choice. I agree with your reservations about both. In fact I've had the very same problem in a couple of development projects, one recently. JSON is friendlier than XML, true, but it's not really a language to think in, even declaratively — too much clutter. YAML is certainly versatile enough, but it provides probably more than you need, and it is... yes, obtuse. Of course, it depends on your intended users; I found it was too "programmerly" for mine. I ended up developing a custom parser for a language with more syntactic sugar than YAML, which has its advantages and disadvantages.
But at a higher level, the new language should be designed around it's use case. If it's always used in a JavaScript context, the JSON might make more sense. If it's for *nix hackers then YAML might be better. If it's for phlembotomists then perhaps something altogether new.
Good luck.