|
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"
|
|
|
|
|
Haha - I have the same t-shirt. I earned it late one night trying to debug a release build problem. Had wrapped important code with #ifdef DEBUG..
Charlie Gilley
<italic>You're going to tell me what I want to know, or I'm going to beat you to death in your own house.
"Where liberty dwells, there is my country." B. Franklin, 1783
“They who can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety.” BF, 1759
|
|
|
|
|
if (item.Substring(0, 3).ToLower() != "PF_")
[Head hangs in shame]
I should have coded:
if (item.Substring(0, 3).ToLower() != "PF_".ToLower())
“That which can be asserted without evidence, can be dismissed without evidence.”
― Christopher Hitchens
|
|
|
|
|
GuyThiebaut wrote: I should have coded:
if (item.Substring(0, 3).ToLower() != "PF_".ToLower())
I hope that's a good example of sarcasm!
if (string.Compare(item, 0, "PF_", 0, 3, StringComparison.OrdinalIgnoreCase) != 0)
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Yes it's self satire... honestly...
“That which can be asserted without evidence, can be dismissed without evidence.”
― Christopher Hitchens
|
|
|
|
|
If we're going for doing it right of course the answer is
if(item.StartsWith("PF_", StringComparison.OrdinalIgnoreCase)) ...
|
|
|
|
|
Well, if you will insist on writing code that other people can understand and maintain...
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
I'm sorry I meant
if(1600548864 == (*(int*)&item.ToLower()) << 8) ...
|
|
|
|
|
That's better!
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Nasty! Unsafe code...
Please, try to avoid it, especially when it can be done without it so much more clearly:
if (((BitConverter.ToInt32(Encoding.ASCII.GetBytes(item), 0) & 6250335) ^ 6243920) == 0)
|
|
|
|
|
Clearly a functional language will magically make this far better:
((xum 567 487) (map item (lambda x (find (xor x (and y z)) (encode pi 49)))
The language is JavaScript. that of Mordor, which I will not utter here
I hold an A-7 computer expert classification, Commodore. I'm well acquainted with Dr. Daystrom's theories and discoveries. The basic design of all our ship's computers are JavaScript.
|
|
|
|
|
CDP1802 wrote:
((xum 567 487) (map item (lambda x (find (xor x (and y z)) (encode pi 49)))
The language is JavaScript. that of Mordor, which I will not utter here
Man! Javascript has changed!
|
|
|
|