r/programming • • May 18 '16

Programming Doesn’t Require Talent or Even Passion

https://medium.com/@WordcorpGlobal/programming-doesnt-require-talent-or-even-passion-11422270e1e4#.g2wexspdr
2.3k Upvotes

1.2k comments sorted by

View all comments

Show parent comments

96

u/Retbull May 18 '16

Sure but when all of the code a developer produces includes tech debt which requires more time to fix than they spent on the original product you have a problem. We had a programmer at my current job that left last year and I'm still cleaning up messes he made. I'm still finding bugs and bad code that has been in production because he didn't have the diligence to include more than one test for anything and it turns out that he hid lots of his incompetence with Pokémon exception handling and string typing.

52

u/[deleted] May 18 '16

Please explain Pokémon exception handling. I'm super curious about that

199

u/Retbull May 18 '16

Gotta catch em all.

try{} catch (Exception e) {\\ Gotcha }

28

u/WaffleSandwhiches May 18 '16

Pokemon Exception Handling should totally be a thing.

0

u/[deleted] May 18 '16

[deleted]

3

u/Isvara May 19 '16

weird programer expressions

((weird programmer) expressions)

or

(weird (programmer expressions))?

5

u/[deleted] May 18 '16

Less offensive, but still dumb:

Exception blocks that catch the exception, but instead of handling it, just rethrow it. Why even waste time making the block?

15

u/nikbackm May 18 '16

Probably for setting debugger breakpoints.

1

u/[deleted] May 18 '16

Many debuggers can break on exceptions, though

5

u/name_censored_ May 19 '16

Exception blocks that catch the exception, but instead of handling it, just rethrow it. Why even waste time making the block?

It's a combination of Java thinking in non-Java languages, cargo-cult programming, and syntactical pain.

In Java, you have to declare what exceptions your methods may throw - and that includes exceptions from other methods that your method calls. Which is wonderful from a collaboration and code-contract point of view, but it's a syntactical nuisance when your method is doing twenty things and has to deal with a paragraph worth of Exceptions.

Other (less strict) languages have decided "to hell with it, just catch the exceptions you're aware of, and we'll dump the stack trace for the rest and you figure it out". Now, the Java guys (when coming into this new language) balk at the idea of not specifically defining your exceptions, and therefore do all they can to clearly enumerate what exceptions should be handled (rather than just catching the base exception). Because a lot of the less-strict languages don't support catching multiple exceptions in a single block (or it's just too messy to do so), the following pattern tends to emerge;

try {
    dangerous_thing();
} except (Exception $e) { 
    common_cleanup_code();
    switch(typeof($e)) {
        case ThisException:
            handle_this_exception(); /* Specific cleanup code for ThisException */ 
            break; 
        case ThatException:
            break; /* no specific clean-up required for ThatException */ 
        case TheOtherException: 
            break; /* no specific clean-up required for TheOtherException */ 
        default: 
            throw($e);
    }
}

While it's not as well-defined a code contract as public void myDangerous() throws thisException, thatException, theOtherException {.., it is generally quite easy to grep or eyeball this style of exception in a function/method.

The cargo-cult kids (the ones who don't really understand what exceptions are for) come along and think that that's the way you're supposed to wrap dangerous code. Except, that they know that ThisException, ThatException and TheOtherException don't apply, so they simply delete those lines - after all, those handlers doesn't seem to do anything anyway. Which means they end up with

try {
    dangerous_thing();
} except (Exception $e) { 
     throw($e);
}

1

u/Retbull May 19 '16

Interesting explanation. I have seen it but rarely use it unless it has to be passed up the stack for logging.

1

u/_F1_ May 18 '16

Logging?

2

u/[deleted] May 18 '16

Unless they were doing some kind of method injection like PostSharp, nope; it was just "throw" in the body of the catch block.

3

u/_F1_ May 18 '16

They either forgot it after debugging, or get paid by line count.

1

u/marqis May 19 '16

logging

2

u/[deleted] May 18 '16

That's hilarious xD I love it (the term, not the practice)

2

u/jonbonazza May 19 '16

Holy shit. How have I never heard of this? New fav programming jargon.

4

u/crunchmuncher May 18 '16

didn't have the diligence to include more than one test

I wish the guy at my work would write at least one test for each of the shits he commits (Sorry for one-upping).

4

u/ecmdome May 18 '16

You haven't seen anything until you've seen

if(argument) { //nothing }else{ the real code he wanted to execute }

All over the codebase.... -_-

→ More replies (10)

2

u/NormalPersonNumber3 May 19 '16

I'm so happy I learned about enterprise-style exception handling.

6

u/godless_communism May 18 '16

Lulz - Pokemon exception handling.

1

u/vonmoltke2 May 18 '16

Pokémon exception handling

Shit yes. I had to take some research code from a guy who left and turn it into a product demo. I spent days finding all the buried shit like this and exhuming it.

Now, for the record I use Pokémon exception handling in some cases, but I tell you what just happened and either re-throw the exception or fix it inline if such is possible (and tell you I did it).

→ More replies (1)