|
I just can't imagine, what the intention of "double return"
It's easy to laugh, but, it's so hard to smile ...
|
|
|
|
|
I sometimes use kick-out returns to temporarily 'comment out' code I suspect of breaking things. You can still do it in C# (might be an error in Java, I forget), and obviously in things like JavaScript or PHP. Leaving one in is pretty bad though.
|
|
|
|
|
Hmm, for some reason that reminds me of the custom scripting language used in the game "Space Empires V"... one of its unique quirks was that a "return" statement did not actually terminate function execution! So the function you describe would in SE5 script wind up returning retB, because it's the last return statement to execute...
|
|
|
|
|
Pascal also has a non terminating return semantics, but it's much clearer than that (as could be expected from Pascal )!
'As programmers go, I'm fairly social. Which still means I'm a borderline sociopath by normal standards.' Jeff Atwood
'I'm French! Why do you think I've got this outrrrrageous accent?' Monty Python and the Holy Grail
|
|
|
|
|
Hmm, that would actually explain the SE5 language, as it does look quite a bit like Pascal... the guy who wrote the game was apparently primarily a Delphi programmer!
|
|
|
|
|
... the horrors in this WinForms app I'm working on...
catch (Exception ex)
{
string errormsg = ex.InnerException.ToString();
}
Nice big NullReferenceException for you there mister.
Other horrors include :
Three separate layers of DB access code, one in VB, on in the Business Logic Layer, and one in a separate assembly (Written in VB!)
|
|
|
|
|
Hey, look on the bright side - throwing a NullReferenceException in a catch block is better than just swallowing the original exception without logging or throwing anything else! :P
|
|
|
|
|
ekolis wrote:
Hey, look on the bright side - throwing a
NullReferenceException in a catch block is better than just swallowing the
original exception without logging or throwing anything else! :P
yeah, that's what made "On Error Resume Next" my least favorite phrase ever in a previous time.
|
|
|
|
|
ekolis wrote: throwing anything else
try{
}
catch(Exception ex){
throw new Exception("My crazy message");
}
This is what you mean right? I've seen people do this, but I always wonder why ? Isn't it heavy doing this?
V.
|
|
|
|
|
That is one way to do it, though I was thinking more along the lines of a custom exception, and (if it makes sense in the situation) including the original exception:
[code]
try {
// code here
}
catch (Exception ex) {
throw new MyApplicationCustomException("Oh no! Something went wrong! For more details see the inner exception...", ex);
}
[/code]
|
|
|
|
|
My current work project (code base from another company) is full of these, though wrapping in custom exception types and preserving the inner exception.
It makes sense when you want to add extra semantic information to the exception because you know the context in which it was called. It doesn't the amount they've done it (and it makes tracking down the actual point of failure a pain).
It is 'heavy', yes, but of the order of milliseconds, and if you're using exceptions properly (i.e. they are only thrown in exceptional circumstances) that doesn't matter.
|
|
|
|
|
Mel Padden wrote: Three separate layers of DB access code, one in VB, on in the Business Logic Layer
Yes, that is a horror itself. Last I checked, that what the Business Logic Layer is for, to be the bridge between the application and the database.
"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
|
|
|
|
|
People write this sort of stuff while debugging and forget to remove it. "Ok so what exception is being thrown. I'll write a try catch and see. Problem solved" but you forget to remove the catch statement.
Does any one know of a nice solution so you can debug but ensure that this sort of rubbish doesn't end up going out the door.
"You get that on the big jobs."
|
|
|
|
|
#if DEBUG
#endif
Not very clean, but somewhat safer.
'As programmers go, I'm fairly social. Which still means I'm a borderline sociopath by normal standards.' Jeff Atwood
'I'm French! Why do you think I've got this outrrrrageous accent?' Monty Python and the Holy Grail
|
|
|
|
|
|
|
Does any one know of a nice solution so you can debug but ensure that this sort of rubbish doesn't end up going out the door.
Only by using pre-compilation tags like #Const and #if-then-else. Set your constant to one value (say True) while debugging, then set it to False as you wind down debugging. C has a similiar capability with a few more options, and I used to use this facility to allow trace statements to appear during development and disappear at time of release simply by changing the value of a constant.
|
|
|
|
|
One developer I worked with used to like
Assert(DateTime.Now < new DateTime(2011, 10, 1))
He'd check stuff in and it would break in QA a few days later.
|
|
|
|
|
OMG - I can't think many coding faux pas worse than that - fingers/hammer combination seems to be all I can recommend - I see you are in the States so hopefully I will never have to work with him
|
|
|
|
|
|
A friend of mine wrote this little pearl a while ago. When I took the keyboard and wrote "true", we laughed for a good 5 mins. ...the next step was getting rid of the crazy infinite loop.
while(Convert.ToBoolean(1))
{
}
|
|
|
|
|
while(true) is one of my pet hates.
"You get that on the big jobs."
|
|
|
|
|
Why?
Oxfords English < Official CCC Players Dictionary
Excuse me for my improper grammar and typos.
It's because English is my primary language, not my first language.
My first languages are C# and Java.
VB, ASP, JS, PHP and SQL are my second language.
Indonesian came as my third language.
My fourth language? I'm still creating it, I'll let you know when it's done!
|
|
|
|
|
while(true) isn't self-documenting
while(true)
{
.... lots of code
if(drunk) break;
drinkBeer();
.... lots more code
}
I much prefer
while(!drunk)
{
.... lots of code
drunk = true;
if(drunk) continue;
drinkBeer();
.... lots more code
}
Although its probably just the drink beer bit I really like
"You get that on the big jobs."
|
|
|
|
|
RobCroll wrote: while(true) isn't self-documenting
Guess that's where comments comes in handy.
RobCroll wrote:
while(true)
{
.... lots of code
if(drunk) break;
drinkBeer();
.... lots more code
}
I much prefer
while(!drunk)
{
.... lots of code
drunk = true;
if(drunk) continue;
drinkBeer();
.... lots more code
}
I'm a fan of while(true) but the first is simply garbage, I never used it like that.
Oxfords English < Official CCC Players Dictionary
Excuse me for my improper grammar and typos.
It's because English is my primary language, not my first language.
My first languages are C# and Java.
VB, ASP, JS, PHP and SQL are my second language.
Indonesian came as my third language.
My fourth language? I'm still creating it, I'll let you know when it's done!
|
|
|
|