Friday, November 24, 2006

Idea of the day

Isn't it annoying when you can't find the end of the sellotape!
Solution: Invent a type of glue that reacts with air and changes colour (slightly darker).
That way you can always find the end of the sellotape, as this will have changed colour.
Ideally, once the tape is resealed it would change back again.

Thursday, November 16, 2006

Nots and Ands

Don’t you just love programming!

If Not (AppSettings("ProxyServer").Equals("")) And (AppSettings("ProxyPort").Equals("")) Then
req.Proxy = GetProxy()
End If


The not doesn't make any difference if both values are empty strings! It should be:


If Not (AppSettings("ProxyServer").Equals("") And AppSettings("ProxyPort").Equals("")) Then
req.Proxy = GetProxy()
End If


Spot the difference!


I reckon there ought to be an easier way to express this concept and I'm sure that 'not/and' 'not/or' structures like this cause lots of bugs. Perhaps new operators, something like this would help:

all({list of values}) {single value to compare against}
any({list of values}) {single value to compare against}


(both returning a boolean)

So to back to the example, to only set proxy settings if both port and server settings exist, we'd have

If all(AppSettings("ProxyServer").length, AppSettings("ProxyPort").length) > 0 Then
req.Proxy = GetProxy()
End If


I'll see if can code, all and any in c#...