|
Really funny. The check for a null string will throw a null reference exception is customMessage is null.
|
|
|
|
|
What is wrong with that? I imagine this was before .Net 4.0 in which you can now use string.IsNullOrWhitespace()...
if(string.IsNullOrWhitespace(customMessage))
...
Illogical thoughts make me ill
|
|
|
|
|
musefan wrote: What is wrong with that?
As _Erik_ said, what happens with this code?
string customMessage = null;
if (string.IsNullOrEmpty(customMessage.Trim()))
...
|
|
|
|
|
now that's shameful coding, but the OP never put that, there is no evidence that it is unsafe to assume that customMessage will never be null. What if the following was the case...
string customMessage = GetCustomMessage();
if (string.IsNullOrEmpty(customMessage.Trim()))
...
string GetCustomMessage(){
string result = GetSomeDataFromSomewhere();
return result ?? "";
}
Illogical thoughts make me ill
|
|
|
|
|
musefan wrote: there is no evidence that it is unsafe to assume that customMessage will never be null
If that was the case then the call to string.IsNullOrEmpty would not be required, as you could safely access the Length property and test for zero. Eitherway you look at it, the OP code is unnecessary
|
|
|
|
|
But the whole point in the trim (IMO) is to test that a complete whitespace string is not confused with meaningful data. Imagine if the string was fetched using my sample method, and the call to get the data in there returns a tab separated list - this function may always end in a tab even when no data has been added. so the resulting value could be "\t" in which case it should be ignored just like "" would be.
Your length test doesn't work in this case because a string of data and whitespace would equal the same. Consider the following possible string values and what you want to test for invalid...
string s = "";
string s = "\t";
string s = @"data 1\tdata 2\t";
Illogical thoughts make me ill
|
|
|
|
|
Sorry, I don't think I phrased it well. The length test was a replacement for the string.IsNullOrEmpty call - you can still call Trim though. Back to the original code:
if (customMessage.Trim().Length == 0)
...
|
|
|
|
|
I see, yep that's OK with me
My initial post was really to find out why it was such a bad line of code when we cannot see any other code to judge. People seemed to be going for the null exception but there was nothing to indicate that wouldcould happen
Illogical thoughts make me ill
|
|
|
|
|
However unlikely, things that CAN happen eventually WILL happen. Illogical or not.
|
|
|
|
|
I didn't say it was unlikely, I said it was possible that it could never happen. That does not mean sometimes it could happen, it means other code could decide that it will never happen.
oggenok wrote: things that CAN happen eventually WILL happen
...and that is not certain
if I wrote...
string s = "hello ";
s = s.Trim();
...would you correct with...
string s= "hello ";
if(!string.IsNullOrEmpty(s))
s = s.Trim();
EDIT: Not understanding my message is not justification to vote it down.
Illogical thoughts make me ill
modified on Tuesday, March 1, 2011 10:22 AM
|
|
|
|
|
Hey!
Found this evaluation if an object is from a certain sort in a Java code:
if(oSomeStringObject.getClass().getSimpleName().equalsIgnoreCase("String")){
doFunnyStuff();
}
that's probably the worst attempt I've seen in a long time. I don't know exactly, but this might be from an C-Programmer trying to code Java. We are using some code given to us here.
regards
Torsten
I never finish anyth...
|
|
|
|
|
TorstenH. wrote: C-Programmer trying to code Java
Or maybe a .NET programmer (C# probably) who failed to find that Java "instanceof" operator is the equivalent to the C# "is" operator.
|
|
|
|
|
Here's another chunk of C++ that has been converted to VB.net:
Public Shared Function Strdate(ByVal dateBuf As String) As String
' timt(tnow)
'tm *tnowVals
'time(&tnow)
'tnowVals = localtime(&tnow)
Dim tnowVals As DateTime = DateTime.Now
tnowVals = DateTime.Now
If tnowVals.Year > 1999 Then 'If (tnowVals.tm_year > 99) Then
tnowVals.Subtract(TimeSpan.FromDays(365 * 100)) ' tnowVals.tm_year -= 100
End If
dateBuf = tnowVals.ToString("MM/dd/yy") 'sprintf(dateBuf, "%02.02d/%02.02d/%02.02d", tnowVals.tm_mon + 1, tnowVals.tm_mday, tnowVals.tm_year)
Return dateBuf
End Function
Notice that even the original C++ is faulty; it should use % (mod) rather than subtracting 100 years -- a Y3K bug.
|
|
|
|
|
PIEBALDconsult wrote: a Y3K bug
...there shall be no computers to run such a program on in the year 3000
Illogical thoughts make me ill
|
|
|
|
|
void show()
{
int man=5;
string action = string.Empty;
for (int j = 1; j < indx-1;j++ )
{
for (int k = 1; k < indy-1; k++)
{
Console.Write(arr[j,k]+ " ");
int q = Math.Abs(arr[j - 1, k - 1] - arr[j, k]);
int w = Math.Abs(arr[j - 1, k] - arr[j, k]);
int e = Math.Abs(arr[j -1, k +1] - arr[j, k]);
int a = Math.Abs(arr[j , k - 1] - arr[j, k]);
int d = Math.Abs(arr[j, k + 1] - arr[j, k]);
int z = Math.Abs(arr[j + 1, k - 1] - arr[j, k]);
int x = Math.Abs(arr[j + 1, k ] - arr[j, k]);
int c = Math.Abs(arr[j + 1, k +1] - arr[j, k]);
if (q < man && w < man && e < man && a < man && d < man && z < man && x < man && c < man)
{
action = string.Empty;
}
else {
if (arr[j - 1, k - 1] == arr[j - 1, k] && arr[j - 1, k] == arr[j + 1, k + 1]) {
if (arr[j - 1, k] == arr[j, k - 1] && arr[j, k - 1] == arr[j - 1, k])
{
if (arr[j - 1, k] == arr[j + 1, k - 1] && arr[j, k - 1] == arr[j + 1, k])
{
action = "c";
}
else
{
if (arr[j - 1, k] == arr[j + 1, k - 1])
{
if (arr[j + 1, k] == arr[j + 1, k + 1]) { action = "xc"; }
else
{ action = "x"; }
}
else
{
if (arr[j + 1, k - 1] == arr[j + 1, k + 1])
{
if (arr[j + 1, k] == arr[j + 1, k + 1]) { action = "zxc"; }
else
{ action = "zx"; }
}
else
{ action = "z"; }
}
}
}
else
{
if (arr[j, k + 1] == arr[j, k - 1] )
{
if (arr[j, k + 1] == arr[j + 1, k - 1] && arr[j, k - 1] == arr[j + 1, k] && arr[j, k - 1] == arr[j + 1, k+1])
{
action = "adzxc";
}
else
{
if (arr[j, k + 1] == arr[j + 1, k - 1] && arr[j, k - 1] == arr[j + 1, k])
{
action = "adzx";
}
else
{
if (arr[j, k + 1] == arr[j + 1, k - 1])
{
action = "adz";
}
else
{ action="adx"}
}
}
}
else{
}
}
this "else if" goes for another 5 pages
not a single coment
|
|
|
|
|
I have no idea either, but the letters listed ("qweadzxc") are arranged on the keyboard as a square. That makes me think it's related to video game controls.
|
|
|
|
|
good guess, it is something on image analysis my job is use pointer instead of array,
can u understand my pain .
|
|
|
|
|
AspDotNetDev wrote: it's related to video game controls.
But only for left handed ones.
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]
|
|
|
|
|
Nah, all vidya nowadays has your right hand on the mouse, and your left hand on WASD.
Hell, even full keyboard RTS games like StarCraft II do, apart from the occasional N or L hit.
|
|
|
|
|
There are plenty of comments.
There's no doubt the companies intellectual property is safe hand there. They have even obfuscated 5 to equal man.
"You get that on the big jobs."
|
|
|
|
|
need comments for these comments
|
|
|
|
|
I would prefer to learn chinese rather than trying to understand this mess.
|
|
|
|
|
So we're all waiting for your brand new article written in Chinese
|
|
|
|
|
This guy should work for the government--he seems to be an expert on ciphers and cryptography!
|
|
|
|
|
There is a App key for that -> "Delete"
I tried to modify an equal code some weeks ago. As I got behind it, I figured out it didn't make much sense at all.
regards
Torsten
I never finish anyth...
|
|
|
|