Is the glass half empty or half full?
-
Oh Boy! Have you got a major disappointment coming... Nothing in life works all the time. And if you aren't ready for when it doesn't, then it will hit you like a tonne of bricks.
Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water
but the important part of that is: "some times life hit your head with a break , don't lose faith" steve jobs, stanford university!
-
What are your error flags: optimistic or perssimistic? How do you code:
boolean success = false;
try {
// ...
success = true;
} catch (Exception ex) {
// ...
}
return success;or
boolean success = true;
try {
// ...} catch (Exception ex) {
success = false;
// ...
}
return success;? Just curious. ;)
Greetings - Jacek
It's always full[^] In answer to your question:
try
{
// ...
return true;
}
catch (Exception ex)
{
// ...
return false;
}Assuming you don't return anywhere else. I don't agree with an idea that a method must have only one point of exit, and have never found code less readable as a result with modern IDEs. In your example I have to get to the bottom of the method to find out what the
boolean
does, and you have to worry about defensive coding. Obviously, other people will have different views on this.Sort of a cross between Lawrence of Arabia and Dilbert.[^]
-Or-
A Dead ringer for Kate Winslett[^] -
What are your error flags: optimistic or perssimistic? How do you code:
boolean success = false;
try {
// ...
success = true;
} catch (Exception ex) {
// ...
}
return success;or
boolean success = true;
try {
// ...} catch (Exception ex) {
success = false;
// ...
}
return success;? Just curious. ;)
Greetings - Jacek
I have no tolerance for errors, so why catch them? They're just going to piss me off, and life has enough aggravations. A simple popup that says, "You screwed up; I'm formatting your C: drive" is usually sufficient to prevent future problems.
Will Rogers never met me.
-
I have no tolerance for errors, so why catch them? They're just going to piss me off, and life has enough aggravations. A simple popup that says, "You screwed up; I'm formatting your C: drive" is usually sufficient to prevent future problems.
Will Rogers never met me.
...only if you make sure to hide the "Cancel" button. "OK" and "OK, sure - go ahead" should be enough.
Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water
-
...only if you make sure to hide the "Cancel" button. "OK" and "OK, sure - go ahead" should be enough.
Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water
I've always considered 'Cancel' and 'Back' buttons to be sops for the weak-minded. In order to assist my users in growing a pair and becoming more decisive, I always leave them out of the dialog. It's my plain duty...
Will Rogers never met me.
-
I've always considered 'Cancel' and 'Back' buttons to be sops for the weak-minded. In order to assist my users in growing a pair and becoming more decisive, I always leave them out of the dialog. It's my plain duty...
Will Rogers never met me.
It's worth taunting them though - A "NO! For Gods sake, NO! STOP!" button is a good idea, provided it is permanently disabled.
Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water
-
What are your error flags: optimistic or perssimistic? How do you code:
boolean success = false;
try {
// ...
success = true;
} catch (Exception ex) {
// ...
}
return success;or
boolean success = true;
try {
// ...} catch (Exception ex) {
success = false;
// ...
}
return success;? Just curious. ;)
Greetings - Jacek
Typically I use the error point of view... I prefer to stop the program / action if something unhandled has happened. Of course I program machines and it can be dangerous to move something in an unhandled way...
[www.tamautomation.com] Robots, CNC and PLC machines for grinding and polishing.
-
What are your error flags: optimistic or perssimistic? How do you code:
boolean success = false;
try {
// ...
success = true;
} catch (Exception ex) {
// ...
}
return success;or
boolean success = true;
try {
// ...} catch (Exception ex) {
success = false;
// ...
}
return success;? Just curious. ;)
Greetings - Jacek
Success is only achieved after you've successfully completed a task. So: boolean success = false;
cheers, Chris Maunder The Code Project | Co-founder Microsoft C++ MVP
-
What are your error flags: optimistic or perssimistic? How do you code:
boolean success = false;
try {
// ...
success = true;
} catch (Exception ex) {
// ...
}
return success;or
boolean success = true;
try {
// ...} catch (Exception ex) {
success = false;
// ...
}
return success;? Just curious. ;)
Greetings - Jacek
I'm with Chris on this one. False unless the process completes and passes all tests. That way, I'm not enumerating badness missing a test or piece that wasn't in the design.
A guide to posting questions on CodeProject[^]
Dave Kreskowiak -
What are your error flags: optimistic or perssimistic? How do you code:
boolean success = false;
try {
// ...
success = true;
} catch (Exception ex) {
// ...
}
return success;or
boolean success = true;
try {
// ...} catch (Exception ex) {
success = false;
// ...
}
return success;? Just curious. ;)
Greetings - Jacek
It depends on the situation. Each is better suited to different scenarios so you shouldn't code it one way all the time.
-
Success is only achieved after you've successfully completed a task. So: boolean success = false;
cheers, Chris Maunder The Code Project | Co-founder Microsoft C++ MVP
:thumbsup: This is the very idea that I teach my students in any of the programming courses I teach.
"The clue train passed his station without stopping." - John Simmons / outlaw programmer "Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon "Not only do you continue to babble nonsense, you can't even correctly remember the nonsense you babbled just minutes ago." - Rob Graham
-
I'm with Chris on this one. False unless the process completes and passes all tests. That way, I'm not enumerating badness missing a test or piece that wasn't in the design.
A guide to posting questions on CodeProject[^]
Dave KreskowiakDave Kreskowiak wrote:
not enumerating badness missing a test or piece that wasn't in the design
Yes. It does make testing easier, and gives more assurance that proof of concept that the code is well designed.
"The clue train passed his station without stopping." - John Simmons / outlaw programmer "Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon "Not only do you continue to babble nonsense, you can't even correctly remember the nonsense you babbled just minutes ago." - Rob Graham
-
Success is only achieved after you've successfully completed a task. So: boolean success = false;
cheers, Chris Maunder The Code Project | Co-founder Microsoft C++ MVP
-
Agreed. But that "boolean success = false;" at the very beginning of a method looks so sad... :((
Greetings - Jacek
Which is why it should be named
result
. -
Which is why it should be named
result
.