Make sure this value is returned...
-
Hi all, I was already reading this forum when it was still called the "Hall of shame". I've got a product to maintain that was created by a developer who is no longer working for us. Even though I've already seen plenty of "hall of shame worthy" code there, I've have never posted it here, because it would have been my first post on CP ever and I thought it is a bad idea to say hello to a community while bashing an ex colleague. However, I came across a piece of code that I can't keep for myself and so I'll do what I didn't want to do and bash in my first post: At the end of a long method I found this one:
try
{
return true;
}
catch (Exception)
{
return false;
}Cheers, cmger
-
Hi all, I was already reading this forum when it was still called the "Hall of shame". I've got a product to maintain that was created by a developer who is no longer working for us. Even though I've already seen plenty of "hall of shame worthy" code there, I've have never posted it here, because it would have been my first post on CP ever and I thought it is a bad idea to say hello to a community while bashing an ex colleague. However, I came across a piece of code that I can't keep for myself and so I'll do what I didn't want to do and bash in my first post: At the end of a long method I found this one:
try
{
return true;
}
catch (Exception)
{
return false;
}Cheers, cmger
Welcome to posting on CP. :) I hope that there used to be more code in the try catch that would give it a reason to be there. Even if there used to be code that justified the try, when that code was removed the try/catch should have also been removed. This is another fine example of code that might work, but really isn't good code, hence my sig. :)
Just because the code works, it doesn't mean that it is good code.
-
Welcome to posting on CP. :) I hope that there used to be more code in the try catch that would give it a reason to be there. Even if there used to be code that justified the try, when that code was removed the try/catch should have also been removed. This is another fine example of code that might work, but really isn't good code, hence my sig. :)
Just because the code works, it doesn't mean that it is good code.
Thanks for the welcome! :-) Nope, there was never anything more in there. At least as far as I can tell from the source control system. I found out that there is only one place where the method is used and there the return value is just ignored. I re-factored the method to return void an removed the block completely. Now there is only the code that preceded the try catch.
-
Thanks for the welcome! :-) Nope, there was never anything more in there. At least as far as I can tell from the source control system. I found out that there is only one place where the method is used and there the return value is just ignored. I re-factored the method to return void an removed the block completely. Now there is only the code that preceded the try catch.
Maybe it was some kind of skeleton for logic to be inserted in the try-catch block later? However, it should've been preceded by a comment at least.
cmger wrote:
I found out that there is only one place where the method is used and there the return value is just ignored.
Rejoice, for you got away easily! :laugh: :laugh: It could've been a lot worse ;)
Full-fledged Java/.NET lover, full-fledged PHP hater. Full-fledged Google/Microsoft lover, full-fledged Apple hater. Full-fledged Skype lover, full-fledged YM hater.
-
Thanks for the welcome! :-) Nope, there was never anything more in there. At least as far as I can tell from the source control system. I found out that there is only one place where the method is used and there the return value is just ignored. I re-factored the method to return void an removed the block completely. Now there is only the code that preceded the try catch.
-
I am not surprised that there was never any useful code there, just disappointed. :sigh: I really hate it when programmers return a value that serves no purpose. :mad:
Just because the code works, it doesn't mean that it is good code.
-
Welcome to posting on CP. :) I hope that there used to be more code in the try catch that would give it a reason to be there. Even if there used to be code that justified the try, when that code was removed the try/catch should have also been removed. This is another fine example of code that might work, but really isn't good code, hence my sig. :)
Just because the code works, it doesn't mean that it is good code.
-
Welcome to posting on CP. :) I hope that there used to be more code in the try catch that would give it a reason to be there. Even if there used to be code that justified the try, when that code was removed the try/catch should have also been removed. This is another fine example of code that might work, but really isn't good code, hence my sig. :)
Just because the code works, it doesn't mean that it is good code.
My guess is that this was "skeleton" code that the coder copy pasted but forgot to fill.