|
The memorial of the never-written-code... with exception-handling
(yes|no|maybe)*
|
|
|
|
|
As a consultant I share your pain.
GibbleCH wrote: Tons of duplicated code. Crazy amounts of dead code (~30-50%)
sounds like it would be quicker to re-write
|
|
|
|
|
Ultimately that was the result. But using lots of unit tests and refactoring to do so. Less error prone, and I was able to ensure functionality remained consistent where it was correct. And some bits of the app did work...
|
|
|
|
|
I see the opposite way to often too...
Private Sub DoSomething
Try
Catch ex As Exception
End Try
A Try Catch block with no code does no harm, this however...
Perhaps the empty Catch is also VB6 inspired... OnErrorResumeNext
It's an OO world.
|
|
|
|
|
Naerling wrote: Perhaps the empty Catch is also VB6 inspired... OnErrorResumeNext
Is it just me or everytime someone talks about bad code, "VB" shows up?
"To alcohol! The cause of, and solution to, all of life's problems" - Homer Simpson
|
|
|
|
|
I blame VB 1, 2 and 3.
I was a toddler at that time so I wouldn't know, but this is what I heard.
VB became object oriented at version 4, but to be backwards compatible MS had to support the non-object oriented style.
As a result many VB programmers kept on programming like they always did and still do so today.
Why not C#? Because the first C# came at around the same time as VB4 and was object oriented right from the start.
On a side note, try to call any PUBLIC member of a Form in VB without having an instance of the Form. It will work, you can call them as if they were Shared (static). I recently found out and was shocked, backwards compatibility with VB1...
Anyway, I don't really blame VB, I blame the programmers who were not willing to learn object orientism right after VB3
Does that sound about right or am I really way off here?
It's an OO world.
|
|
|
|
|
Naerling wrote: VB became object oriented at version 4
Not fully, still lacked lots of OO principles, even VB 6 (like something as basic as inheritance).
Naerling wrote: I blame the programmers who were not willing to learn object orientism right
after VB3
I actually seen that in action on VB.Net.
Naerling wrote: Does that sound about right or am I really way off here?
Yes, it does. But in my opinion that's not the full story and the full story about all the VB infame does not apply to everyone and to all scenarios. But yes, the word VB gives me goose bumps, specially when I learn I have to work with existing code.
"To alcohol! The cause of, and solution to, all of life's problems" - Homer Simpson
|
|
|
|
|
I had to work with lots of existing VB code... Code that goes as far back as being coded in VB6 and imported to .NET (when I started to learn programming there I learned from seeing what NOT to do)
Luckily my hard studies got me to a point where my boss actually lets me write new classes and libraries for every programmer in the company (that's 4 people including me...) to use (and yes, I am one of those VB programmers who DOES know what an Interface (other than GUI) is and how to use it)
It's an OO world.
|
|
|
|
|
Naerling wrote: my boss actually lets me write new classes and libraries for every programmer in
the company to use
Now, that's really cool. It's a very nice role to have.
Naerling wrote: and yes, I am one of those VB programmers who DOES know what an Interface (other than GUI) is and how to use it
Some may consider you a mythical character
"To alcohol! The cause of, and solution to, all of life's problems" - Homer Simpson
|
|
|
|
|
Fabio Franco wrote: Some may consider you a mythical character
Thanks!
It's an OO world.
|
|
|
|
|
Fabio Franco wrote: Is it just me or everytime someone talks about bad code, "VB" shows up?
It's just you - the worst code was (and may still be) written in C/C++ by former BASIC, COBOL, and FORTRAN programmers still new to Dykstra's "GoTo Considered Harmful" dictum...which didn't prevent them from abusing every feature in the language. I spent years cleaning such code, and still don't think I got everything fixed the way it should be (e.g. readable).
BASIC, COBOL, and FORTRAN all allowed really bad code to be developed, real "spaghetti" code, but recasting the same engineering in C (or, worse by two or three orders of magnitude in this age of templates, C++) permits monstrosities to be created that even the coders may not be able to understand after a month or two working on other projects. Worse, with macros, you can make C/C++ look like BASIC or FORTRAN...perhaps even COBOL, though I've never seen anyone sick enough to try that (yes, I've seen examples of the other two practices, and it just makes you ill to see it if you ever loved C).
As for On Error Resume Next....what other language system can anyone name that is as ubiquitous as BASIC, COBOL, FORTRAN, or C that allowed a non-in-line interrupt-style error handler to be constructed? Yes, the only one that comes to my mind, as well, is BASIC. On Error GoTo was a huge advance for its time; On Error Resume Next was, really, just a way to allow "old-fashioned" error handling (checking output variables and return values for error conditions) to be used or not. Most of the cocks-of-the-progamming-walk who complain about the foibles of this feature just weren't around to complain about it in 1968 when Dartmouth BASIC was released; if it seems a dated feature now, well, OF COURSE IT IS.
Hmmm, does this count as a rant?
|
|
|
|
|
cpkilekofp wrote: Hmmm, does this count as a rant?
Oh definitely . Please don't take this personally
cpkilekofp wrote: the worst code was (and may still be) written in C/C++
Nobody said that the worse code seen was in VB. The joke was about how often the name Ugly Betty comes up whenever we are talking about ugly girls.
"To alcohol! The cause of, and solution to, all of life's problems" - Homer Simpson
|
|
|
|
|
There was tons of that in there too. Along with lots of catch blocks that broke the call stack by throwing a new, useless error message.
|
|
|
|
|
|
I think the guy created a function body to copy for other functions. That would save him writing the exception handling block over and over again when a new function is added. No coding horror, though it might look like one at first view.
|
|
|
|
|
Copying the exception handling over and over again would be a coding horror anyway. The exception should generally be caught in only a few places in the top tier.
|
|
|
|
|
There are easier ways
[ctrl][k][x] try [enter]
or
try[tab][tab]
even if you have already written the code- select code and
[ctrl][k][s] try [enter]
|
|
|
|
|
Maybe he didn't know about code snippets....
|
|
|
|
|
I find it brilliant. 100% bug-free!
|
|
|
|
|
I feel your pain. I've just finished going through a similar process. After a while you stop getting annoyed and start laughing. The one that made me laugh most was:
public class OrderName
{
public String getName {
return "Order";
}
}
That was the class in totality. One method that returned a hard coded value.
[EDIT] I just found a better one:
for (int i = 1; i < 2; i++) {
}
"You get that on the big jobs."
modified on Sunday, August 14, 2011 10:23 PM
|
|
|
|
|
Reminds me of things like this...
for (int i = 0; i < 5; i++) {
switch (i) {
case 1: {
}
case 2: {
}
case 3: {
}
case 4: {
}
case 5: {
}
default: {
}
}
}
|
|
|
|
|
This code feels like some Zen koan or something..
If a tree falls in the forest but no one is around, does it make a noise?
|
|
|
|
|
|
Reminds me of an application I support that had the following gem in it.
Not only was this method called only once in the entire solution, but apparently someone "forgot" to code anything in it. I'm sure this isn't the first time someone has seen this one, too.
private bool IsValid()
{
return true;
}
I wasn't, now I am, then I won't be anymore.
|
|
|
|
|
I've actually done something like this (but never left it in the production code) on a rapidly evolving piece of a class. The purpose behind it is that you originally start out with a method with let's say, 100 lines of code, then the person that was driving the requirements no longer wants the checking, so you go back, and in order to test your entire application quickly without refactoring, you throw the "return true" in there.
Not saying it isn't stupid to allow something like that to end up in production, just saying I've actually done it before for quick testing.
|
|
|
|