Click here to Skip to main content

The Weird and The Wonderful

   

The Weird and The Wonderful forum is a place to post Coding Horrors, Worst Practices, and the occasional flash of brilliance.

We all come across code that simply boggles the mind. Lazy kludges, embarrasing mistakes, horrid workarounds and developers just not quite getting it. And then somedays we come across - or write - the truly sublime.

Post your Best, your worst, and your most interesting. But please - no programming questions . This forum is purely for amusement and discussions on code snippets. All actual programming questions will be removed.

 
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page  Show 
RantOh no, not again....memberJacek Gajek12hrs 26mins ago 
Another two (three?) hours spent on this kind of typo:
public int LoadedSampleCount
        {
            get { return (int)GetValue(LoadedSampleCountProperty); }
            set { SetValue(LoadedSampleCountProperty, value); }
        }
        public static readonly DependencyProperty LoadedSampleCountProperty =
            DependencyProperty.Register("LoadedSampleCount", typeof(int), typeof(TreeWindowVM SampleSetLoaderVM), new PropertyMetadata(0));
This is a result of a "GUI refactoring" -- moving parts of code to an user control. And forgetting to set an owner of a dependency property to a new model view again. Awww... Mad | :mad: Mad | :mad:
Greetings - Jacek

GeneralFound something interestingmemberBotCar23 May '13 - 22:08 
Just came across the following in some code I maintain:
 
foreach (Object item in group)
{
// Some code...
int i = 1;
string key = "SomeString_" + i.ToString();
// Some more code...
}
 
I suspect the idea was to use i to help make the dictionary keys unique.
GeneralWhy not: // just shoot me!memberesaulsberry20 May '13 - 8:48 
try
{
    account.Save();
}
catch { ; } //Not good!
Mad | :mad:
GeneralRe: Why not: // just shoot me!memberPualee20 May '13 - 10:14 
At least there are comments.
GeneralRe: Why not: // just shoot me!protectorOriginalGriff20 May '13 - 11:02 
I can think of a few comments myself...
The universe is composed of electrons, neutrons, protons and......morons. (ThePhantomUpvoter)

GeneralRe: Why not: // just shoot me!memberPankaj Nikam20 May '13 - 19:26 
Guess programmer was hungry thats why he "ate" the exception Big Grin | :-D
Always Keep Smiling.
Yours Pankaj Nikam

GeneralRe: Why not: // just shoot me!memberOshtri Deka20 May '13 - 22:15 
Relax.
This is just sweeping under the rug.
 

It could be worse.
Mislim, dakle jeo sam.

GeneralRe: Why not: // just shoot me!memberGary Wheeler21 May '13 - 1:17 
I'm impressed they wasted the energy on a surplus semicolon.
Software Zen: delete this;

GeneralRe: Why not: // just shoot me!memberenglebart21 May '13 - 2:39 
They might have a style rule that enforces:
"catch block cannot be empty"
 
Warning: Empty catch block.
 
ftfy: ";"
GeneralRe: Why not: // just shoot me!memberGary Wheeler21 May '13 - 2:48 
... which just demonstrates how misleading style enforcement can be.
Software Zen: delete this;

GeneralRe: Why not: // just shoot me!memberesaulsberry21 May '13 - 2:59 
Big Grin | :-D What kills me is the comment. It would have taken the same effort to say Logger.Log(ex);
GeneralRe: Why not: // just shoot me!memberagolddog21 May '13 - 3:35 
I'm trying (in vain so far) to think up any scenario where the context around this might make this o.k. For example, something like:
 
int pageIndex = 0;
try {
    pageIndex = int.TryParse(Request[pageNum])
} catch (Exception e) {
    Logger.info("Page Index of " + Request[pageNum] + " invalid, using " + pageIndex.ToString());
}
 
(Of course, I'd use Int.TryParse instead and null-check the request variable)
 
But, you get the idea--some scenario where you can continue to operate with default data given an unexpected condition. I can't think of any situation where the missing context makes it o.k. to swallow an exception trying whatever a Save operation does.
GeneralRe: Why not: // just shoot me!memberesaulsberry21 May '13 - 3:40 
In this case it's just plain sloppy, lazy, and wrong. It should log and throw, allowing the error to propagate to the global error handler. The object's been validated so if the save fails it's a critical failure somewhere in the system, like the database is down. Eating the error when a save fails is never the right thing to do. The user blissfully goes about their business because the save "worked" but it didn't. Wrong, wrong, wrong.
GeneralRe: Why not: // just shoot me!memberStatementTerminator21 May '13 - 3:51 
I can think of situations where it might be appropriate to do something like that.
 
For instance, suppose you are implementing a "like" button or something similar. It's not critical that it works and let's assume that it's unreliable for reasons beyond the programmer's control, like maybe it depends on an external service which is not always available.
 
So in that case maybe it's OK to swallow the exception since it's not unusual and nothing will really break if it fails, so you just silently fail and the user can try again if they want. There aren't many situations like this in programming though, and you still should probably log the exceptions.
 
I'm pretty sure that something like account.Save() is a bit too important to treat this way, though.
GeneralRe: Why not: // just shoot me!memberJacek Gajek24 May '13 - 0:02 
StatementTerminator wrote:
implementing a "like" button or something similar. It's not critical that it works

Man, people split up because of a 'like' button. You don't 'like' in time -- you loose. It IS crtical. Roll eyes | :rolleyes:
Greetings - Jacek

GeneralRe: Why not: // just shoot me!memberStatementTerminator24 May '13 - 3:49 
That's OK, people who care about "like" buttons should be ostracized anyway.
 
On a side note, if I hear someone at my organization say one more time that our site needs to be more like Facebook, I'm going to garrote myself with a Cat5 cable.
GeneralRe: Why not: // just shoot me!memberJacek Gajek24 May '13 - 11:36 
Well, CP seems to go in that direction, too... It is a matter of time when it becomes "CodeBook". If it makes you feel better, I can vote you down Laugh | :laugh:
Greetings - Jacek

GeneralRe: Why not: // just shoot me!memberStatementTerminator21 May '13 - 3:43 
Looks to me like the original programmer was too lazy to handle an exception, and another programmer came along and added the helpful "Not good!" comment, and left it like that. I don't know which programmer to hate more.
 
Five bucks says that account.Save() has a return value indicating success.
JokeRe: Why not: // just shoot me!memberRafagaX21 May '13 - 5:02 
Well if saving doesn't work now, it could work later... Poke tongue | ;-P
CEO at:
- Rafaga Systems
- Para Facturas
- Modern Components
for the moment...

GeneralRe: Why not: // just shoot me!memberKP Lee21 May '13 - 13:06 
RafagaX wrote:
Well if saving doesn't work now, it could work later...
Oh, yea! Really user friendly. I ask to save, it works fine. Except I don't know if it worked or not. So now I've got to retrieve the data. If it is retrieved, fine, it worked. If not, then I get to save again and then check again and...
GeneralRe: Why not: // just shoot me!membersparkytheone21 May '13 - 9:59 
If in the account class the Save method looked like this there might be a scenario where the eating of exceptions is fine:
 
try
{
// Some code to save the record to the db
....
}
catch(Exception ex)
{
logger.Log(ex);
throw;
}
GeneralRe: Why not: // just shoot me!memberPablo Aliskevicius22 May '13 - 3:19 
I've read somewhere that this code is equivalent to:
try
{
    // account.Save(); // If this can fail silently, then why bother?
}
catch { ; } //Not good!
 
Then again, a LART would be more educational. Wink | ;)
Pablo.
 
"Accident: An inevitable occurrence due to the action of immutable natural laws." (Ambrose Bierce, circa 1899).

GeneralRe: Why not: // just shoot me!memberesaulsberry22 May '13 - 3:21 
A fantastic point.
GeneralCan't people read the form description anymore?memberRob Grainger16 May '13 - 3:20 
I notice that a fair few of the recent posts here seem out of place.
 
Can't people read?
 
ps. I guess that by posting this, I now have to include myself in that category, but I'm hoping to be indulged.
"If you don't fail at least 90 percent of the time, you're not aiming high enough."
Alan Kay.

GeneralRe: Can't people read the form description anymore?professionalPIEBALDconsult16 May '13 - 4:21 
Two wrongs don't make a right. Roll eyes | :rolleyes:

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   


Advertise | Privacy | Mobile
Web04 | 2.6.130523.1 | Last Updated 25 May 2013
Copyright © CodeProject, 1999-2013
All Rights Reserved. Terms of Use
Layout: fixed | fluid