|
OP may just have built this piece of code to prevent a warning saying that variable 'number_of_records' has been declared but is never used.
Quite brilliant, actually.
Women are composed of carbon, hydrogen, oxygen and nitrogen; men are also composed of carbon, hydrogen, oxygen and nitrogen, but in such proportions that force respect.
|
|
|
|
|
Looks like an incomplete sanity check. It should be:
if (number_of_records > 0)
{}
else if (number_of_records <= 0)
{}
else
{
printf("%d", *(int*)666);
}
Greetings - Jacek
|
|
|
|
|
It's always good to check whether a particular record is existing or not before accessing that record.
Specially in collections, sometimes it maybe empty or less than the number of required records that you want to access.
The following code will execute based on the records available
DataTable table = new System.Data.DataTable();
table.Columns.Add("ID");
table.Rows.Add("1");
string test = string.Empty;
int num_of_records = table.Rows.Count;
if (num_of_records > 0)
{
test = table.Rows[0][0].ToString();
}
else
{
return;
}
The following code is directly trying to access a record which may or may not be existing though the code is syntactically correct it may throw error in the event of unavailablity of records.
DataTable table = new System.Data.DataTable();
table.Columns.Add("ID");
string test = string.Empty;
test = table.Rows[0][0].ToString();
IndexOutOfRangeException - There is no row at position 0.
|
|
|
|
|
I agree, and the original post was probably more of a question of what the developer intended to do inside the {} in both the if part and the else part; which of course could be anything.
If anything it's just dead code the compiler would likely cut out.
"I've seen more information on a frickin' sticky note!" - Dave Kreskowiak
|
|
|
|
|
From the legacy VB6 app being ported...
Private Sub cmdGateway_Click()
If UCase("" & InputBox("Input password")) <> "DIFFERENT" Then
MsgBox ("Incorrect password")
Exit Sub
Else
MsgBox ("Password accepted")
End If
End Sub
The real password was not as above, but in every other sense this is representative.
The same password is used for many "sensitive" commands through the app. In this case though, the button simply checks the password and does nothing else.
I'm off for some mind bleach (whiskey).
"If you don't fail at least 90 percent of the time, you're not aiming high enough."
Alan Kay.
|
|
|
|
|
The original 'Script Kiddie' (Programmer is too professional a term for this guy) obviously didn't know anything about security.
Getting information off the Internet is like taking a drink from a fire hydrant.
- Mitchell Kapor
|
|
|
|
|
Well, he knew that he needed a password for something, just not for what thing 
|
|
|
|
|
Whats the problem? It's completely secure provided you ship a copy of VS and the source to each user so they can set their own...
Never underestimate the power of stupid things in large numbers
--- Serious Sam
|
|
|
|
|
The following is not a useful error message:
Quote from upgrade log: src\Libraries\WindowsAPICodePack\Shell\Shell.csproj: Error on line 551291232. Expected 'ENCODING' but found 'utf-8'.
The file is 296 lines, not 551291232 lines.
Visual Studio 2013 Premium.
That error was nowhere near the issue (an unmatched tag on line 15)
Getting information off the Internet is like taking a drink from a fire hydrant.
- Mitchell Kapor
|
|
|
|
|
I've been doing some work with accessing a Queue on multiple threads (to see just how non-thread-safe they are) and had one report a count of -10. But it worked just fine.
|
|
|
|
|
PIEBALDconsult wrote: and had one report a count of -10. But it worked just fine.
Ouch. That's probably even worse than it simply failing, because you could have production code giving bad results without an exception.
.-.
|o,o|
,| _\=/_ .-""-.
||/_/_\_\ /[] _ _\
|_/|(_)|\\ _|_o_LII|_
\._. |\_/|"` |_| ==== |_|
|_|_| ||" || ||
|-|-| ||LI o ||
|_|_| ||'----'||
/_/ \_\ /__| |__\
|
|
|
|
|
WTF? That is rather strange. I wonder what else the framework has in store for this forum?
Getting information off the Internet is like taking a drink from a fire hydrant.
- Mitchell Kapor
|
|
|
|
|
|
And sadly the interface doesn't match the regular queue's.
|
|
|
|
|
The day you find an error message that accurately describes the error, then you can be surprised.
|
|
|
|
|
Getting information off the Internet is like taking a drink from a fire hydrant.
- Mitchell Kapor
|
|
|
|
|
Sad but true... 
|
|
|
|
|
Brisingr Aerowing wrote: Visual Studio 2013 Premium.
The extra lines come from being a Premium version. 
|
|
|
|
|
Getting information off the Internet is like taking a drink from a fire hydrant.
- Mitchell Kapor
|
|
|
|
|
"Error on line 551291232"
Now would be a good time to argue for payment by lines of code. Even at a penny a line, you'd be doing well.
"If you don't fail at least 90 percent of the time, you're not aiming high enough."
Alan Kay.
|
|
|
|
|
It was a C# project file that I had modified manually (changed framework version, removed file upgrade-related tags, fixed references) but I had accidentally removed a required end tag on line 15, which caused the error.
Getting information off the Internet is like taking a drink from a fire hydrant.
- Mitchell Kapor
|
|
|
|
|
He called for my help when he couldn't understand a piece of code.
After 2 hours digging, we finally understood what the code does. A convoluted piece of junk that just shows a string on a field on the page.
But the most facepalming thing we found was this piece of "code":
public string GetLimitMessage(int total, int limit){
if(total > limit)
try
{
return "The Limit has been reached!"
}
catch(Exception)
{
return "";
}
else
return string.Empty;
}
Aside from translation (the original is on Portuguese), that's the exactly code we found. We are still facepalming.
|
|
|
|
|
Do you know the one wrote this? I want to hire him! My office is too dirty lately...
I'm not questioning your powers of observation; I'm merely remarking upon the paradox of asking a masked man who he is (V).
|
|
|
|
|
He doesn't work here anymore (actually can be anyone of 4 people, but none of them work here now).
The thing is that all of them bragged about how their code was better and how they were the best
I don't want to see the worst. 
|
|
|
|
|
Of course they bragged about their code. They used the advanced feature "try-catch" so it must be great code! Well, great in their minds, anyway.
Just because the code works, it doesn't mean that it is good code.
|
|
|
|