{"id":17603,"date":"2009-07-07T10:00:00","date_gmt":"2009-07-07T10:00:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/oldnewthing\/2009\/07\/07\/command-line-parsers-look-at-what-you-typed-not-what-what-you-typed-looks-like\/"},"modified":"2009-07-07T10:00:00","modified_gmt":"2009-07-07T10:00:00","slug":"command-line-parsers-look-at-what-you-typed-not-what-what-you-typed-looks-like","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20090707-00\/?p=17603","title":{"rendered":"Command line parsers look at what you typed, not what what you typed looks like"},"content":{"rendered":"<p>\nCommand line parsers are stricter than human beings.\nThe computer cares about what you typed.\nIf you type something else that superficially resembles what you want,\nbut is not actually what you want,\nthen you won&#8217;t get what you want,\neven though it sure looks like what you want.\n<\/p>\n<p>\nI covered a special case of this topic earlier when I described\nsmart quotes as\n<a HREF=\"http:\/\/blogs.msdn.com\/oldnewthing\/archive\/2009\/02\/25\/9443404.aspx\">\nthe hidden scourge of text meant for computer consumption<\/a>.\nYou think you typed a quotation mark, but the editor\nsecretly &#8220;improves&#8221; it from U+0022 to U+201C.\nThen you paste the text into a command line and you get strange\noutput because the command line parser uses U+0022 as the\nquotation mark, not characters like U+201C which physically resemble\nU+0022 but aren&#8217;t.\nA human being would say, &#8220;Yeah, that&#8217;s a quotation mark,\nwe&#8217;ll let it slide.&#8221;\nA command line parser knows what it wants and accepts no substitutes.\n<\/p>\n<p>\nEven though my original examples are for command line use,\nthe principle applies elsewhere,\nand I&#8217;m going to use CSS selectors as my example,\nbecause the command line programs used in my original examples\nare internal Microsoft tools,\nand explaining their command line syntax would distract from the message.\nOn the other hand, everybody can look up CSS selector syntax.\n(There is an opportunity for a snarky comment here, but I&#8217;m going\nto withhold the pre-emptive snarky comment in the hopes that my\nreaders are mature enough to not go for the cheap drive-by insult.\nI am almost always disappointed by the result, but I try again\nevery so often to see if the environment has changed.)\n<\/p>\n<p>\nHere is an imaginary question\/answer session inspired by\nactual events:\n<\/p>\n<blockquote CLASS=\"q\">\n<p>\n<b>From<\/b>: Xxxx Xxxxx\n<\/p>\n<p>\nHow do I make a CSS rule apply only to elements with a specific\ntag and a specific class?\nSpecifically, I want a rule to apply only to elements of the form\n<code>&lt;SPAN CLASS=\"Name\"&gt;<\/code>.\n<\/p>\n<\/blockquote>\n<blockquote CLASS=\"q\">\n<p>\n<b>From<\/b>: Yyyyy Yyyyyy\n<\/p>\n<p>\nYou use <code>SPAN.Name<\/code>.\n<\/p>\n<\/blockquote>\n<blockquote CLASS=\"q\">\n<p>\n<b>From<\/b>: Xxxx Xxxxx\n<\/p>\n<p>\nI tried that, but it doesn&#8217;t work.\n<\/p>\n<pre>\nSPAN. Name { color: red; }\n<\/pre>\n<\/blockquote>\n<p>\nThis person became one of\n<a HREF=\"http:\/\/blogs.msdn.com\/oldnewthing\/archive\/2009\/04\/16\/9551818.aspx\">\nthose people who are not interested in why something works\nbut are only interested in the magic phrase they need to type<\/a>.\nWhether or not you believe that the\n&#8220;just tell me what to type&#8221; mindset is acceptable,\nyou have to concede that if you choose to adopt that mindset,\n<i>you need to actually type what people tell you to type<\/i>.\n<\/p>\n<p>\nIn this case, the person decided that the punctuation rules for CSS\nare the same as the punctuation rules for English,\nand since English allows (and even encourages) a space after a period,\nthen CSS should also allow it.\n&#8220;I mean, it looks so much\nbetter on the screen with a space after the period.&#8221;\n(I bet these are the same people who\n<a HREF=\"http:\/\/blogs.msdn.com\/oldnewthing\/archive\/2008\/11\/13\/9064840.aspx\">\nmove cities around on a map in order to produce a more\nvisually-pleasing arrangement<\/a>.)\n<\/p>\n<p>\nOr maybe the person decided that the punctuation rules for CSS were\nthe same as C++. C++ allows spaces on either side of the field selector\noperator.\nIf C++ allows it, then so too should CSS.\n<\/p>\n<p>\nOf course, neither case is true.\nCSS has its own rules for parsing,\nand in CSS, spaces are significant.\n<\/p>\n<p>\nWhat I found even more mind-boggling was another question\/answer\nsession.\nI&#8217;m going to use the same question and answer for illustrative purposes,\nbut in reality, the question was different.\n<\/p>\n<blockquote CLASS=\"q\">\n<p>\n<b>From<\/b>: Wwww Wwwww\n<\/p>\n<p>\nHow do I make a CSS rule apply only to elements with a specific\ntag and a specific class?\nSpecifically, I want a rule to apply only to elements of the form\n<code>&lt;SPAN CLASS=\"Name\"&gt;<\/code>.\n<\/p>\n<\/blockquote>\n<blockquote CLASS=\"q\">\n<p>\n<b>From<\/b>: Yyyyy Yyyyyy\n<\/p>\n<p>\nYou use <code>SPAN.Name<\/code>.\n<\/p>\n<\/blockquote>\n<blockquote CLASS=\"q\">\n<p>\n<b>From<\/b>: Wwww Wwwww\n<\/p>\n<p>\nI tried that, but it doesn&#8217;t work.\n<\/p>\n<pre>\n.Name SPAN { color: red; }\n<\/pre>\n<\/blockquote>\n<p>\nI don&#8217;t know what possessed this second person to take the instructions\nand then <i>scramble the pieces<\/i> on the assumption that, hey,\nthe order of the pieces of the selector aren&#8217;t important, as long as\nthey&#8217;re all there, right?<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Command line parsers are stricter than human beings. The computer cares about what you typed. If you type something else that superficially resembles what you want, but is not actually what you want, then you won&#8217;t get what you want, even though it sure looks like what you want. I covered a special case of [&hellip;]<\/p>\n","protected":false},"author":1069,"featured_media":111744,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[26],"class_list":["post-17603","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-other"],"acf":[],"blog_post_summary":"<p>Command line parsers are stricter than human beings. The computer cares about what you typed. If you type something else that superficially resembles what you want, but is not actually what you want, then you won&#8217;t get what you want, even though it sure looks like what you want. I covered a special case of [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/17603","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/users\/1069"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/comments?post=17603"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/17603\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media\/111744"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media?parent=17603"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=17603"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=17603"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}