top | item 3912336

(no title)

burgerbrain | 14 years ago

> "I saw people were using them to hold parsing directives"

What could possibly make somebody want to do that? Are there any examples around of people doing that?

discuss

order

tolmasky|14 years ago

You can imagine something like this:

    {
       /* if IE */
       browser: "IE"
       /* else */
       browser: "standard"
       /* endif */
    }
Pretty terrible and still possible (but admittedly harder) without comments.

greghinch|14 years ago

If you are storing this kind of implementation logic in your data, I hope I never have to work with you (not aimed at parent posting, but rather the global "you"

famousactress|14 years ago

It's not hard to imagine if you sorta hold your breath and let yourself get a little dizzy and think hard about XML you've had the pleasure of messing with.

I quickly get visions of version numbers, customized namespace declarations, typedefs, strftime date format strings...

kuahyeow|14 years ago

or say Javadoc @ directives....sigh

wmil|14 years ago

The CDDB/FreeDB format requires you to parse comments... http://www.jwz.org/doc/cddb.html

And people do all kinds of nonsense with HTML comments. A very bad idea is often the fastest to implement.

Yarnage|14 years ago

I completely believe him. Even though XML is really verbose I saw quite a few folks adding these types of things in XML comments.

So this wouldn't surprise me one bit. Would be interesting to see some real-world examples though.

mcav|14 years ago

And so instead, people embed parsing directives in the JSON itself.

jerf|14 years ago

Yes, but that works. Taking in such JSON and then immediately spewing it back out doesn't change the underlying meaning. Transforms from such JSON to some other format (perhaps even another JSON format) must explicitly choose what to do with "comments", instead of accidentally just discarding them. Given that parsing directives are going to exist somewhere, this is the correct place for them.

(Better yet is to create an explicit place for metadata. I almost reflexively use {"metadata": null, "payload": ...} now instead of putting my payload right at the top level, because wouldn't you know it, sooner or later some metadata always seems to wander in. And if it doesn't... shrug. If you're in a place where you can afford JSON in the first place the extra cost is probably way below the noise threshold for you.)

frobozz|14 years ago

Here's an example of using javascript comments to set options on a parser. It isn't JSON, but it is pertinent.

/* jslint nomen: true, debug: true, evil: false, vars: true */

endgame|14 years ago

Weren't pascal comments delimited by `{` and `}`, and weren't borland pascal compiler directives of the form `{$X}`?

kabdib|14 years ago

Yes, this was pretty common in Pascal.

Also, Emacs uses comments to set file-local options. There's a long tradition of overloading comments to achieve metalinguistic ends. JavaDoc and Doxygen are great examples.

Even when handed a decent macro language with whizzy namespaces and a great DOM, I imagine that some people will still stoop to gross and convenient hacks.

mikeash|14 years ago

Not JSON, but here's a truly horrible example of Internet Explorer using specially formed comments to take different actions: http://www.quirksmode.org/css/condcom.html

devicenull|14 years ago

They really aren't that bad, definitely very handy for injecting IE specific stylesheets, without having to rely on javascript.