Enable/disable controls the stupid ways



  • http://www.codeproject.com/useritems/Enable_Disable_Controls.asp

    How many WTFs can you find in this code? Here's some I found:

    He casts control objects to specific class to call Enabled property on them which is available in the Control class. No need to do any casting.

    No support for custom controls containing other controls. Should be handled recursively.

    Only works on Web forms, not Windows forms.



  • Also, he creates new objects and drops them out of scope on every iteration of the loop.  If nothing else, that's a bit of bad form.
     



  • The sad thing is that the project I'm working on has a far, far worse method.



  • And so the pattern will continue. Someone goes to Codeproject, thinks they're learning something, and learns this cr@p. Next thing you know, it's in a codebase somewhere. This one reminds me of this old WTF post: http://worsethanfailure.com/Articles/Way_To_Go_O_0x2e_O_0x2e_!.aspx

     

    The Real WTF is being the least bit surprised when discovering crap on Codeproject. It's like finding crap in a cow pasture. 



  • Looks like this listing is gonna be nuked. It's been moved to "purgatory":

     

    http://www.codeproject.com/Purgatory/Enable_Disable_Controls.asp



  • That site is just so overflowing with "developers" who are desperate to see their names on a tech article someplace. There's nothing, absolutely NOTHING about disabling controls on a page that warrants an article. Even if the code was flawless, does something as simple as disabling controls, in a single sub, deserve an article?

    We may as well have whole articles on integer math, string formatting, hello world, etc.

    This really musta been this guy's first .NET Sub that worked, and he was just soooooo excited about it. 

     

     



  • To be fair you have to note the site's "This is an unedited reader contribution" tag and the article rating as well though. Looks like the site has at least some self cleaning capabillities left in contrast of a certain other site.



  • For Textboxes, setting ReadOnly to true instead of Enabled to false could be preferable in many cases (at least in WinForms).

    So, if done better, at least some of those IFs could be used for a good thing. Of course the author of the codeproject article failed to do that.



  • @bstorer said:

    Also, he creates new objects and drops them out of scope on every iteration of the loop.  If nothing else, that's a bit of bad form.
     

     

    Its also a memory leak waiting to happen. 



  • Admittedly, I've never really worked in C#, but I fail to see any memory leaks here.  The stuff he creates is all on the stack, which should be removed when it goes out of scope.  Also, C# is garbage collected anyway.



  • @unklegwar said:

    That site is just so overflowing with "developers" who are desperate to see their names on a tech article someplace. There's nothing, absolutely NOTHING about disabling controls on a page that warrants an article. Even if the code was flawless, does something as simple as disabling controls, in a single sub, deserve an article?

    We may as well have whole articles on integer math, string formatting, hello world, etc.

    This really musta been this guy's first .NET Sub that worked, and he was just soooooo excited about it. 

    This is how most code bloat happens. "I worked hard to come up with this, therefore everyone should be using it, regardless of whether there's a system library that already does it better."



  • @bstorer said:

    Admittedly, I've never really worked in C#, but I fail to see any memory leaks here.  The stuff he creates is all on the stack, which should be removed when it goes out of scope.  Also, C# is garbage collected anyway.

    Exactly. No new objects are created, just existing objects are casted. 



  • @PSWorx said:

    To be fair you have to note the site's "This is an unedited reader contribution" tag and the article rating as well though. Looks like the site has at least some self cleaning capabillities left in contrast of a certain other site.

     

    I think they all say that. I've never seen one that doesn't. No one edits those. It's like a giant supermarket post-it board.

     



  • @bstorer said:

    Also, he creates new objects and drops them out of scope on every iteration of the loop.  If nothing else, that's a bit of bad form.
     

     

    No objects are created in that code. What code are U reading?

     



  • A-HA!

     

    As if that site didn't already have enough crap flowing in, here's a sure way to get a ton of extra worthless submissions: A CONTEST!

     

    http://www.codeproject.com/script/competitions/monthly/

     

    It's like offering a reward for info leading to the capture of Big Bird. Suddenly every wacko has seen a large yellow avian. 



  • @unklegwar said:

    @bstorer said:

    Also, he creates new objects and drops them out of scope on every iteration of the loop.  If nothing else, that's a bit of bad form.
     

     No objects are created in that code. What code are U reading?

     

    Correct.  What I should have said is "references to objects", or even simply "variables". 



  • should have said...could have said...but didn't have the brain to say...maybe bstorer is idiot number 2. has to have the diff between creating an object and creating a ref pointed out.



  • @unklegwar said:

    We may as well have whole articles on integer math, string formatting, hello world, etc.

    plz send me teh articlez



  • @gochai said:

    should have said...could have said...but didn't have the brain to say...maybe bstorer is idiot number 2. has to have the diff between creating an object and creating a ref pointed out.

     

    Nice first post.  Bstorer has posted enough quality stuff here that he's earned the right to have some slack cut.  I notice however that prior to this troll you have posted the square root of fuck all.



  • <font color="#cc0000" size="7">Did nobody notice that this post is over 1 year old?</font>



  • @Ryde said:

    The sad thing is that the project I'm working on has a far, far worse method.
    No!  Please don't tell us what it is!  I want to wait until I see it myself!

    EDIT:  That'll show me to post a response before I read the whole thread.  Thanks Morbz


Log in to reply
 

Looks like your connection to What the Daily WTF? was lost, please wait while we try to reconnect.