Comment On Avoiding the Exception

"I found this interesting tidbit while making some changes to a .NET application," Tim Kowalski writes. [expand full text]
« PrevPage 1 | Page 2Next »

Re: Avoiding the Exception

2010-06-30 11:02 • by Griphon (unregistered)
Moving on

Re: Avoiding the Exception

2010-06-30 11:04 • by almost first (unregistered)
almost first

Re: Avoiding the Exception

2010-06-30 11:04 • by frosttt (unregistered)
try {
"frist"
} catch(NotFristException) exception {
Response.Redirect("second.aspx");
}

Re: Avoiding the Exception

2010-06-30 11:06 • by Knux2 (unregistered)
A little talkative, isn't he?
Fixed:


catch (Exception ex)
{
CommonLoggerHelper.DumpException(ex);
Response.Redirect("default.aspx"); //Lazy, loses all user's quiz answers
}

Re: Avoiding the Exception

2010-06-30 11:08 • by Ocson (unregistered)
It is perhaps in our best interests to have interesting things to say in the comments. It is said that nine tenths of TDWTF time should be spent reading the WTF, but I find myself spending nine tenths of the time writing comments. So all I have to say for this is a big LOL. I feel a little dirty, but time grows short and I must move on.

Re: Avoiding the Exception

2010-06-30 11:11 • by Yaos
I imagine he asked himself, "Should I take the time to write the code to remember the users answers, or should I just write a long rambling explanation on why I won't?"

:10bux: says there is already information stored per user and he was too stupid to use it.

Re: Avoiding the Exception

2010-06-30 11:13 • by wbiz (unregistered)
i feel dirty and lazy too

Re: Avoiding the Exception

2010-06-30 11:14 • by Antony Koch (unregistered)
I like the fact that his diatribe is massive, talking about exceptional circumstances such as server resets and what not, all the while handling these exceptional circumstances by, well, not handling them appropriately.

captcha: secundum - latin for the "wtf?" part of reading bad code.

Re: Avoiding the Exception

2010-06-30 11:14 • by TheCPUWizard
313373 in reply to 313370
To me the key element is "Since this is simply a tutorial application". If it is NOT intended to ever be used in a production environment (i.e. as a "real" application), this approach is warranted.

Look at the code samples that sip with products, that appear in magazines, appear in blogs, etc. It is extremely rare that the code is "production quality".

At least the author has indicated in the comments what some of the issues with the "tutorial" implementation are.

Now if this became a production code base, then WTF!

Re: Avoiding the Exception

2010-06-30 11:15 • by Bob (unregistered)
"Since this is simply a tutorial application"...

...the WTF probably lies with someone other than the author of the comments.

Re: Avoiding the Exception

2010-06-30 11:17 • by Whiskey, Eh? (unregistered)
Simple explanation: he is being paid per line of code written. Somehow, in his company, that includes comments.

Re: Avoiding the Exception

2010-06-30 11:18 • by Ken B. (unregistered)
I think what he really meant to say is:

/*

* I get paid using the LOC method of productivity,
* so I need to come up with more "L"s.
*/

Re: Avoiding the Exception

2010-06-30 11:18 • by Maurits
TRWTF is using Response.Redirect("default.aspx") rather than Response.Redirect("./"). default.aspx should never be linked to or redirected to explicitly, just implicitly. (Posting to default.aspx is another matter due to IIS's insane "no posting to a default document" rule.)

Re: Avoiding the Exception

2010-06-30 11:18 • by Bob (unregistered)
See:

http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/Q_23108345.html

Re: Avoiding the Exception

2010-06-30 11:19 • by Ozz (unregistered)
tl;dr

Re: Avoiding the Exception

2010-06-30 11:21 • by re:me (unregistered)
313380 in reply to 313373
TheCPUWizard:
To me the key element is "Since this is simply a tutorial application". If it is NOT intended to ever be used in a production environment (i.e. as a "real" application), this approach is warranted.

Look at the code samples that sip with products, that appear in magazines, appear in blogs, etc. It is extremely rare that the code is "production quality".

At least the author has indicated in the comments what some of the issues with the "tutorial" implementation are.

Now if this became a production code base, then WTF!


I didn't take it as the application itself was a tutorial on programming, rather that it is something like a CBT app.

Re: Avoiding the Exception

2010-06-30 11:23 • by Anonymous (unregistered)
Adequate explanatory comments play a fundamental role in fostering a codebase that is easy to update and maintain. But seriously, we don't need your life story. If your comment has a word-count comparable to the average novella then you've provided too much detail.

I especially like the way this coder references his other comments, almost as though he wants us to go trawling through other code files so we can piece together his complete odyssee. I think he'd be better off writing fiction than code.

Re: Avoiding the Exception

2010-06-30 11:31 • by Jim (unregistered)
313383 in reply to 313382
Anonymous:
Adequate explanatory comments play a fundamental role in fostering a codebase that is easy to update and maintain. But seriously, we don't need your life story. If your comment has a word-count comparable to the average novella then you've provided too much detail.

I especially like the way this coder references his other comments, almost as though he wants us to go trawling through other code files so we can piece together his complete odyssee. I think he'd be better off writing fiction than code.


Even better would be a Choose-Your-Own-Odyssey following many possible routes through all of the comments in the codebase

Re: Avoiding the Exception

2010-06-30 11:36 • by Steve (unregistered)
Oh, I've seen this type of coder before. This type of coder is not the best at writing actual code but is great at making excuses as to why it's OK to not write the code. Long rambling comments that basically amount to "I should be doing some real work here but it's awfully tricky so here is an unnecessarily verbose explanation as to why it's OK to skip it so I can get on with something simple like making icons". This type of coder is easily identified by the ratio of functional lines to commented lines, as well as the vacant look on his face. His most commonly used design pattern is:

// TODO

Re: Avoiding the Exception

2010-06-30 11:39 • by Buddy (unregistered)
Oh yeah, done the easy way out.

OLAP::~OLAP()

{
::CloseHandle(connection);

// Let the OS deal with the memory deallocations
// Lazy, I know...
}


Re: Avoiding the Exception

2010-06-30 11:42 • by Anonymous (unregistered)
313386 in reply to 313383
Jim:
Anonymous:
Adequate explanatory comments play a fundamental role in fostering a codebase that is easy to update and maintain. But seriously, we don't need your life story. If your comment has a word-count comparable to the average novella then you've provided too much detail.

I especially like the way this coder references his other comments, almost as though he wants us to go trawling through other code files so we can piece together his complete odyssee. I think he'd be better off writing fiction than code.


Even better would be a Choose-Your-Own-Odyssey following many possible routes through all of the comments in the codebase

"If you want to know why the developer hasn't implemented a proper logging framework, turn to page LogUtils.cs."

"If you want to know why the developer hasn't implemented exception handling, turn to page ErrorHandler.cs."

"If you want to get some work done, fire the developer then turn to page Form1.cs."

Re: Avoiding the Exception

2010-06-30 11:43 • by Goo (unregistered)
I'd solve it differently. First, I'd write this:

//todo: make sure that we don't lose any of the answers if this is triggered.

And then hope another programmer has the will and the free time to add a bonus database layer that is only read from when the main db crashes along with its failover, and sets something up so that the data is persistent across sessions.

So, in essence, If someone has an Starfleet Engineering mentality, who thinks they can't live without a secondary backup, it'll get fixed. If not, I can say I warned them all, and they didn't listen.

Re: Avoiding the Exception

2010-06-30 11:43 • by Ryan (unregistered)
So... It sounds like somebody cut and pasted some tutorial code directly into a production environment. Awesome.

Re: Avoiding the Exception

2010-06-30 11:51 • by Steve A (unregistered)
Try Catch is for sissies!

Re: Avoiding the Exception

2010-06-30 11:54 • by SeySayux (unregistered)
Okay, I heard of projects with a lack of documentation, but this? Seriously? I'd like to hire that guy right now. He'd never have to write one piece of code. Brilliant. Just brilliant. A peer to Shakespeare.

Re: Avoiding the Exception

2010-06-30 11:54 • by Brian follower of Deornoth
313392 in reply to 313384
One of my former colleagues took this technique to the logical conclusion: he wrote only comments, and no code at all. It transpired this was because he didn't know anything about the language he was ostensibly coding in. The ghastly truth was revealed on the day of the code review; he didn't turn up, and was never seen again.

They were beautiful comments, though.

Re: Avoiding the Exception

2010-06-30 11:55 • by verisimilidude (unregistered)
313393 in reply to 313375
Whiskey, Eh?:
Simple explanation: he is being paid per line of code written. Somehow, in his company, that includes comments.

Any good metrics program tracks the number of comment lines. This guy was short for the week and added a weeks worth to the exception block that had to be put in when his code tried to dereference a null object. Now his per cent comment lines will be right on target.

Re: Avoiding the Exception

2010-06-30 11:58 • by frits
If the rest of the application is coded reasonably defensively, I'm not sure what he's going on about. The biggest mistake I can see is not generating a error message so the user knows why he just lost his answers. If a database connection is lost, or some other database problem happens, that's an exceptional situation. Log it, display it, and move on. Let the testers and the customers report real world failures.

Re: Avoiding the Exception

2010-06-30 12:03 • by Resuna (unregistered)
313395 in reply to 313373
That was my reaction, too. The real WTF is that someone seems to have taken a tutorial and put it into production without finishing the "exercises for the reader" part of the tutorial.

Re: Avoiding the Exception

2010-06-30 12:10 • by DaveyDaveDave
313396 in reply to 313395
Resuna:
That was my reaction, too. The real WTF is that someone seems to have taken a tutorial and put it into production without finishing the "exercises for the reader" part of the tutorial.


Agreed. Although I kind of hope that he/she typed it all out from an actual dead-tree book. :)

Re: Avoiding the Exception

2010-06-30 12:20 • by ysth (unregistered)
or other database malladies occur


Bad girl, down!

Re: Avoiding the Exception

2010-06-30 12:23 • by blah (unregistered)
TRWTF is he didn't return Boolean.FileNotFound;

Re: Avoiding the Exception

2010-06-30 12:39 • by BSDPwns (unregistered)
cookies....

Re: Avoiding the Exception

2010-06-30 12:57 • by EmperorOfCanada (unregistered)
The comment is a bit long but sometimes I see developers solving hard problems of little worth in the same time they could have solved dozens of small but important problems.

An example would be one I saw who solved a series of rather hard spacing problems between FF and IE when they needed to solve the problem of IE people not being able to log in.

Re: Avoiding the Exception

2010-06-30 12:58 • by Gary (unregistered)
goggling around I see a few versions of this floating about -- i notice that the example on experts-exchange is VB.net but the example here is C#- which implies that someone actually went and changed their ' to // or vice versa?

immitto - "imma immitto somethin righnow"

Re: Avoiding the Exception

2010-06-30 13:03 • by Luis Espinal (unregistered)
313407 in reply to 313373
TheCPUWizard:
To me the key element is "Since this is simply a tutorial application". If it is NOT intended to ever be used in a production environment (i.e. as a "real" application), this approach is warranted.


Uhhhh, not if the user has to pay to get the quiz or he has something to lose, like a grade or something, or the quiz is long and it is imperative to get users' input.

If this is an application that 1) users have to pay for (or spend a considerable time getting through it) or 2) the owner has an incentive to get it out to users, and 3) you get paid to write it and maintain it, it is production, it is real

Sorry man, but bad software engineering is bad software engineering.

I mean, how hard it is to save state between pages or questions? People do it all the time successfully. There are so many approaches it's not even funny. It's not rocket science on a tight schedule.

Don't know the context of this application, but with all things being equal, that wall of comment is just an attempt of CYOA rather than a pragmatic hack under duress.


TheCPUWizard:
Look at the code samples that sip with products, that appear in magazines, appear in blogs, etc.


In 15 years, I've only seen that, like probably four or five times. It is not that common.

TheCPUWizard:
It is extremely rare that the code is "production quality".


Uh, depends on where you work and who you work with. I'll grant that no software if bug free, but from there to say few pieces of code is "production quality" is a bit of a stretch.

TheCPUWizard:
At least the author has indicated in the comments what some of the issues with the "tutorial" implementation are.


He really didn't explain anything. He simply created a wall of text to poorly justify his wtf.

TheCPUWizard:
Now if this became a production code base, then WTF!


Apparently it is. Just because it's not a financial transaction system, that does not make it a toy or non-production.

Re: Avoiding the Exception

2010-06-30 13:03 • by Mike (unregistered)
The real WTF is that he will never revisit the code and fix it unless there are complaints that it's broken. And then I'll be the guy working there who has to deal with it.

Re: Avoiding the Exception

2010-06-30 13:05 • by Tim Notsir (unregistered)
"Redirect" in all its incarnations is TRWTF.

A URL is supposed to be a Uniform Resource Locator (see http://en.wikipedia.org/wiki/URL )

So when your site visitor requests a resource, you give it to them, or, if that is not possible, explain why in response to the original request.

All a "redirect" accomplishes is telling the browser "ooh your naughty user asked for foo when he should have asked for blargh, try again!" at which point the browser (probably) obediently returns asking for blargh, which you already knew was going to be the answer, but you refused to give it on the first request, so here we go all over again.

This cargo-cult copycat obsession with redirecting people all over the place has led to the web we know and love today, where most of your bookmarks to things you really care about are broken. For example, I want to see how my tdwtf stock is doing. I should be able to choose my bookmarked link to my brokerage's "today's gain/loss" page. But oh noes I'm not logged in. So instead of giving me a login form then and there which, when submitted back to the same URL, would result in what I originally asked for, I get redirected to "the one and only true login page". By the time I finish logging in the site has usually forgotten my original request so I end up at some stupid marketing page. Or maybe that's on purpose...

Re: Avoiding the Exception

2010-06-30 13:08 • by CodeNinja (unregistered)
At least it's well commented.

Re: Avoiding the Exception

2010-06-30 13:08 • by Lines of Clue (unregistered)
313411 in reply to 313376
Ken B.:
I think what he really meant to say is:

/*

* I get paid using the LOC method of productivity,
* so I need to come up with more "L"s.
*/
I thought the "C" in "LOC" stood for code not comments!

Re: Avoiding the Exception

2010-06-30 13:11 • by Sir Ruam (unregistered)
313412 in reply to 313377
Maurits:
TRWTF is using Response.Redirect("default.aspx") rather than Response.Redirect("./"). default.aspx should never be linked to or redirected to explicitly, just implicitly. (Posting to default.aspx is another matter due to IIS's insane "no posting to a default document" rule.)

IIS's insane

Simplified that for you...

But yes, you're right. If you design so that all your URLs end in / you won't have to break the entire freaking web when you decide to upgrade from .aspx to .whatever

Re: Avoiding the Exception

2010-06-30 13:24 • by Benjamin Franz (unregistered)
313414 in reply to 313409
When a site is reorganized it makes no sense to tell a *user* clicking on a link that the page isn't there anymore. You tell the search engines (301) and send the user to the best available location as transparently as possible.

And yes, that is a reasonable interpretation of "URLs are forever".

Re: Avoiding the Exception

2010-06-30 13:29 • by Worse (unregistered)
313415 in reply to 313373
TheCPUWizard:
To me the key element is "Since this is simply a tutorial application". If it is NOT intended to ever be used in a production environment (i.e. as a "real" application), this approach is warranted.

Look at the code samples that sip with products, that appear in magazines, appear in blogs, etc. It is extremely rare that the code is "production quality".

At least the author has indicated in the comments what some of the issues with the "tutorial" implementation are.

Now if this became a production code base, then WTF!


Tutorial code should show good practices. That makes this even worse. If you're [sic] code doesn't even work, then why should I learn from you?

Re: Avoiding the Exception

2010-06-30 13:32 • by tentux (unregistered)
Something tells me that resetting the server will probably result in a lost session making the whole rant unnecessary in the first place.

Re: Avoiding the Exception

2010-06-30 13:40 • by seriously (unregistered)
313418 in reply to 313378
Bob:
See:

http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/Q_23108345.html


how did you know that existed? that's kind of nuts

Re: Avoiding the Exception

2010-06-30 13:46 • by Trick (unregistered)
What about error reporting??

Re: Avoiding the Exception

2010-06-30 13:49 • by boog (unregistered)
313421 in reply to 313384
Steve:
Oh, I've seen this type of chatterbox before. This type of chatterbox is not the best at writing actual code but is great at making excuses as to why it's OK to not write the code. Long rambling comments that basically amount to "I should be doing some real work here but it's awfully tricky so here is an unnecessarily verbose explanation as to why it's OK to skip it so I can get on with something simple like making icons". This type of chatterbox is easily identified by the ratio of functional lines to commented lines, as well as the vacant look on his face. His most commonly used design pattern is:

// TODO


FTFY

Re: Avoiding the Exception

2010-06-30 13:50 • by JohnWestMinor
TRWTF is his continued use of "//" instead of using "/* ... */" blocks.

Re: Avoiding the Exception

2010-06-30 13:51 • by what are you talking about (unregistered)
313423 in reply to 313418
seriously:
Bob:
See:

http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/Q_23108345.html


how did you know that existed? that's kind of nuts


google it you fucking moron.

Re: Avoiding the Exception

2010-06-30 13:56 • by Luis Espinal (unregistered)
313425 in reply to 313423
what are you talking about:
seriously:
Bob:
See:

http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/Q_23108345.html


how did you know that existed? that's kind of nuts


google it you fucking moron.


Easy tiger.
« PrevPage 1 | Page 2Next »

Add Comment