<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Pop Quiz</title><link>http://blogs.msdn.com/b/ericlippert/archive/2004/07/29/pop-quiz.aspx</link><description>Every non-trivial language has "gotchas". Here's one. Consider the following JScript, which creates an object and sets some fields to zero: 
 var x = { 0 : 0, 123 : 0, 1.23 : 0, blah : 0, "dude!" : 0, "-1.23" : 0 }; 
 A little weird, but it works just</description><dc:language>en-US</dc:language><generator>Telligent Evolution Platform Developer Build (Build: 5.6.50428.7875)</generator><item><title>VBScript Quiz Answers, Part Two</title><link>http://blogs.msdn.com/b/ericlippert/archive/2004/07/29/pop-quiz.aspx#380662</link><pubDate>Sat, 26 Feb 2005 01:29:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:380662</guid><dc:creator>Fabulous Adventures In Coding</dc:creator><description>&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=380662" width="1" height="1"&gt;</description></item><item><title>re: Pop Quiz</title><link>http://blogs.msdn.com/b/ericlippert/archive/2004/07/29/pop-quiz.aspx#201046</link><pubDate>Thu, 29 Jul 2004 20:27:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:201046</guid><dc:creator>Eric Lippert</dc:creator><description>Indeed.&lt;br&gt;&lt;br&gt;I'm not actually going to FIX it, mind you.  I don't own that code anymore.  Next time I see the owner, I'll mention it to him, but this is a pretty low-priority fix.&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=201046" width="1" height="1"&gt;</description></item><item><title>re: Pop Quiz</title><link>http://blogs.msdn.com/b/ericlippert/archive/2004/07/29/pop-quiz.aspx#201043</link><pubDate>Thu, 29 Jul 2004 20:24:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:201043</guid><dc:creator>Steven Bone</dc:creator><description>Eric - talk about response times...  11:43 AM Nicholas Allen reports a possible bug.  12:01 PM Eric Lippert finds the internal source code, determines the problem, adds a warning in the code, and writes a response.&lt;br&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=201043" width="1" height="1"&gt;</description></item><item><title>re: Pop Quiz</title><link>http://blogs.msdn.com/b/ericlippert/archive/2004/07/29/pop-quiz.aspx#201038</link><pubDate>Thu, 29 Jul 2004 20:21:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:201038</guid><dc:creator>Eric Lippert</dc:creator><description>Right -- James has hit the nail on the head.  There's only one place in the JScript code that converts strings to numbers, and that's the same code that is used in parseInt/parseFloat/etc, so that they remain consistent with each other.  (Though there are in fact some oddities, which might be a good subject for a future entry.)&lt;br&gt;&lt;br&gt;Your design is better -- the warning should have gone into the scanner, not into the portion of the parser which turns numeric literal tokens into expression nodes in the abstract syntax tree.&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=201038" width="1" height="1"&gt;</description></item><item><title>re: Pop Quiz</title><link>http://blogs.msdn.com/b/ericlippert/archive/2004/07/29/pop-quiz.aspx#201014</link><pubDate>Thu, 29 Jul 2004 19:49:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:201014</guid><dc:creator>Nicholas Allen</dc:creator><description>Interesting.  That is kind of weird to use a runtime function to do the conversion.&lt;br&gt;&lt;br&gt;We check for bad octals in the scanner so the warning has already gone out before anyone gets their hands on the token.&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=201014" width="1" height="1"&gt;</description></item><item><title>re: Pop Quiz</title><link>http://blogs.msdn.com/b/ericlippert/archive/2004/07/29/pop-quiz.aspx#200993</link><pubDate>Thu, 29 Jul 2004 19:19:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:200993</guid><dc:creator>James Mastros</dc:creator><description>For a while, perl had a bug whereby floating point numbers would be interpreted slightly differently depending on where they were used -- it hit very rarely, and only effected the last digit.  The problem?  Two different functions were being used, one for compile-time constants, one for arithemetic on strings holding floating-point numbers, that did the conversion ever-so-slightly differently.  Perl has a much looser compiletime/runtime dichtomy then many languages, and will happily give you warnings at runtime when it feels the need, so that's not an issue there, but the lesson is still important -- stuble differences in behavior aren't generally a good thing, when your users expect two things to work the same way, and if you implement something twice, you'll end up with subtle differences in behavior.&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=200993" width="1" height="1"&gt;</description></item><item><title>re: Pop Quiz</title><link>http://blogs.msdn.com/b/ericlippert/archive/2004/07/29/pop-quiz.aspx#200984</link><pubDate>Thu, 29 Jul 2004 19:01:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:200984</guid><dc:creator>Eric Lippert</dc:creator><description>Ah, how interesting.  That's a bug.  &lt;br&gt;&lt;br&gt;I added the warning to the code path where an octal literal is evaluated as part of a numeric expression.  Since as we've just seen, a label must not be an expression, the warning is never hit.&lt;br&gt;&lt;br&gt;In this case we're not looking to evaluate an expression as a number.  We need that thing as a canonical string.  So we need to turn it into a number, and then turn it back into a string.  For some odd reason, the routine that the compiler uses to do that is the same routine as is used at runtime by parseInt, rather than the routine used by the compiler in the main line expression evaluator.  parseInt, being a runtime function, doesn't produce compile-time warnings.&lt;br&gt;&lt;br&gt;I'm not sure why the compiler author made that choice -- I didn't write that part of the compiler.&lt;br&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=200984" width="1" height="1"&gt;</description></item><item><title>re: Pop Quiz</title><link>http://blogs.msdn.com/b/ericlippert/archive/2004/07/29/pop-quiz.aspx#200972</link><pubDate>Thu, 29 Jul 2004 18:49:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:200972</guid><dc:creator>Nicholas Allen</dc:creator><description>JScript .NET (jsc 7.10.3052 to be exact)&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=200972" width="1" height="1"&gt;</description></item><item><title>re: Pop Quiz</title><link>http://blogs.msdn.com/b/ericlippert/archive/2004/07/29/pop-quiz.aspx#200969</link><pubDate>Thu, 29 Jul 2004 18:47:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:200969</guid><dc:creator>Eric Lippert</dc:creator><description>I don't get any error for either of those.  Or are you talking about JScript .NET?&lt;br&gt;&lt;br&gt;I talked a bit about malformed octal here:&lt;br&gt;&lt;br&gt;&lt;a target="_new" href="http://blogs.msdn.com/ericlippert/archive/2003/10/23/53278.aspx"&gt;http://blogs.msdn.com/ericlippert/archive/2003/10/23/53278.aspx&lt;/a&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=200969" width="1" height="1"&gt;</description></item><item><title>re: Pop Quiz</title><link>http://blogs.msdn.com/b/ericlippert/archive/2004/07/29/pop-quiz.aspx#200964</link><pubDate>Thu, 29 Jul 2004 18:43:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:200964</guid><dc:creator>Nicholas Allen</dc:creator><description>Since we're talking about the quirks of numbers in object initializers...&lt;br&gt;&lt;br&gt;Why doesn't&lt;br&gt;&lt;br&gt;var x = { 08 : 0 };&lt;br&gt;&lt;br&gt;whine about being a malformed octal literal?&lt;br&gt;&lt;br&gt;var y = 08;&lt;br&gt;&lt;br&gt;does.&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=200964" width="1" height="1"&gt;</description></item></channel></rss>