|
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.
|
|
|
|
|
So I assume all over the codebae you have something like this?
if (GetLimitMessage(a, b).Length > 0)
MessageBox.Show(GetLimitMessaage(a, b));
The good thing about pessimism is, that you are always either right or pleasently surprised.
|
|
|
|
|
Are you mad! That would be far too risky to write it like that, far better would be:
if (!GetLimitMessage(a, b).equals(GetLimitMessage(1, -1)) {
if (!String.IsNullOrEmpty(GetLimitMessage(a, b)) {
MessageBox.Show(GetLimitMessaage(a, b));
}
else
{
MessageBox.Show("The monkey's dead!");
}
}
speramus in juniperus
|
|
|
|
|
Now I need some more mind bleach...
|
|
|
|
|
Surely a MessageBox is rather "old hat"? How do you display a Fail Whale in a MessageBox?
|
|
|
|
|
Woah up there, you're missing a major source of defensive coding here...
try {
if (GetLimitMessage(a,b) != null && GetLimitMessage(a,b).Equals(GetLimitMessage(1, -1))) {
if (!string.IsNullOrEmpty(GetLimitMessage(a,b)) {
try {
MessageBox.Show(GetLimitMessage(a,b));
}
catch (Exception ex) {
throw;
}
}
}
}
catch (Exception ex) {
MessageBox.Show("The monkey's dead!");
}
"If you don't fail at least 90 percent of the time, you're not aiming high enough."
Alan Kay.
|
|
|
|
|
It's an APS.NET MVC 3 Application, so it's:
Controller:
if(Helper.GetLimitMessage(total, 100))
{
ViewBag.LimitMessage = Helper.GetLimitMessage(total, 100);
ViewData["LimitMessage"] = Helper.GetLimitMessage(total, 100);
}
View:
@if(ViewBag.LimitMessage != "")
{
@Helper.GetLimitMessage(total, 100)
}
else if (ViewData["LimitMessage"] != null)
{
@ViewData["LimitMessage"]
}
Even my coworker who normally doesn't rant on code is cursing this one.
|
|
|
|
|
There isn't a large enough for this.
|
|
|
|
|
Is this the real life?
Is this just fantasy?
caught in a landslide
no escape from reality
open your eye's
look up to the ceiling and stare
I'm just a poor coder, I get no sympathy
because I make simple things, make them work
respect my deadlines, don't be a jerk
Any way management blows, doesn't really matter to meeeee
To meeeeeee
MAMAAAAA I just killed my coworker
put a gun against his head
pulled my trigger, now he's dead...
.
|
|
|
|
|
|
I produced this little gem, a few months ago:
QMutex statusMutex;
int status;
int GetStatus(){
statusMutex.lock();
return status;
statusMutex.unlock();
}
Needles to say that it didn't really work as great as I expected it to
Veni, vidi, caecus
|
|
|
|
|
The compiler should issue a warning or unreachable code. Did it?
And what with the uninitialised statusMutex thingy?
Or is there some background magic going on I'm not privy to?
Cheers!
"I had the right to remain silent, but I didn't have the ability!"
Ron White, Comedian
|
|
|
|
|
Manfred R. Bihy wrote: And what with the uninitialised statusMutex thingy?
It is initialized - It is Qt code, where objects can be initialized by just writing "ObjectType variablename; ".
Remember that this is a must for constructors not accepting any parameters - Otherwise they'd be mistaken for method calls, leading the compiler to throw up.
And, No - The compiler did not issue a warning or an error, may has something to do with the Qt-Plugin not playing nice to VS 2012.
Veni, vidi, caecus
|
|
|
|
|
Marco Bertschi wrote: It is Qt code, where objects can be initialized by just writing "ObjectType variablename; ".
Interesting, to say the least. What would you do in Qt if you wanted an uninitialised variable declaration?
Cheers!
"I had the right to remain silent, but I didn't have the ability!"
Ron White, Comedian
|
|
|
|
|
Not initialized variables are bad!
Nevertheless, go for MyType myObject = 0; .
Initialize to 0 because the MS C++ compiler may get a little hiccup if you try it with NULL - Even though it is theoretically valid, MS uses another value which is != 0 for the debug versions to avoid the use of unintilized variables - This behavior may lead to system crashes in the debug version, therefore my first statement.
Veni, vidi, caecus
|
|
|
|
|
Marco Bertschi wrote: Not initialized variables are bad!
I'm an engineer, trust me, I know what I'm adfsadfasdfdfffffffffffffffffffffüllächt!
"I had the right to remain silent, but I didn't have the ability!"
Ron White, Comedian
|
|
|
|
|
Why didn't you use RAII?
class MutexLocker {
QMutex &m;
public:
MutexLocker(QMutex &qm) : m(qm) { m.lock(); }
~MutexLocker() { m.unlock(); }
};
int GetStatus(){
MutexLocker tmp(statusMutex);
return status;
}
Pablo.
"Accident: An inevitable occurrence due to the action of immutable natural laws." (Ambrose Bierce, circa 1899).
"You are to act in the light of experience as guided by intelligence" (Rex Stout, "In the Best Families", 1950).
|
|
|
|
|
Manfred R. Bihy wrote: The compiler should issue a warning or unreachable code. Did it?
Is that what I just ignored...

|
|
|
|
|
"worst code you'll ever see is the one you wrote last year"
|
|
|
|