6 ms·
> "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 t
by burgerbrain 14y 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?
- endgame 14y agoWeren't pascal comments delimited by `{` and `}`, and weren't borland pascal compiler directives of the form `{$X}`?
- kabdib 14y agoYes, 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.
- Yarnage 14y agoI 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.
- wmil 14y agoThe CDDB/FreeDB format requires you to parse comments... http://www.jwz.org/doc/cddb.html 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.
- mcav 14y agoAnd so instead, people embed parsing directives in the JSON itself.
- jerf 14y agoYes, 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.)
- mcav 14y agoIf you don't parse the metadata, it doesn't matter whether it's in JSON or in a comment. You lose the intended meaning either way.
- Lazare 14y agoBut the point is that if you have comments in your JSON, the first time you do some sort of "for key in data" to transform the data and spit it back out, the comments are gone; you may never even realize they were there to start with. If you do that with the metadata explicitly stored as a separate key-value pair in your blob, then this doesn't happen; the meta data is never silently discarded when you, say, take all the key value pairs in the JSON blob and send them out down the wire to a client. If you want to strip the meta-data, you have to do that. I know this isn't Python, but I think the Zen of Python is on point here: "Explicit is better than implicit."
- groovy2shoes 14y ago> But the point is that if you have comments in your JSON, the first time you do some sort of "for key in data" to transform the data and spit it back out, the comments are gone; you may never even realize they were there to start with. If you've stored comments as regular data, you haven't lost them but you've just transformed them in the output.
- famousactress 14y agoIt'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...
- mikeash 14y agoNot 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 http://www.quirksmode.org/css/condcom.html
- devicenull 14y agoThey really aren't that bad, definitely very handy for injecting IE specific stylesheets, without having to rely on javascript.
- Nagyman 14y agoThis brings to mind Closure Compiler's use of comment annotations to add type checking, etc to javascript. https://developers.google.com/closure/compiler/docs/js-for-compiler https://developers.google.com/closure/compiler/docs/js-for-c...
- pavel_lishin 14y agoSymfony2 offers it as a possibility: http://symfony.com/doc/current/book/doctrine.html#add-mapping-information http://symfony.com/doc/current/book/doctrine.html#add-mappin...
- jhaglund 14y agoYep, it made me rage a bit when I found that in a project I'm working on. Comments are for people, people!
- tolmasky 14y agoYou can imagine something like this: { /* if IE */ browser: "IE" /* else */ browser: "standard" /* endif */ } Pretty terrible and still possible (but admittedly harder) without comments.
- greghinch 14y agoIf 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"
- davedx 14y agoUnfortunately it's all too common in mobile development - mobile is the new "bad old days" of user agent sniffing hell.
- pavel_lishin 14y agoYou typically don't store this sort of thing in data, though. Then again, we have certain types of logic stored in a database table, loaded through fixtures... so my two cents may be worth much less than what they appear.
- chris_wot 14y agoHappens already. Two examples: 1. Internet Explorer has conditional comments - http://msdn.microsoft.com/en-us/library/ms537512%28v=vs.85%29.aspx http://msdn.microsoft.com/en-us/library/ms537512%28v=vs.85%2... 2. Sprockets' directive processor uses directives in comments. https://github.com/sstephenson/sprockets https://github.com/sstephenson/sprockets
- frobozz 14y agoHere'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 */
- mseebach 14y agoAs others have pointed out, this is fairly common, but no-one seem to have pointed to this one: http://en.wikipedia.org/wiki/C_preprocessor http://en.wikipedia.org/wiki/C_preprocessor