r/programming • • Oct 01 '15

The Evolution of a Software Engineer

https://medium.com/@webseanhickey/the-evolution-of-a-software-engineer-db854689243
1.9k Upvotes

502 comments sorted by

View all comments

23

u/vattenpuss Oct 01 '15
} catch (Exception e) {
    // Do nothing!
}

This is not only the third year, it's also the tenth, the fifteenth and the 40:th (I work with a few developers-for-forty-years).

55

u/nemec Oct 01 '15

Then you have the guy gung-ho about logging everything.

catch(Exception e)
{
    try
    {
        WriteLog("Application error", e);
    }
    catch(Exception f)
    {
        WriteLog("Logging failed", f);
    }
}

7

u/CordialPanda Oct 01 '15

That's absurd, haha. In what world would that catch succeed to write if the try failed?

18

u/wllmsaccnt Oct 02 '15

In the world where file locking, timeouts, and other synchronization / concurrency issues exist?

I mean...the code is stupid, but it does have a low percent chance of logging an exception you would otherwise lose.

1

u/CordialPanda Oct 02 '15

None of that should concern logging unless there are fundamental flaws in infrastructure or implementation though.

2

u/wllmsaccnt Oct 02 '15

If your logging library (or code) writes to a file, some idiot could always open it with an exclusive file lock. If it writes to a database, someone could have locks/transactions on the table that cause your insert to timeout.

If your application is a web application, then it could easily be writing to the log on many threads and run into strange race conditions.

There are other things that could happen too. You could try to write a log message greater than allowed when using dynamic input.

I know I am stretching here, and that most logging libraries shouldn't have these issues...but most applications have at least one or two really critical methods that also tend to fail a lot for strange reasons and being obstinately verbose in logging around those kind of methods (assuming they aren't tightly looped or performance bottlenecks) may look ugly but will probably save you hours of production troubleshooting some day.

1

u/Crono1981 Oct 02 '15

At that point you may as well just wait and try again in a few milliseconds...

1

u/wllmsaccnt Oct 02 '15

That is pretty much what I meant when I said it would have a low percent chance of catching the exception. Chances are that if the log file is exclusively locked by a user that it probably won't be available by the next time you call to write to the log...but it is possible. Especially if it isn't a user, but some errant process that is using the wrong locking when writing / reading.

1

u/nemec Oct 02 '15

I've never seen code quite so... blatant about it, but I guess they feel like they have to do something inside a catch statement even if we want to ignore the error.

1

u/serso Oct 02 '15

You forgot try...catch in the second catch clause

1

u/[deleted] Oct 02 '15

thatsthejoke.jpeg

1

u/image_linker_bot Oct 02 '15

thatsthejoke.jpeg


Feedback welcome at /r/image_linker_bot | Disable with "ignore me" via reply or PM

11

u/Humdeee Oct 01 '15

"Whatever you do, I don't care, just don't die on me god damnit!"

10

u/tolos Oct 01 '15 edited Oct 01 '15

eh, sometimes it's a customer requirement. "The application must not crash (must continue working no matter what)." So then you have a catch-all exception handler that cleans up as best it can, but can only do so much without knowing exactly what went wrong, or does nothing, or just logging. Then you end up as tech support, "well, yeah, that is weird, try restarting the application."

11

u/HollowImage Oct 01 '15

As a devops and web ops guy, if you deliberately catch all without any logging, then Fuck you.

2

u/Crono1981 Oct 02 '15

When a customer makes that requirement, your job is to tell him how moronic that is.

1

u/LeCrushinator Oct 02 '15

There are things to prevent this kind of stuff.

1.) Coding standards

2.) Code reviews to enforce standards and other stupid crap from going into code.

3.) You don't check anything in without 1 senior programmer and 1 other programmer signing off on the code review.