4 ms·
(young) people seem to always want to find ways to skirt the "rules" that Crockford sets up (see also, jslint). Just stop. The rules he lays out are there to ma
by greghinch 14y ago
(young) people seem to always want to find ways to skirt the "rules" that Crockford sets up (see also, jslint). Just stop. The rules he lays out are there to make your _long term_ programing life easier. Yes you may have to remember to use semicolons and quote things, but when you have to live with an application you've been working on for years, hopefully you'll learn to appreciate the fact that putting in a little extra time now saves you tons of headaches down the road.
- aseemk 14y agoI'm actually a big fan of Douglas Crockford. And don't worry, my code uses semicolons. ;) I'm not sure why you lump quoting keys with semicolons, though; his regular JS style guide doesn't discourage quoting object key (neither does JSLint).
- ZenPsycho 14y agothere's a reason he requires it for JSON. it's that javascript has problems when you use a javascript reserved word as a key- for instance, if you were making an RPC api, and you had a json object {do:"methodname"} the javascript eval method would throw a fit. So rather than include the full list of javascript reserved words in a spec intended to be language agnostic, he just made quoting the key a requirement, which makes things vastly simpler.
- aseemk 14y agoThis was indeed a problem in the IE6 days. Every browser today (and ES5) supports reserved keywords as unquoted object keys. There are thus no reserved keywords for object keys in ES5, and by extension, JSON5.
- ZenPsycho 14y agoNo, but there ARE a ton of JSON parsers that expect and require quoted keys now. So it is, in fact, still a requirement. And I don't know about you, you may be lucky, but I still have to make my stuff work on IE6.
- DavidAbrams 14y agoIt's too bad, though, because all the extra quotes bloat what is otherwise a nice, spare format.
- ZenPsycho 14y agoIt has exactly the opposite effect on the notation's grammar.
- tomjen3 14y agoWhen was Crockford elected to set the rules for programmers and why wasn't I given a vote? Oh, he was never elected? Why the fuck should I care about what one man thinks then?
- mryan 14y agoYou should try relaxing a bit more, this seems like an incredibly silly thing to get worked up about. There are plenty of legitimate things in the world to get angry about - object serialisers are not one of them. IMHO, aggressive comments that contain nothing but sarcasm are not welcome here. Let's try and keep the place a bit friendly (or at least grown-up and professional), even if we disagree. If you are going to be sarcastic, at least have the decency to make an interesting point at the same time. > When was Crockford elected to set the rules for programmers and why wasn't I given a vote? Crockford was obviously not "elected" in any official sense. However, he produced something that the programming language needed, and it very quickly became a standard. Have you ever used JSON in a project? Then you implicitly voted for JSON and, by extension, Crockford. > Oh, he was never elected? Why the fuck should I care about what one man thinks then? Because the rest of the industry has decided that JSON's benefits outweigh its downsides, and using it is a net positive. JSON is not perfect, but it solves an annoying problem rather elegantly.
- greghinch 14y agoWell if you use JSON, you did vote, because he created the spec. If you've never read his book or watched any of his talks, maybe you should check them out. He never says "this is how you have to do it". He says something to the effect of 1) JavaScript is a flawed language. 2) DC has used/helped develop it for a long time 3) he has figured out a lot of least bad solutions and habits to try and for to mitigate common problems. If you don't want to follow his suggestions fine, but don't be surprised when you run into the problems that he created them to help you avoid.