But was it intuitive ??
Fri, Jun 30 2006 1:31
yesterday I asked people what does the code 2 < 1 < 5 produce.
Much to my amazement everyone seemed to get it right !! I must admit when the syntax was pointed out to me just the other day I really didn't expect to see what I saw. Admittedly, the syntax I used was low < x < high, still it wasn't until I fed it values for x above high or below low that I realized the syntax was doing other than I what I expected. Yes it was always True, regardless of the value of x.
But by my recent informal blog survey everyone got it right, so that possilby means either (1) it was intuitive, (2) people knew to expect the unexpected due to the way I asked the question (3) the sample set was too small to tell, and/or (4) frequent readers of my blog are the most intelligent coders there are so just because they could understand the code doesn't mean the average coder could ;)
So I'm thinking it's a combination of (2) , (3) and (4), and that the syntax is NOT intuitive <g>
So perhaps a follow question(s) should be:
(a) would you expect that result when you see If low < x < high Then, or would you expect that to test if x is in the range from low to high ?
(b) If you found code like this in existing VB production code would you leave it there ? If not, what would you say/do to the coder who wrote it ? If so,why would you use that syntax ?