Strictly Short Circuit
-
Names changed to protect the innocent... I'm working with some VB.net projects and I decided to turn on Option Strict. It threw an error for this line:
If someProp Is Nothing OrElse String.IsNullOrEmpty(someProp.Value OrElse someProp.Value = "0") Then
This is what was intended:
If someProp Is Nothing OrElse String.IsNullOrEmpty(someProp.Value) OrElse someProp.Value = "0" Then
:-D for option explicit! :(( for the fact that I have several projects to go and I'm working in the order of best code to worst code.
-
Names changed to protect the innocent... I'm working with some VB.net projects and I decided to turn on Option Strict. It threw an error for this line:
If someProp Is Nothing OrElse String.IsNullOrEmpty(someProp.Value OrElse someProp.Value = "0") Then
This is what was intended:
If someProp Is Nothing OrElse String.IsNullOrEmpty(someProp.Value) OrElse someProp.Value = "0" Then
:-D for option explicit! :(( for the fact that I have several projects to go and I'm working in the order of best code to worst code.
-
Names changed to protect the innocent... I'm working with some VB.net projects and I decided to turn on Option Strict. It threw an error for this line:
If someProp Is Nothing OrElse String.IsNullOrEmpty(someProp.Value OrElse someProp.Value = "0") Then
This is what was intended:
If someProp Is Nothing OrElse String.IsNullOrEmpty(someProp.Value) OrElse someProp.Value = "0" Then
:-D for option explicit! :(( for the fact that I have several projects to go and I'm working in the order of best code to worst code.
eh, this is a garden-variety typo bug. I wouldn't count it as a horror as it doesn't look intentional. Even so, I can feel a sympathetic headache building...thanks :~
-
eh, this is a garden-variety typo bug. I wouldn't count it as a horror as it doesn't look intentional. Even so, I can feel a sympathetic headache building...thanks :~
Yeah, the real horror is that VB.net allows that at all.
-
Yeah, the real horror is that VB.net allows that at all.
-
Allowing OrElse inside of an IsNullOrEmpty is a bad thing? On the contrary, that could be very useful.
The bad part is that the OrElse is between a string and a boolean, which is returning a boolean, which then gets passed as a parameter to String.IsNullOrEmpty.
-
The bad part is that the OrElse is between a string and a boolean, which is returning a boolean, which then gets passed as a parameter to String.IsNullOrEmpty.
-
True object-oriented programming allows it because they are all objects. It doesn't care.
Using a string as a boolean has nothing to do with object-oriented programming. If the code were directly comparing the boolean and the string, that might be considered something near valid (what with operator overloading), but that was not the case here. This code is basically like doing this:
If "Dragons" Then
' Dragons be true!
Else
' Dragons be false :-(
End IfIt doesn't make any sense.
-
Using a string as a boolean has nothing to do with object-oriented programming. If the code were directly comparing the boolean and the string, that might be considered something near valid (what with operator overloading), but that was not the case here. This code is basically like doing this:
If "Dragons" Then
' Dragons be true!
Else
' Dragons be false :-(
End IfIt doesn't make any sense.
-
The bad part is that the OrElse is between a string and a boolean, which is returning a boolean, which then gets passed as a parameter to String.IsNullOrEmpty.
AspDotNetDev wrote:
The bad part is that the OrElse is between a string and a boolean, which is returning a boolean, which then gets passed as a parameter to String.IsNullOrEmpty.
Uh, that's WHY there is an Option Strict: to allow relaxed type checking on certain operations. Though here it is certainly annoying, and one of the reasons I tend to use Option Strict pretty consistently.
-
Names changed to protect the innocent... I'm working with some VB.net projects and I decided to turn on Option Strict. It threw an error for this line:
If someProp Is Nothing OrElse String.IsNullOrEmpty(someProp.Value OrElse someProp.Value = "0") Then
This is what was intended:
If someProp Is Nothing OrElse String.IsNullOrEmpty(someProp.Value) OrElse someProp.Value = "0" Then
:-D for option explicit! :(( for the fact that I have several projects to go and I'm working in the order of best code to worst code.
Computers should be used for what they are good at: systematic consistency checks. Because this is where they can help preventing bugs early. Static analysis. If I were God, I would make the Strict mode compulsory. And enhance the programming languages to help computers help us. For instance by introducing dimensional analysis on the data.
Dim Meters as Unit
Dim Side As Integer in Meters, Area As Integer in Meters^2, Count(0 To 5) As IntegerArea = 3 * Side 'Error: Option Strict On disallows implicit conversion from Meters to Meters^2
Count(Side) = Count(Side) + 1 'Error: Option Strict On disallows using dimensional expressions as indexes -
Names changed to protect the innocent... I'm working with some VB.net projects and I decided to turn on Option Strict. It threw an error for this line:
If someProp Is Nothing OrElse String.IsNullOrEmpty(someProp.Value OrElse someProp.Value = "0") Then
This is what was intended:
If someProp Is Nothing OrElse String.IsNullOrEmpty(someProp.Value) OrElse someProp.Value = "0" Then
:-D for option explicit! :(( for the fact that I have several projects to go and I'm working in the order of best code to worst code.
I feel your pain! Our company has a product where turning Option Strict On results in probably 1000's of errors... Stuff like:
Dim i As Integer = someStringThatSupposedlyCanOnlyHoldAnInteger
The worst part is that code like this goes wrong on regular basis. Our users will never know though... Errors are caught and logged (preferably at the lowerst level, some 10 functions deep) and the software goes on like nothing ever happened :)
It's an OO world.
public class Naerling : Lazy<Person>{
public void DoWork(){ throw new NotImplementedException(); }
} -
Computers should be used for what they are good at: systematic consistency checks. Because this is where they can help preventing bugs early. Static analysis. If I were God, I would make the Strict mode compulsory. And enhance the programming languages to help computers help us. For instance by introducing dimensional analysis on the data.
Dim Meters as Unit
Dim Side As Integer in Meters, Area As Integer in Meters^2, Count(0 To 5) As IntegerArea = 3 * Side 'Error: Option Strict On disallows implicit conversion from Meters to Meters^2
Count(Side) = Count(Side) + 1 'Error: Option Strict On disallows using dimensional expressions as indexesThat should be possible with OOP. A Lounge post earlier in the week led me to a paper written by C. A. R. Hoare in 1973 in which he states that a language should allow that: http://www.eecs.umich.edu/~bchandra/courses/papers/Hoare_Hints.pdf[^]
-
That should be possible with OOP. A Lounge post earlier in the week led me to a paper written by C. A. R. Hoare in 1973 in which he states that a language should allow that: http://www.eecs.umich.edu/~bchandra/courses/papers/Hoare_Hints.pdf[^]
Thanks for pointing at this article: a pure delight ! As is turns out, little of Hoare's hints have been followed, I guess :)
-
I feel your pain! Our company has a product where turning Option Strict On results in probably 1000's of errors... Stuff like:
Dim i As Integer = someStringThatSupposedlyCanOnlyHoldAnInteger
The worst part is that code like this goes wrong on regular basis. Our users will never know though... Errors are caught and logged (preferably at the lowerst level, some 10 functions deep) and the software goes on like nothing ever happened :)
It's an OO world.
public class Naerling : Lazy<Person>{
public void DoWork(){ throw new NotImplementedException(); }
}Naerling wrote:
Our company has a product where turning Option Strict On results in probably 1000's of errors
Then you need to start fixing now. Enable it on file level and fix the files one by one. If it's not the highest priority your company has problems.
Light moves faster than sound. That is why some people appear bright, until you hear them speak. List of common misconceptions
-
AspDotNetDev wrote:
The bad part is that the OrElse is between a string and a boolean, which is returning a boolean, which then gets passed as a parameter to String.IsNullOrEmpty.
Uh, that's WHY there is an Option Strict: to allow relaxed type checking on certain operations. Though here it is certainly annoying, and one of the reasons I tend to use Option Strict pretty consistently.
-
Naerling wrote:
Our company has a product where turning Option Strict On results in probably 1000's of errors
Then you need to start fixing now. Enable it on file level and fix the files one by one. If it's not the highest priority your company has problems.
Light moves faster than sound. That is why some people appear bright, until you hear them speak. List of common misconceptions
In the old VB days, I worked on a project and we mandated
Option Explicit
for all files. One dev kept removing it as his code wouldn't build when it was switched on...
Panic, Chaos, Destruction. My work here is done. Drink. Get drunk. Fall over - P O'H OK, I will win to day or my name isn't Ethel Crudacre! - DD Ethel Crudacre I cannot live by bread alone. Bacon and ketchup are needed as well. - Trollslayer Have a bit more patience with newbies. Of course some of them act dumb - they're often *students*, for heaven's sake - Terry Pratchett
-
In the old VB days, I worked on a project and we mandated
Option Explicit
for all files. One dev kept removing it as his code wouldn't build when it was switched on...
Panic, Chaos, Destruction. My work here is done. Drink. Get drunk. Fall over - P O'H OK, I will win to day or my name isn't Ethel Crudacre! - DD Ethel Crudacre I cannot live by bread alone. Bacon and ketchup are needed as well. - Trollslayer Have a bit more patience with newbies. Of course some of them act dumb - they're often *students*, for heaven's sake - Terry Pratchett
How did you punish him?
Light moves faster than sound. That is why some people appear bright, until you hear them speak. List of common misconceptions
-
Using a string as a boolean has nothing to do with object-oriented programming. If the code were directly comparing the boolean and the string, that might be considered something near valid (what with operator overloading), but that was not the case here. This code is basically like doing this:
If "Dragons" Then
' Dragons be true!
Else
' Dragons be false :-(
End IfIt doesn't make any sense.
Someone doesn't use PHP.
Don't forget to rate my post if it helped! ;) "He has no enemies, but is intensely disliked by his friends." "His mother should have thrown him away, and kept the stork." "There's nothing wrong with you that reincarnation won't cure." "He loves nature, in spite of what it did to him."
-
How did you punish him?
Light moves faster than sound. That is why some people appear bright, until you hear them speak. List of common misconceptions
It was a long process of giving him a roll kick to the nadgers every time he checked in a file without
Option Explicit
. We needed to have a rota.
Panic, Chaos, Destruction. My work here is done. Drink. Get drunk. Fall over - P O'H OK, I will win to day or my name isn't Ethel Crudacre! - DD Ethel Crudacre I cannot live by bread alone. Bacon and ketchup are needed as well. - Trollslayer Have a bit more patience with newbies. Of course some of them act dumb - they're often *students*, for heaven's sake - Terry Pratchett