What could possibly make somebody want to do that? Are there any examples around of people doing that?
What could possibly make somebody want to do that? Are there any examples around of people doing that?
{
/* if IE */
browser: "IE"
/* else */
browser: "standard"
/* endif */
}
Pretty terrible and still possible (but admittedly harder) without comments.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.
1. Internet Explorer has conditional comments - 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
I quickly get visions of version numbers, customized namespace declarations, typedefs, strftime date format strings...
And people do all kinds of nonsense with HTML comments. A very bad idea is often the fastest to implement.
So this wouldn't surprise me one bit. Would be interesting to see some real-world examples though.
(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.)
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."
If you've stored comments as regular data, you haven't lost them but you've just transformed them in the output.
TANSTAAFL.
I'd submit that an incomplete understanding of the source data is not necessarily a problem. It's often a design goal. Generic tools have a limited understanding of the source data by design. I don't want my JSON parser/formatter/minifier/etc. to know about some silly parsing rules you added as comments. I want my JSON parser to understand JSON as it's defined.
Your nonstandard comment directives are the problem, not the fact that I didn't write a custom tool.
/* jslint nomen: true, debug: true, evil: false, vars: true */
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.
https://developers.google.com/closure/compiler/docs/js-for-c...