Fabulous Adventures In Coding
Eric Lippert is a principal developer on the C# compiler team. Learn more about Eric.
8) Which of these programs is syntactically legal?
Only (c) is legal, the rest are illegal. None are legal in VB6.
(a) is illegal because it is illegal to define the same procedure twice inside a class. (b) is illegal because only procedure and variable declarations are legal inside a class. (d) is illegal because you cannot put a function between the
There are three interesting facts about (d).
Second, the syntax error raised by the parser is on the
Third, bizarrely enough it
(c) is legal. Due to a mistake in the VBScript 1.0 parser, we didn't check to see if functions were inside global-code
I wanted to fix this in VBScript 2.0, but we couldn't because we discovered that many ASP page authors accidentally put function declarations inside
When I implemented classes in VBScript v5.0 of course there was no previous version of classes to be compatible with, so I tightened it down; a class may not redefine functions. And since a class scope does not allow conditional statements, the problem with functions inside conditionals goes away inside classes.
Many of these quiz corner cases illustrate an important point: get the language design and implementation right the first time, because you're stuck with it forever!
PingBack from http://websitescripts.247blogging.info/fabulous-adventures-in-coding-vbscript-quiz-answers-part-eight/