• milestogofromhere.com (unregistered)

    this is hilarious...coming from a VB shop, that is how a lot of people I woked with would have done it.

  • Morbii (unregistered)

    lol

  • blah (unregistered)

    I'm not a VB programmer, but the code at the bottom looks wrong.  It doesn't handle the radio case , IRadioButtonControl.

  • Mike J (unregistered) in reply to Morbii

    Hah, I'm glad she left the original code in there, though it needs a long comment in the same tone about learning the language you're trying to develop in.

    'Way To Go Programmers !!! 'Gotta love these programmers who don't KNOW 'wtf language they're trying to develop in. 'but you know, 10 minutes of reading would just be 'TOO hard wouldn't it?!

  • Joe (unregistered)

    5th?

  • X (unregistered) in reply to Morbii

    O.O.Doh!!

  • YAYitsAndrew (unregistered)

    Even the clean solution looks like garbage to me, but I doubt that's the fault of the submitter.

  • Rafial (unregistered) in reply to Mike J

    The solution may have been a tad sub-optimal, but the original programmers gripe has merit...

  • Michael (unregistered) in reply to blah

    ICheckBoxControl is an interface. Both the checkbox and radiobutton implement it. I.e., anything that is "checkable" is checked by the replacement code.

                 --Michael
    
  • DSx (unregistered) in reply to blah
    Anonymous:
    I'm not a VB programmer, but the code at the bottom looks wrong.  It doesn't handle the radio case , IRadioButtonControl.


    The radio button control extends the checkbox control.
  • diaphanein (unregistered)
    Alex Papadimoulis:

    Dim thisControl As Control = FindControl(controlName)
    If Not thisControl Is Nothing AndAlso TypeOf (thisControl) Is ICheckBoxControl Then
      CType(thisControl, System.Web.UI.ICheckBoxControl).Checked = True
    End If

    IMHO, the above code is also a WTF.  The type of the control is being checked twice.  The below C# is the best way of doing the above logic.

    ICheckBoxControl c = FindControl(controlName) as ICheckBoxControl;
    if (c != null) c.Checked = true;

    Not having used VB.Net, I'm not sure if it has an equivalent to the 'as' operator, but it doesn't, its a crime against .Net.

  • (cs)

    Based on the comment I expected to see code along the lines of:

    if (checkbox)

          checkboxobject.checked = true;

    else if (radio button)

       radiobuttonobject.checked = selected;

  • nimrand (unregistered) in reply to blah

    Actually, the second block of code is correct as far as checking the control's type, because RadioButton implements the ICheckBox interface (the 'I' in the name is .NET's naming convention for interfaces).  So, testing for that interface would succeed on both radio buttons and checkboxes.  This only makes the original programmer's taunt all the more hilarious, because you DON'T need to know which of the two types of controls it is to access its Checked property.  You simply access it through the interface, which is why the interface is there in the first place.

  • DSx (unregistered) in reply to diaphanein
    Anonymous:
    Alex Papadimoulis:

    Dim thisControl As Control = FindControl(controlName)
    If Not thisControl Is Nothing AndAlso TypeOf (thisControl) Is ICheckBoxControl Then CType(thisControl, System.Web.UI.ICheckBoxControl).Checked = True End If

    IMHO, the above code is also a WTF.  The type of the control is being checked twice.  The below C# is the best way of doing the above logic.

    ICheckBoxControl c = FindControl(controlName) as ICheckBoxControl;
    if (c != null) c.Checked = true;

    Not having used VB.Net, I'm not sure if it has an equivalent to the 'as' operator, but it doesn't, its a crime against .Net.



    Off the top of my head, i would think that this code would throw an exception if controlName was not a CheckBox or RadioButton, while her code would fail gracefully.
  • John Hensley (unregistered)

    'hay guys micro$oft sux am i rite?


  • Talonius (unregistered) in reply to DSx
    Anonymous:
    Anonymous:
    Alex Papadimoulis:

    Dim thisControl As Control = FindControl(controlName)
    If Not thisControl Is Nothing AndAlso TypeOf (thisControl) Is ICheckBoxControl Then CType(thisControl, System.Web.UI.ICheckBoxControl).Checked = True End If

    IMHO, the above code is also a WTF.  The type of the control is being checked twice.  The below C# is the best way of doing the above logic.

    ICheckBoxControl c = FindControl(controlName) as ICheckBoxControl;
    if (c != null) c.Checked = true;

    Not having used VB.Net, I'm not sure if it has an equivalent to the 'as' operator, but it doesn't, its a crime against .Net.



    Off the top of my head, i would think that this code would throw an exception if controlName was not a CheckBox or RadioButton, while her code would fail gracefully.

    Nah, the "as" keywords attempts to convert to the requested type.  If the attempt fails no exception is thrown; instead, null is returned.  Thus his check for null on the second line.

     

  • diaphanein (unregistered) in reply to DSx
    Anonymous:
    Anonymous:
    Alex Papadimoulis:

    Dim thisControl As Control = FindControl(controlName)
    If Not thisControl Is Nothing AndAlso TypeOf (thisControl) Is ICheckBoxControl Then CType(thisControl, System.Web.UI.ICheckBoxControl).Checked = True End If

    IMHO, the above code is also a WTF.  The type of the control is being checked twice.  The below C# is the best way of doing the above logic.

    ICheckBoxControl c = FindControl(controlName) as ICheckBoxControl;
    if (c != null) c.Checked = true;

    Not having used VB.Net, I'm not sure if it has an equivalent to the 'as' operator, but it doesn't, its a crime against .Net.



    Off the top of my head, i would think that this code would throw an exception if controlName was not a CheckBox or RadioButton, while her code would fail gracefully.

    Nope - the as operator returns null if the type cast cannot be completed.  From http://msdn.microsoft.com/library/en-us/csref/html/vclrfAs.asp?frame=true:

    The as operator is like a cast except that it yields null on conversion failure instead of raising an exception. More formally, an expression of the form:

    expression as type

    is equivalent to:

    expression is type ? (type)expression : (type)null

    except that expression is evaluated only once.

    Note that the as operator only performs reference conversions and boxing conversions. The as operator cannot perform other conversions, such as user-defined conversions, which should instead be performed using cast expressions.

     

  • (cs)

    Anyone who would ok Vb.NET for corporate development is the true loser here.  Years back when .net came out I was able to sucessfully move all of my VB6 programmers over to C# in a matter of days.  After about a month working with C# I sent one of my programmers a VB6 program to fix a bug and he almost quit on me, begrudgingly he pulled up VB6 and went to work on it.   Then he decided that perhaps we were making a bad decision moving everything over to C# instead of VB.net (he thought losing VB skills was a bad thing) so he took a course on VB.net, after the course he agreed with me C# was the way to go.  Everytime I see VB.net code I am thoroughly reminded I made the right choice.

     

     

  • Willie (unregistered) in reply to DSx

    The C# 'as' operator will return null if it can't successfully cast its operand.

  • mike5 (unregistered)

    Gotta love a language that has "AndAlso" operator...

    Cheers, Mike5

  • Subversion Rocks (unregistered)

    This is why I use SubVersion now everywhere.  Anytime I see someone checking in bullshit like that get's caught, tagged and released.  I usually also prepend in the XML comments something like:


    /*        
    * CCCC RRRRR AAA PPPPP
    * CC RR RR AA AA PP PPP
    * CC RRRRR AA AA PPPPP
    * CC RRRR AAAAA PP
    * CC RR RR AA AA PP
    * CCCC RR RR AA AA PP
    *
    * Architecture Violation Removed
    * By: {programmer name}
    * Hours spent refactoring: X.XX
    *
    */

  • (cs)
    Alex Papadimoulis:
    
    
    <span style="color: rgb(0, 0, 255);">Case</span> <span style="color: rgb(0, 0, 255);">Else</span>
      strCtrlId = Trim(ctrl.ID.ToString)
    


    Not to mention ctrl.ID is already a String!
  • JS (unregistered)

    Simple rule: Whenever you think the people that designed the framework you're using are idiots, it's probably you who is the idiot.

  • KeithSpook (unregistered) in reply to e.thermal
    e.thermal:

    Anyone who would ok Vb.NET for corporate development is the true loser here....  ...Everytime I see VB.net code I am thoroughly reminded I made the right choice.

     

    Correct.  Vb.NET is an attempt at a programming language, and it is a bad business decision to write web applications in a programming language (or an attempt thereof).

  • Andrew Hare (unregistered) in reply to e.thermal
    e.thermal:

    Anyone who would ok Vb.NET for corporate development is the true loser here.  Years back when .net came out I was able to sucessfully move all of my VB6 programmers over to C# in a matter of days.  After about a month working with C# I sent one of my programmers a VB6 program to fix a bug and he almost quit on me, begrudgingly he pulled up VB6 and went to work on it.   Then he decided that perhaps we were making a bad decision moving everything over to C# instead of VB.net (he thought losing VB skills was a bad thing) so he took a course on VB.net, after the course he agreed with me C# was the way to go.  Everytime I see VB.net code I am thoroughly reminded I made the right choice.


    That's stupid, its all the .NET framework.  There are only a handful of things that you can do in c# that you cannot do in vb.net.  Explain to me which aspects of c# would be neccesary to prevent production from grinding to a halt if you were forced to use vb?
  • (cs) in reply to KeithSpook
    Anonymous:
    e.thermal:

    Anyone who would ok Vb.NET for corporate development is the true loser here....  ...Everytime I see VB.net code I am thoroughly reminded I made the right choice.

     

    Correct.  Vb.NET is an attempt at a programming language, and it is a bad business decision to write web applications in a programming language (or an attempt thereof).



    Two of the most moronic, ignorant posts I've ever seen here ... which is actually quite an impressive achievement at this site.

    I hope at least one of these is sarcasm.
  • Anonymaly (unregistered) in reply to Andrew Hare

    Andrew Hare:
    Explain to me which aspects of c# would be neccesary to prevent production from grinding to a halt if you were forced to use vb?

    In my opinion, a cleaner, more elegant and more easily readable syntax.

  • (cs) in reply to mike5

    mike5:
    Gotta love a language that has "AndAlso" operator...

    Yeah, that kind of threw me. What's the difference between "AndAlso" and "And"? Does it have something to do with lazy vs strict evaluation?

  • Gene Wirchenko (unregistered) in reply to Jeff S

    gotta love these comments

    Sincerely,

    Gene Wirchenko

     

  • Anonymaly (unregistered) in reply to Snagglepuss
    Snagglepuss:

    mike5:
    Gotta love a language that has "AndAlso" operator...

    Yeah, that kind of threw me. What's the difference between "AndAlso" and "And"? Does it have something to do with lazy vs strict evaluation?

    It's a "bitwise" And versus the "logical" And with left-to-right associativity with early drop-out from expression evaluation if any of the terms on the left evaluate to false.

  • KeithSpook (unregistered) in reply to Jeff S
    Jeff S:
    Anonymous:
    e.thermal:

    Anyone who would ok Vb.NET for corporate development is the true loser here....  ...Everytime I see VB.net code I am thoroughly reminded I made the right choice.

     

    Correct.  Vb.NET is an attempt at a programming language, and it is a bad business decision to write web applications in a programming language (or an attempt thereof).



    Two of the most moronic, ignorant posts I've ever seen here ... which is actually quite an impressive achievement at this site.

    I hope at least one of these is sarcasm.


    Yes, I would say that mine is sarcasm.  I would think that most people would have caught that.  Sorry I over estimated... I'll never do it again.
  • (cs) in reply to JS

    Anonymous:
    Simple rule: Whenever you think the people that designed the framework you're using are idiots, it's probably you who is the idiot.

    Idunno... implementing short-circuit boolean evaluation as an unintuitive "AndAlso" seems pretty idiotic to me.

              -dZ.

     

  • (cs)

    The funny part is how they've confused an attribute of the type system with the object oriented paradigm.  There are dynamically-typed OO languages where they could write code like this that would function.  Ruby and Smlltalk are just two examples.

  • Anonymaly (unregistered)

    BTW, there is nothing wrong with the re-written VB.NET code.  The ICheckBoxControl interface (which only exists in .NET Framework 2.0) is implemented by the CheckBox class.  The RadioButton class, in turn, derives from the CheckBox class, therefore, inherits the interface.  Both RadioButton and Checkbox, in turn, have a Checked property.

    Given an instance of an object, the 'Is' comparison operator is used to determine if it can be coerced to an ICheckBoxControl interface.  If so, the code then changes the type (equivalent to a C# cast or similarly the C# as operator) to the interface and sets the 'Checked' property.  Nice, clean, and obviously object-oriented.

  • (cs) in reply to KeithSpook
    Anonymous:
    Jeff S:
    Anonymous:
    e.thermal:

    Anyone who would ok Vb.NET for corporate development is the true loser here....  ...Everytime I see VB.net code I am thoroughly reminded I made the right choice.

     

    Correct.  Vb.NET is an attempt at a programming language, and it is a bad business decision to write web applications in a programming language (or an attempt thereof).



    Two of the most moronic, ignorant posts I've ever seen here ... which is actually quite an impressive achievement at this site.

    I hope at least one of these is sarcasm.


    Yes, I would say that mine is sarcasm.  I would think that most people would have caught that.  Sorry I over estimated... I'll never do it again.


    Whew ... thank you, Keith !   The problem with this site is you have to be really clear when you are being sarcastic .... some of the posts I've seen here are pretty frightening!  (e.g., the one you quoted and responded to)
  • (cs) in reply to mike5
    Anonymous:
    Gotta love a language that has "AndAlso" operator...

    Cheers, Mike5


    That's the first time you'll hear this athiest say Amen.
  • WangTF (unregistered) in reply to DZ-Jay
    DZ-Jay:

    Anonymous:
    Simple rule: Whenever you think the people that designed the framework you're using are idiots, it's probably you who is the idiot.

    Idunno... implementing short-circuit boolean evaluation as an unintuitive "AndAlso" seems pretty idiotic to me.

              -dZ.

    AndAlso would seem to be more intuitive than ||.  I think the whole point of this WTF is you should learn the language before criticizing it.

  • (cs) in reply to Vector
    Vector:
    Anonymous:
    Gotta love a language that has "AndAlso" operator...

    Cheers, Mike5


    That's the first time you'll hear this athiest say Amen.


    We've covered this a million times here.  They left "And" as a non-shortcurcuting operator for backwards compatability with previous versions of VB.  They added "AndAlso" to introduce a short-circuiting And operator to VB.NET.   Same with "Or" and "OrElse".

    You can say that maybe the names are a little silly, or they could have used symbols like in C#, but if you don't understand it, don't criticise it.
  • (cs) in reply to Andrew Hare

    The main thing (besides the fucking god-awful syntax that makes me want to vomit blood forever) that drove me to C# was the lack of commenting support -- VB.NET (as supported in VS.NET 2003) does not support XML comments without a VS plug-in. 

    /sarcasm?

  • (cs) in reply to Anonymaly
    Anonymous:

    Andrew Hare:
    Explain to me which aspects of c# would be neccesary to prevent production from grinding to a halt if you were forced to use vb?

    In my opinion, a cleaner, more elegant and more easily readable syntax.

    Interesting.  I find VB.NET to be more closely related to actual language... by far.  I started in C++ and found myself continually pulling my hair out due to braces and semicolons.

    More elegant?  Why?  Because it makes you feel like you're programming a space shuttle?

    Cleaner?  Why?  Is this not due to the programmer's abilities?

    I'm always hearing why everyone should use C# instead of that "toy language" VB.NET, and I never hear why.  AndAlso, I've found I can accomplish the same tasks in both languages in the same amount of time. 

  • Anonymaly (unregistered) in reply to WangTF
    Anonymous:

    AndAlso would seem to be more intuitive than ||.  I think the whole point of this WTF is you should learn the language before criticizing it.

    Of course "AndAlso" would be much more intuitive than "||".  That's because "||" actually maps to "OrElse" in VB.NET.  Yes, I knew you meant "&&".  However, both those operators are 'mnemonics'.  I prefer using a mnemonic; to me, it makes the code seem less verbose or 'busy'.

  • (cs)

    I'm just excited that the submission was made by a woman. Three cheers for smart chicks!!!

    p.s. fake Gene Wirchenko, you've got to do better than that if you aspire to Wirchenkism.

  • Emmanuel D. (unregistered) in reply to WangTF
    Anonymous:

    AndAlso would seem to be more intuitive than ||.  I think the whole point of this WTF is you should learn the language before criticizing it.



    It would also be better, considering that || is more like "or" than like "and"... :P
  • Anonymaly (unregistered) in reply to Pope
    Pope:
    Anonymous:

    Andrew Hare:
    Explain to me which aspects of c# would be neccesary to prevent production from grinding to a halt if you were forced to use vb?

    In my opinion, a cleaner, more elegant and more easily readable syntax.

    Interesting.  I find VB.NET to be more closely related to actual language... by far.  I started in C++ and found myself continually pulling my hair out due to braces and semicolons.

    More elegant?  Why?  Because it makes you feel like you're programming a space shuttle?

    Cleaner?  Why?  Is this not due to the programmer's abilities?

    I'm always hearing why everyone should use C# instead of that "toy language" VB.NET, and I never hear why.  AndAlso, I've found I can accomplish the same tasks in both languages in the same amount of time. 

    Whoah there Cowboy.  I did remember to note that it was my opinion.  No, I do not find that it feels remotely anything like programming a "space shuttle"; that's quite an odd comparison.

    However, having used assembly language, C and C++ for quite some time, I have become accustomed to mnemonics and terse reprentation of complex expressions without the need for it to read like "Green Eggs and Ham".

    It was a matter of becoming accustomed to that programming style.  Learning C# has made me more productive "out of the box".  Having used Visual Basic 6.0 for quite some time, I can read VB.NET as well --it just hurts my eyes.

  • Fake Gene Wirchenko (unregistered) in reply to januarys

    ok, I admit it, it was fake. But I always wanted to be like Gene Wirchenko when I grow up. He is my role model and inspiration. 

    Sincerely,

    Fake Gene Wirchenko

  • (cs) in reply to Pope
    Pope:
    Anonymous:

    Andrew Hare:
    Explain to me which aspects of c# would be neccesary to prevent production from grinding to a halt if you were forced to use vb?

    In my opinion, a cleaner, more elegant and more easily readable syntax.

    More elegant?  Why?  Because it makes you feel like you're programming a space shuttle?

    Cleaner?  Why?  Is this not due to the programmer's abilities?

    I find c#/c++/java/anything not VB cleaner and more elegant because it is less verbose, using brackets instead of words for delimiting blocks.  I also think "WEnd" is totally unnecessary.

     

     

     

     

  • Brian Kemp (unregistered) in reply to diaphanein

    Nope - the as operator returns null if the type cast cannot be completed.  From http://msdn.microsoft.com/library/en-us/csref/html/vclrfAs.asp?frame=true:

    The as operator is like a cast except that it yields null on conversion failure instead of raising an exception. More formally, an expression of the form:

    expression as type

    is equivalent to:

    expression is type ? (type)expression : (type)null

    except that expression is evaluated only once.

    Note that the as operator only performs reference conversions and boxing conversions. The as operator cannot perform other conversions, such as user-defined conversions, which should instead be performed using cast expressions.

     

    The best part is that the as operator seems to just do the try-catches for you...well, it feels like it.  There's noticable lag in my debugger when I get a null result from an as operator, which would be the exception being thrown then caught before your code ever sees it.

    C# version of the code:

    Control thisControl = FindControl(controlName);
    if (thisControl != null && thisControl is ICheckBoxControl)
    {
        ((ICheckBoxControl)(thisControl)).Checked = True;
    }
  • (cs) in reply to Anonymaly
    Anonymous:
    Anonymous:

    AndAlso would seem to be more intuitive than ||.  I think the whole point of this WTF is you should learn the language before criticizing it.

    Of course "AndAlso" would be much more intuitive than "||".  That's because "||" actually maps to "OrElse" in VB.NET.  Yes, I knew you meant "&&".  However, both those operators are 'mnemonics'.  I prefer using a mnemonic; to me, it makes the code seem less verbose or 'busy'.

    That's a really interesting point... like being able to pick out numbers on a page of text because they stand out when imbedded in regular text.  Hmm.  Thanks.

  • (cs) in reply to wintermyute

    wintermyute:
    VB.NET (as supported in VS.NET 2003) does not support XML comments without a VS plug-in. 

    //open up a connection to the database server

    WTF does that say?

    //<comment>open up a connection to the database server</comment>

    Ahhh ... so much clearer ...

     

    (Yes, I know what you meant -- just a joke)

  • (cs) in reply to januarys
    januarys:

    I'm just excited that the submission was made by a woman. Three cheers for smart chicks!!!



    I second your base sentiment, but it's wrong of you to associate programming with "smarts". This industry does suffer from sausagefestivess.

Leave a comment on “Way To Go O.O.!”

Log In or post as a guest

Replying to comment #:

« Return to Article