Finding Bugs in my code with And vs. AndAlso

Not trying to start a holy war over VB,C#, short-circuiting, and not short-circuiting, but I thought this was somewhat interesting.  I have some VB.NET code that uses "AndAlso".  I switched it to "And" due to some user requirements changing.  Bang I found one interesting error when I am looping through the elements of a datagrid and using the FindControl() method to get the specific control.  I had misspelled the control name.  Yeah, Yeah, I know about having a test plan and all that.  My point is that I had never thought of finding bugs as a possible reason to not short-circuit.  In this case, the problem would  have been found because the entire process would not have completed, but not quite as quickly. 

Wally

2 Comments

  • I don't understand why you'd ever need to change from AndAlso to And. What possible user-requirement changed caused such a specific implementation change? How is the code written that the right hand side HAS to be evaluated regardless of the lhs?

  • Well, the real question is, are we in business to "Find and Fix Bugs" or to "Code Solutions to Business Problems"



    My preference being the latter :-)



    So, I'd have been using the AndAlso (actually I just program in C# so &&) and I'd have seen the same problem as a "gee whiz" :-)

Comments have been disabled for this content.