Well, I’ve been here for about 2 months now, living in the Camden City Center on St. Joseph’s Parkway. So far so good, I love the neighborhood . . . I can take Louis a couple blocks down the street, eat pizza, drink some beer and let him play with his many admirers. The first couple of weeks were a bit touchy, as my upstairs neighbor banged on the floor while I played Tierney Sutton (Frank Sinatra redux) a bit too loud for taste around 10:30PM on a Sunday evening . . . that banging caused a rim on fire sprinklers rim to fall off . . . near panic time as that had the potential to destroy about 8K of audio and computer equipment . . . the management straightened her out . . .And just recently my new neighbors (unregistered) dogs where howling 2 or more times per hour every day . . . seems like that’s died down a bit . . . it’s a nice place . . . I don’t really know my neighbors like I did when I lived in a house . . . so some downsides for sure . . . such is apartment life . . .
My discovery of vb.net short-circuit logic . . . Or ‘how can a C# programmer screw up the obivous?’D
After I was laid off from Omnicell, I took a job as a contractor at Hess (Thanks Guys!) doing Visual Basic and Silverlight development. I found I rather enjoyed working with vb.net, and that for some mysterious reason they had difficulty finding developers that could do the work. Some of it had to do with a misplaced conceit regarding visual basic, c# and some notion of vb.net inferiority! I found that vb.net is very expressive, and the version that runs against 4.0 CLR is every bit as good as C#. This was MS’s desire, to ensure that the vb.net language enjoyed parity with it’s C# sibling. I think they’ve done a great job with it . . . but doesn’t mean that all is hunky dory with vb.net for c# programmers – for sure! I (re-)discovered the horrors of eager vs short-circuit expression operators first hand!
My work involved working on creating new code, and rewriting much of their old database I/O code one an application that interfaced with their Documentum system. Since it had been a while since I created solutions using basic or pascal, I went my merry way believe that ‘and’ is ‘&&’ and ‘or’ is ‘||’ . . . not so! So what is also blather about short-circuit logic? Here’s an example:
if cheap_to_check() = true and expensive_to_check() = true then
end if ...
Well let’s see that should be like this in C# – right?
if(cheap_to_check() == True && expensive_to_check() == True)
(there might be a syntax error or two here . . . but you get the point!)
These two if conditional statements are NOT semantically equivalent! I was attempting to code an often used pattern that would use an inexpensive operation to determine if a more expensive operation would be executed.
I use to expect that with both of these statements, if the cheap_to_check() returned false, the conditional code would not execute no matter what. This is not the case. C#, C, C++ and other languages of that ilk exhibit by default the notion of short-circuit operator logic. Its is as if if that statement reads ‘hey lets not bother with doing that expensive operation because we already know that the cheap operation returned false . . . let’s just move on!” . . . Unfortunately with the Visual Basic Dot Net the execution of the function ‘expensive_to_check()’ will occur no matter what. Visual Basic Dot Net and it’s brethren use eager operators – all expressions are evaluated on that if statement line.
We now introduce the short-circuit and/or operators for visual basic – AndAlso and OrElse . . these are semantically equivalent operators to the C languages ‘&&’ and ‘||’. So rewriting the above expresions like this does the trick:
if cheap_to_check() = true AndAlso expensive_to_check() = true then
The same is to be the said for the Or (eager operator) and the OrElse (short circuit operator). No matter what, all expressions that are connected by an ‘or’operator will be evaluated (unless of course, an exception occurs within one of the expressions).
Well . . .that’s all for now folks . . . next time (whenever that is!) I’ll explore the deep mysteries of the VB.Net ‘Not’, ‘IsNot’, and ‘Nothing’ operators . . . its not a not like we C programmers know, and ‘IsNot Nothing’ is not just metaphysical . . . it’s the real deal!
After working with EDM from MS – specifically the 3.5 version on the Visual Studio 2008 designer, I’m impressed . . . but I did find a weird bug. The EDM engine accepted a malformed table name with high-order bit ascii character in the table name. Once it munched on this, it went bezerk causing all sorts of mischief. I correct the table name, updated the model and removed the old entity and association from the model. In its’ defense, EDM tried to tell me that there was problem – but I didn’t figure it out very quickly. The table in question was named HostIPAddress, and EDM mapped it to an Entity named ‘Host_IPAddress’. Since I edited the table through the SqlServer graphical editor, the table looked just fine to me. Once I looked at the SQL itself, it appeared that the table name was ‘Host IPAddress’ (note the space). All is well now . . .
This is my new blogging website . . . I hope to grow it by leaps and bounds . . stay tuned!