Code should be 5 or anything above 7 long...
-
Before people start... The horror is NOT that this is VB code... Now with that out of the way... A bit of weird code a colleague found recently...
' This code should always be 5 characters long.
If code.Length < 5 Or code.Length = 6 Or code.Length = 7 Then
Throw New Exception("Code should be 5 characters long.")
End IfMy guess is that the programmer assumed it would be 5 characters long or less. Then it turned out it could be 6 too so the
Or code.length = 6
part was added, then the code was 7 at some occurrence... The users weren't stupid enough to enter an 8 character code so that one hasn't been added (yet) :laugh: Why not simply check ifcode.Length <> 5
? :rolleyes:It's an OO world.
public class Naerling : Lazy<Person>{
public void DoWork(){ throw new NotImplementedException(); }
} -
Before people start... The horror is NOT that this is VB code... Now with that out of the way... A bit of weird code a colleague found recently...
' This code should always be 5 characters long.
If code.Length < 5 Or code.Length = 6 Or code.Length = 7 Then
Throw New Exception("Code should be 5 characters long.")
End IfMy guess is that the programmer assumed it would be 5 characters long or less. Then it turned out it could be 6 too so the
Or code.length = 6
part was added, then the code was 7 at some occurrence... The users weren't stupid enough to enter an 8 character code so that one hasn't been added (yet) :laugh: Why not simply check ifcode.Length <> 5
? :rolleyes:It's an OO world.
public class Naerling : Lazy<Person>{
public void DoWork(){ throw new NotImplementedException(); }
}At least the programmer added a comment stating what the code should do. :rolleyes:
-
At least the programmer added a comment stating what the code should do. :rolleyes:
If only the code did what was commented... Perhaps requirements changed and the comment is wrong? :rolleyes:
It's an OO world.
public class Naerling : Lazy<Person>{
public void DoWork(){ throw new NotImplementedException(); }
} -
Before people start... The horror is NOT that this is VB code... Now with that out of the way... A bit of weird code a colleague found recently...
' This code should always be 5 characters long.
If code.Length < 5 Or code.Length = 6 Or code.Length = 7 Then
Throw New Exception("Code should be 5 characters long.")
End IfMy guess is that the programmer assumed it would be 5 characters long or less. Then it turned out it could be 6 too so the
Or code.length = 6
part was added, then the code was 7 at some occurrence... The users weren't stupid enough to enter an 8 character code so that one hasn't been added (yet) :laugh: Why not simply check ifcode.Length <> 5
? :rolleyes:It's an OO world.
public class Naerling : Lazy<Person>{
public void DoWork(){ throw new NotImplementedException(); }
} -
Before people start... The horror is NOT that this is VB code... Now with that out of the way... A bit of weird code a colleague found recently...
' This code should always be 5 characters long.
If code.Length < 5 Or code.Length = 6 Or code.Length = 7 Then
Throw New Exception("Code should be 5 characters long.")
End IfMy guess is that the programmer assumed it would be 5 characters long or less. Then it turned out it could be 6 too so the
Or code.length = 6
part was added, then the code was 7 at some occurrence... The users weren't stupid enough to enter an 8 character code so that one hasn't been added (yet) :laugh: Why not simply check ifcode.Length <> 5
? :rolleyes:It's an OO world.
public class Naerling : Lazy<Person>{
public void DoWork(){ throw new NotImplementedException(); }
}OMG ... I can't look at it. I'm feeling sick. Thank you for ruining my day! :-)
-
Before people start... The horror is NOT that this is VB code... Now with that out of the way... A bit of weird code a colleague found recently...
' This code should always be 5 characters long.
If code.Length < 5 Or code.Length = 6 Or code.Length = 7 Then
Throw New Exception("Code should be 5 characters long.")
End IfMy guess is that the programmer assumed it would be 5 characters long or less. Then it turned out it could be 6 too so the
Or code.length = 6
part was added, then the code was 7 at some occurrence... The users weren't stupid enough to enter an 8 character code so that one hasn't been added (yet) :laugh: Why not simply check ifcode.Length <> 5
? :rolleyes:It's an OO world.
public class Naerling : Lazy<Person>{
public void DoWork(){ throw new NotImplementedException(); }
} -
Before people start... The horror is NOT that this is VB code... Now with that out of the way... A bit of weird code a colleague found recently...
' This code should always be 5 characters long.
If code.Length < 5 Or code.Length = 6 Or code.Length = 7 Then
Throw New Exception("Code should be 5 characters long.")
End IfMy guess is that the programmer assumed it would be 5 characters long or less. Then it turned out it could be 6 too so the
Or code.length = 6
part was added, then the code was 7 at some occurrence... The users weren't stupid enough to enter an 8 character code so that one hasn't been added (yet) :laugh: Why not simply check ifcode.Length <> 5
? :rolleyes:It's an OO world.
public class Naerling : Lazy<Person>{
public void DoWork(){ throw new NotImplementedException(); }
} -
Before people start... The horror is NOT that this is VB code... Now with that out of the way... A bit of weird code a colleague found recently...
' This code should always be 5 characters long.
If code.Length < 5 Or code.Length = 6 Or code.Length = 7 Then
Throw New Exception("Code should be 5 characters long.")
End IfMy guess is that the programmer assumed it would be 5 characters long or less. Then it turned out it could be 6 too so the
Or code.length = 6
part was added, then the code was 7 at some occurrence... The users weren't stupid enough to enter an 8 character code so that one hasn't been added (yet) :laugh: Why not simply check ifcode.Length <> 5
? :rolleyes:It's an OO world.
public class Naerling : Lazy<Person>{
public void DoWork(){ throw new NotImplementedException(); }
}What's so bad about being explicit about what you don't accept as a valid value? :) Besides that, we also have a lot of literal values here. Checking the length against a constant or some configuration entry can be helpful, especially because the code's valid length may have changed over time. Throwing a plain vanilla exception with a literal message also is sloppy. It's not that hard to derive custom exeption classes for your application and would help in avoiding Pokemon exception handling.
I'm invincible, I can't be vinced
-
Before people start... The horror is NOT that this is VB code... Now with that out of the way... A bit of weird code a colleague found recently...
' This code should always be 5 characters long.
If code.Length < 5 Or code.Length = 6 Or code.Length = 7 Then
Throw New Exception("Code should be 5 characters long.")
End IfMy guess is that the programmer assumed it would be 5 characters long or less. Then it turned out it could be 6 too so the
Or code.length = 6
part was added, then the code was 7 at some occurrence... The users weren't stupid enough to enter an 8 character code so that one hasn't been added (yet) :laugh: Why not simply check ifcode.Length <> 5
? :rolleyes:It's an OO world.
public class Naerling : Lazy<Person>{
public void DoWork(){ throw new NotImplementedException(); }
}My fix :-)
' Code should be 5 or anything above 7 long
If IsPrime(90*code.Length+61) Then
Throw New Exception("Code should be 5 or anything above 7 characters long.")
End If -
Before people start... The horror is NOT that this is VB code... Now with that out of the way... A bit of weird code a colleague found recently...
' This code should always be 5 characters long.
If code.Length < 5 Or code.Length = 6 Or code.Length = 7 Then
Throw New Exception("Code should be 5 characters long.")
End IfMy guess is that the programmer assumed it would be 5 characters long or less. Then it turned out it could be 6 too so the
Or code.length = 6
part was added, then the code was 7 at some occurrence... The users weren't stupid enough to enter an 8 character code so that one hasn't been added (yet) :laugh: Why not simply check ifcode.Length <> 5
? :rolleyes:It's an OO world.
public class Naerling : Lazy<Person>{
public void DoWork(){ throw new NotImplementedException(); }
} -
Difference between VB or C# is a syntax, thanks to the .net framework. But if you ask what do I think is that C# is better. But ultimately it comes toward preference.
-
My fix :-)
' Code should be 5 or anything above 7 long
If IsPrime(90*code.Length+61) Then
Throw New Exception("Code should be 5 or anything above 7 characters long.")
End IfAre you a member of Obfuscators Anonymous. :)
Chris Meech I am Canadian. [heard in a local bar] In theory there is no difference between theory and practice. In practice there is. [Yogi Berra] posting about Crystal Reports here is like discussing gay marriage on a catholic church’s website.[Nishant Sivakumar]
-
Before people start... The horror is NOT that this is VB code... Now with that out of the way... A bit of weird code a colleague found recently...
' This code should always be 5 characters long.
If code.Length < 5 Or code.Length = 6 Or code.Length = 7 Then
Throw New Exception("Code should be 5 characters long.")
End IfMy guess is that the programmer assumed it would be 5 characters long or less. Then it turned out it could be 6 too so the
Or code.length = 6
part was added, then the code was 7 at some occurrence... The users weren't stupid enough to enter an 8 character code so that one hasn't been added (yet) :laugh: Why not simply check ifcode.Length <> 5
? :rolleyes:It's an OO world.
public class Naerling : Lazy<Person>{
public void DoWork(){ throw new NotImplementedException(); }
} -
Before people start... The horror is NOT that this is VB code... Now with that out of the way... A bit of weird code a colleague found recently...
' This code should always be 5 characters long.
If code.Length < 5 Or code.Length = 6 Or code.Length = 7 Then
Throw New Exception("Code should be 5 characters long.")
End IfMy guess is that the programmer assumed it would be 5 characters long or less. Then it turned out it could be 6 too so the
Or code.length = 6
part was added, then the code was 7 at some occurrence... The users weren't stupid enough to enter an 8 character code so that one hasn't been added (yet) :laugh: Why not simply check ifcode.Length <> 5
? :rolleyes:It's an OO world.
public class Naerling : Lazy<Person>{
public void DoWork(){ throw new NotImplementedException(); }
} -
Indeed...
Dim counter As Long ' This could be a REAL long code!
For Each c As Char In code
counter = counter + 1
End If
If counter < 5 Then
Throw New Exception("The code is to short!")
ElseIf counter = 6
Throw New Exception("The code is to long!")
ElseIf counter = 7
Throw New Exception("The code is to long!")
Else
' Some code here :)
End IfIt's an OO world.
public class Naerling : Lazy<Person>{
public void DoWork(){ throw new NotImplementedException(); }
} -
Indeed...
Dim counter As Long ' This could be a REAL long code!
For Each c As Char In code
counter = counter + 1
End If
If counter < 5 Then
Throw New Exception("The code is to short!")
ElseIf counter = 6
Throw New Exception("The code is to long!")
ElseIf counter = 7
Throw New Exception("The code is to long!")
Else
' Some code here :)
End IfIt's an OO world.
public class Naerling : Lazy<Person>{
public void DoWork(){ throw new NotImplementedException(); }
} -
The happy face is a hidden VB feature in .NET 4 ;p
It's an OO world.
public class Naerling : Lazy<Person>{
public void DoWork(){ throw new NotImplementedException(); }
} -
Are you a member of Obfuscators Anonymous. :)
Chris Meech I am Canadian. [heard in a local bar] In theory there is no difference between theory and practice. In practice there is. [Yogi Berra] posting about Crystal Reports here is like discussing gay marriage on a catholic church’s website.[Nishant Sivakumar]
Yeah, at the Novice rank. I hope to go up to Apprentice this year.
-
Maybe the comment and the error message should have been ' This code should always be 5 characters or more than 7 characters.
-
Before people start... The horror is NOT that this is VB code... Now with that out of the way... A bit of weird code a colleague found recently...
' This code should always be 5 characters long.
If code.Length < 5 Or code.Length = 6 Or code.Length = 7 Then
Throw New Exception("Code should be 5 characters long.")
End IfMy guess is that the programmer assumed it would be 5 characters long or less. Then it turned out it could be 6 too so the
Or code.length = 6
part was added, then the code was 7 at some occurrence... The users weren't stupid enough to enter an 8 character code so that one hasn't been added (yet) :laugh: Why not simply check ifcode.Length <> 5
? :rolleyes:It's an OO world.
public class Naerling : Lazy<Person>{
public void DoWork(){ throw new NotImplementedException(); }
}These instances of code changes were not done by a programmer. A developer maybe, but not a programmer.