Why? Normally the test expression is evaluated at runtime, and the result is compared to each case until a match is found. In my experience, the case expressions are usually constant, and they are usually unique values (in C# & C++ these behaviors are enforced). Here, the test expression is the constant, and the case expressions are calculated at runtime. And, since in the actual example there were several expressions that were returning boolean results, there were several cases that would have the same values. That is what I mean by backward. It certainly works, and maybe it just struck me as odd because my background is predominantly C++ & C#. But, the company I'm at has a large body of VB.NET code and this is the only instance I've seen of a case statement done this way. And, it is backward compared to the example in MSDN as well. It seems like if you want to evaluate a series of expressions until you find one that is true, using an if-then-elseif would be more appropriate. Just my opinion.
David St Hilaire
Posts
-
VB Select Case statement incarnation of C# if (true = [condition]) -
VB Select Case statement incarnation of C# if (true = [condition])I saw this at work. I guess the coder wanted to do a series of validations and return an error when the first failure condition was found. I don't know if you'll consider this a horror or not, but it is definitely a backwards way of doing this.
Select Case (true)
Case [failure condition 1]
Throw New Exception("Condition 1 failed.")
Case [failure condition 2]
Throw New Exception("Condition 2 failed.")
'etc...
Else
'Success!
End Select -
To me this is a coding horror, and to you? [modified]I see a lot of:
if (b1)
b2 = true;
else
b2 = false;and even some:
switch (b1)
{
case true:
b2 = true;
break;
case false:
b2 = false;
break;
} -
Oh man...Can you explain the horror? At first I thought you were getting a value from a text box and putting it right back into the text box, but after closer inspection I see that isn't the case (assuming the language is case-sensitive).
-
goto statement [moved]How about if I try to help him out with this code sample I came across from someone who was apparently trying to avoid using a goto? I don't have access to the actual function anymore, but the basic idea went:
do { //some code here if ([condition]) break; //some more code here if ([condition]) break; //this goes on for awhile.... if ([condition]) break; // ... } while (false); // clean up code
-
SetFocus.comDoes anyone know anything about the SetFocus training organization (setfocus.com)? Is it for real, and is it worth it?