• anon (unregistered) in reply to diaphanein
    Anonymous:

    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;

    And even that looks like it has redundancy. The C++ equivalent would be

    dynamic_cast< ICheckBoxControl& >( FindControl( controlName ).Checked = true ;

    and the unlikely error case would be handled by the exception mechanism. Somehor I get the feeling, Dijkstra was right all along and (Visual) Basic rots the mind.

  • Iago (unregistered) in reply to anon

    The point is that the C# version stands alone - it never raises an exception at all.  Whereas your single line of C++ actually needs wrapping in a try...catch block, which leaves it ending up MORE verbose than the C#, not less.

  • MB (unregistered) in reply to OneFactor

    The VB.NET compiler will actually return Nothing (for object types) or the default val (for value types) if you don't provide an explicit return. I'd suspect that C# would too, but that there's a compiler option to treat that warning as an error. Obviously, if at runtime you try to call methods and properties on a null reference, you will get a NullReferenceException no matter what language your IL was compiled from (though in VB, shouldn't that be a NothingReferenceException?). FYI, VB.NET 2005 will also warn you (by default - you can also treat it as an error) on not returning a value. As for "adding or omitting parentheses" [that results in syntax errors, not logic errors] and being allowed to compile - I have no idea what you mean there, and without a sample, I don't believe it. Unless maybe you're late binding and the methods you want don't exist (which is a programmer WTF, not the language. Though it should be off by default.)

  • (cs) in reply to Subversion Rocks
    Anonymous:
    This is why I use SubVersion now everywhere.  Anytime I see someone checking in bullshit like that get's caught, tagged and released.


    Wow, you mean Subversion can automatically detect bad code upon checking in? That's a bad ass version control system you got there.
  • (cs)

    Sarcasm mode ON.

    There's nothing wrong with that! You know those pesky M$ API programmers always make mistakes... Who can be sure that

    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

     

    and specially that obscure "FindControl" routine works as expected?.

    Oh, and also... RTTI is BAD and SLOW! Shitty "TypeOf"! Bleh!

    Let him re-create the entire API! Blame M$ on not opening it's source code!

    SARCASM MODE OFF

    Cheers!

    Guido, from Las Palmas de Gran Canaria, Spain

  • Pooma (unregistered) in reply to taryn
    Taryn
    gender = female (just to be clear).


    Eeek, don't go making assignments to gender around here!  You'll only confuse the poor lambs with your possible trans-gender ability!
  • (cs) in reply to EsotericMoniker
    EsotericMoniker:


    We should write apps the good old fashioned way, carrying our bits from the database over to the web server one at a time... uphill... both ways... in the snow...   And we like it that way!

    You forgot; "... and doing it only with zeroes (ones making it waaaay to easy and modern)..."

    ("Quoted" from Dilbert)
  • Ben (unregistered) 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.

    I agree, much cleaner and easier to read, but not so sure about the "grinding to a halt" comment. None Of Those Capitals Mixed Case Every Where End Sentence. It is also especially useful if you are building web applications and you use client side Javascript too. C# is very similar so it is easy to switch from one to the other. Go ECMAScript!

    Personally I think that VB.NET was simply an effort by Microsoft to not give VB programmers a heart attack when they saw the .NET Framework development environment!

    Seriously though, whatever floats your boat. The Framework will work with almost any language, so who cares. As long as I don't have to maintain COBOL, who gives a shit.

  • (cs) in reply to bullestock

    I think that the using VB.NET or C# is a religous argument, everyone will have their own belief over which is better / more concise / more maintainable / etc., however for a developer coming from a VB6 background VB.NET looks a little too familiar and doesn't encourage thinking in an OO manner despite the fact that it is a very different beast. At least if a VB6 developer moves to C# the different syntax will require them to at least pick up a book and encourage them to read up on OO principles before leaping into an "OO is crap, this used to be so much easier in VB6" train of thought.

  • zamies (unregistered)

    For me there is another WTF here.

    The existence of a keyword AndAlso
    WTF???

    LOL

  • zamies (unregistered) in reply to Jeff S
    Jeff S:
    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.


    well jeffs has got a interesting point here.

    Let me think.... Hey fellows we got to make a better language because vb6 sux bigtime.
    Yeah but what do we do with the and operator? Lets keep it old style vb6 semantics and introduce a better one wih a  different name in vb.net. Sounds like a plan, lets do it.

    Smells like dogshit to me...

  • (cs) in reply to bullestock
    bullestock:
    Anonymous:
    This is why I use SubVersion now everywhere.  Anytime I see someone checking in bullshit like that get's caught, tagged and released.


    Wow, you mean Subversion can automatically detect bad code upon checking in? That's a bad ass version control system you got there.

    I don't think so, me thinks there are a pair of guys who review every checkin/patch to the trunk.

    You can use SVN's triggers to do some (limited) automated code analysis on patches though
  • bongo (unregistered)

    I am continually amazed that people that write code like the first example even get jobs as programmers! Nobody hires a professional author without seeing what they can write first... why do companies hire programmers before seeing what they can program? I don't get it. That's the real WTF.

    And by the way, as a  someone who doesn't know VB... WTF "AndAlso"  that's gotta be a typo. You can't be serious... I mean that's like writing "PlusAddition" ... or even "EqualsSameAs"

  • (cs) in reply to Subversion Rocks

    Awesome - that's made my day that.

  • (cs) in reply to Subversion Rocks
    Anonymous:
    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
    *
    */

    By "that" I mean "this" - Brilliant

     

  • bongo (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.



    I don't know VB but I don't know what FindControl returns... if "controlName" is a parameter and this is a method then it is possible that a bad controlName could be passed to this block. In that case you couldn't know if thisControl is of the type "ICheckBoxControl" or not. So the example is an example of defensive programming. The author is defending against future morons using his method called "setCheckBox" to try and set the Checked field of an IButtonControl.

    Even if FindControl is written to only return ICheckBoxControl objects then I still wouldn't call this a WTF. We reserve that for monumentally stupid things. Things like defining true... or spending 300 lines running complex regular expressions to return the value that was passed in as a parameter exactly the way you were given it without producing any side-effects.
  • Chris (unregistered)

    Gak!  The reworked code looks like COBOL!

  • diaphanein (unregistered) in reply to makomk

    makomk:
    Hmmm... looking at that disassembly makes me wonder if perhaps you could actually get away without checking that obj != null; it looks likely that the "is" operator always returns false if called on null. Do you know if this in any way guaranteed?

    From the MS CIL docs:

    <FONT size=2>The </FONT><FONT face="Courier New" color=#000080>isinst</FONT><FONT size=2> instruction tests whether obj (type </FONT><FONT face="Courier New" color=#000080>O</FONT><FONT size=2>) is an instance of class. Class is a metadata token (a </FONT><FONT face="Courier New" color=#000080>typeref</FONT><FONT size=2> or </FONT><FONT face="Courier New" color=#000080>typedef </FONT><FONT size=2>see </FONT><FONT size=2>Partition II</FONT><FONT size=2><FONT color=#ff0000>_alink_partitionII</FONT>) indicating the desired class. If the class of the object on the top of the stack implements class (if class is an interface) or is a subclass of class (if class is a regular class), then it is cast to the type class and the result is pushed on the stack, exactly as though </FONT><FONT face="Courier New" color=#000080>castclass</FONT><FONT size=2> had been called. Otherwise NULL is pushed on the stack. If obj is NULL, </FONT><FONT face="Courier New" color=#000080>isinst</FONT><FONT size=2> returns NULL.</FONT>

    <FONT size=2></FONT> 

    <FONT size=2></FONT> 

    <FONT size=2>So, yeah, the check for null is necessary, as isinst returns either the object cast to the requested type, or null.</FONT>

  • diaphanein (unregistered) in reply to bongo
    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.



    I don't know VB but I don't know what FindControl returns... if "controlName" is a parameter and this is a method then it is possible that a bad controlName could be passed to this block. In that case you couldn't know if thisControl is of the type "ICheckBoxControl" or not. So the example is an example of defensive programming. The author is defending against future morons using his method called "setCheckBox" to try and set the Checked field of an IButtonControl.

    Even if FindControl is written to only return ICheckBoxControl objects then I still wouldn't call this a WTF. We reserve that for monumentally stupid things. Things like defining true... or spending 300 lines running complex regular expressions to return the value that was passed in as a parameter exactly the way you were given it without producing any side-effects.

    I did not disagree that the rewritten code was more correct than the original (and it appears in VB.Net the best you can do).  My stipulation is that, at least in C#, there is a better, faster, way of doing the equivalent logic.  Namely, calling FindControl (which, btw, is documented here: http://msdn2.microsoft.com/en-us/library/system.web.ui.control.findcontrol(VS.80).aspx), verifying the return value is of type ICheckBoxControl, performing the cast, and then calling the Checked setter.

     

  • diaphanein (unregistered) in reply to diaphanein
    Anonymous:

    makomk:
    Hmmm... looking at that disassembly makes me wonder if perhaps you could actually get away without checking that obj != null; it looks likely that the "is" operator always returns false if called on null. Do you know if this in any way guaranteed?

    From the MS CIL docs:

    <FONT size=2>The </FONT><FONT face="Courier New" color=#000080>isinst</FONT><FONT size=2> instruction tests whether obj (type </FONT><FONT face="Courier New" color=#000080>O</FONT><FONT size=2>) is an instance of class. Class is a metadata token (a </FONT><FONT face="Courier New" color=#000080>typeref</FONT><FONT size=2> or </FONT><FONT face="Courier New" color=#000080>typedef </FONT><FONT size=2>see </FONT><FONT size=2>Partition II</FONT><FONT size=2><FONT color=#ff0000>_alink_partitionII</FONT>) indicating the desired class. If the class of the object on the top of the stack implements class (if class is an interface) or is a subclass of class (if class is a regular class), then it is cast to the type class and the result is pushed on the stack, exactly as though </FONT><FONT face="Courier New" color=#000080>castclass</FONT><FONT size=2> had been called. Otherwise NULL is pushed on the stack. If obj is NULL, </FONT><FONT face="Courier New" color=#000080>isinst</FONT><FONT size=2> returns NULL.</FONT>

    <FONT size=2></FONT> 

    <FONT size=2></FONT> 

    <FONT size=2>So, yeah, the check for null is necessary, as isinst returns either the object cast to the requested type, or null.</FONT>

    Sorry, misread the post I quoted.  Actually, yeah - is does return false if the expression is null.  The code could be written as:

    Control c = FindControl(name);
    if (c is ICheckBoxControl)
       ((ICheckBoxControl)c).Checked = true;

    However, you still perform the typecast twice with this code, versus once when using "as".  I would think, though, that a good optimizer would be able to remove the the second cast and make the two forms identical.  

  • Craig Lipscomb (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. 



    Explain to me why curly braces and semicolons cause you to pull your hair out?  I am sure case sensitivity also caused you to pull out your hair then too.  These three things is why I love C like languages.  i had to take a VB course in college and thought it was the most awful thing i seen.  WHILE/WEND ??? IF/END???  there is no structure to that.  true its easier to read as a language, but so is c.  while () { }  makes a lot more sense, easier to see bc all blocks of code use the same things....                 
  • (cs) in reply to zamies
    Anonymous:
    Jeff S:
    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.


    well jeffs has got a interesting point here.

    Let me think.... Hey fellows we got to make a better language because vb6 sux bigtime.
    Yeah but what do we do with the and operator? Lets keep it old style vb6 semantics and introduce a better one wih a  different name in vb.net. Sounds like a plan, lets do it.

    Smells like dogshit to me...



    As I mentioned earlier, it's amazing some of the moronic ignorance out there.   What's worse is this script kiddie probably makes more than I do and will probably someday be my boss.

    What Microsoft did with VB.NET is one of the ballsiest, smartest things a big sofware company has ever done with an existing flawed, but highly successful product.  They had an extremely popular language, they recognized it's problems, and they rewrote it from scratch.  They did not cater to the beginner, but rather to creating a true, robust OOP language.   They took big chances by breaking compatabililty in lots of places to do so.   But when they could, they kept compatability with older versions of VB when it didn't inherently violate any core principles.

    Of course, this was a no-win situation. If it is 100% compatable with VB <=6 ,the language is a mess.  The "VB" bashing continues (in this case, somewhat deservedly so) and it's not a solid language.  If they do break compatability, people complain about *that*, even though the language itself is now a million times better. And no matter what, they all will still complain because it looks like BASIC and has the same core keywords and syntax.  Should they have changed this?  Should they never have released VB.NET?  What would you have done with .NET?  Just released C#, let VB die off, and that's that?   Would that be a smart business decision?  Would you continue VB6 on it's current path and release a more patched up, more crappy, more quirky, more "pseudo-OOP" language with VB7?   How would you have implemented VB.NET?  Broken ALL compatability by removing all of those BASIC keywords (End, Dim, And, Or, If-Then, End If, etc) you because you don't think they're "cool" or "hardcore" enough for you?

    Let's get back to the AND operator.  In VB6 it didn't short-circuit.  In VB5 it didn't.  In QBASIC, it didn't.  Whether you like it or not, that's the way it was.   VB derived from BASIC for god's sake, I don't understand why people get confused about that. 

    So, along comes VB.NET.  As we know, MS is cleaning up VB -- rewriting it from scratch.  Breaking it away from BASIC where necessary, but trying to keep it as backwards compatable as possible.  Trying to make it a first-class language but still trying to make it accessable to users of older versions of VB.  They get to the AND operator and think to themselves:

    "Ok, in VB <= 6, it did not shortcircuit.  We'd like to implement it as a shortcircuiting operator in VB.NET.  But to do so, it will break compatability.  It certainly doesn't compromise the integrity of our new language to have the AND operator behave as it does in VB <=6, as long as we add an operator that does shortcircuit.  Please easy solution, right?  So let's create *another* operator, and call it, AndAlso.  Lame name, yep.  that's life.  But now we have the best of both worlds.  Will script kiddies think this is something to complain about?  Probably, but it solves the problem, adds a needed feature, it works, let's move on."

    Why the hell do people have a problem with this?  I know it's M$ and they're evil and "Windows sux" and all that, but this is ridiculous.  The addition of AndAlso and OrElse was one of the most highly documented things about .NET, I am amazed that 5 years later people still get confused about it.  Since the language has now been out for a while, knowing about these operators is a good indicator of who actually knows the language, and who is just complaining.

    Make fun of older versions of VB a little if you want, but remember it's purpose.  Remember why it was created.  Remember who it was for.  Think about how it changed over the years.  Was Microsoft "stupid" to leverage BASIC and create a language for beginners?  Were they "stupid" to add features over the years to it?  Was it a bad thing to create a visual language for Windows that beginner programmers could use?  Was it a bad thing to make it somwhat more powerful over time, but still backwards compatable?  Should they never have released another version after 1.0?

    Critizing the flaws in VB<=6 when comparing it to more robust languages is one thing, but to criticize VB.NET for these things is ridiculous.  It's very amusing to me how it scares the "real programmers" out there that Microsoft wrote VB.NET in such a way that it contains virtually all the features of C# with simply a different language syntax (even moreso in .NET 2.0)  They freak out about it, try to attack it as much as possible .. "it can't be a real language! It just .. cant' be!  I don't know why, but I don't like it!  I'm hard-core!  My { and } keys have worn off my keyboard!  VB sux!  Yeah, that's it! "

    Can we *finally* get past all this?  Please? 


  • (cs) in reply to triso

    triso:
    Anonymous:
    Gotta love a language that has "AndAlso" operator...

    Cheers, Mike5
    <FONT size=5>A</FONT>t least Microsoft bent to public pressure and put it in.  They could have kept up with their "VB isn't C" and the NIH nonsense.

     

    I think its the other way around.  From what I understand, the designers included short-circuit evaluation by default, just as god intended boolean expressions to be evaluated, but due to public pressure from the VB dev community ("short-circuit what?? that'll break all our current apps! I don't understand! put it back the way it was, please!"), full evaluation was reset as the default for boolean operators, and short-circuit added as an "extra bonus" with braindead names like "AndAlso" and "OrElse".

          -dZ.

  • Anonymaly (unregistered) in reply to utunga
    utunga:

    You say that "seems cleaner" but then you justify it by pointing out that its easier on the compiler. Just my opinion but I'm totally with Oliver on this one.

    Worrying about redundant IL is precisely the kind of thing that programmers (myself included) have to resist, when they are trying to write clean, easily maintained code.

    Worry about the programmers that come after more than the the compiler. You're talking about saving a few trillionths of a second in performance, in return for what seems to me like a less obvious statement of events.

    Actually, I think my version is a bit more succinct and easier to read.  The intent was not to make things easier for the compiler.  It seems 'cleaner' from the standpoint that (of course, in my humble opinion), reads rather nicely and has only one simple logical expression to parse in the if() statement.

    Now, that aside, I do have to admit that I am not ignorant of the fact that using both 'as' and 'is' together in that regard is adding redundant IL code.  Regardless of how many "trillionths of a second" it saves to avoid it, I think it still shows prudence towards not being wasteful --that in addition to actually writing very readable and maintainable code.  I would challenge you to show how the code that I have presented is not maintainable.

    I find it all too easy nowadays for people to illegitimately use the phrase "premature optimization" or "sacrifices readability and maintainability" if only to do nothing more than provide an excuse to avoid learning how things work "under the hood" and maintain their ignorance of same.  It also explains why some people still write bloated, slow and leaky code for embedded processors after coming from a platform where their wasteful habits were allowed to flourish.  Those habits, by the way, are the kinds of things that 'good' programmers should really have to resist.

  • Erik (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.

    The type is not checked twice.  The type is checked once with some shorthand reflection, and if it is the correct type, then it is type cast once.  Her code is pretty much the most direct equivalent to yours that there would be in VB.

  • diaphanein (unregistered) in reply to Erik
    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.

    The type is not checked twice.  The type is checked once with some shorthand reflection, and if it is the correct type, then it is type cast once.  Her code is pretty much the most direct equivalent to yours that there would be in VB.

    I disagree.  The type is being checked twice:

    1. TypeOf (thisControl) Is ICheckBoxControl
    2. CType(thisControl, System.Web.UI.ICheckBoxControl)

    Now, granted - what she is doing is good.  She's checking the type to make sure the cast will succeed to avoid an unnecessary exception thrown if the type isn't ICheckBoxControl.  But, the CType function must check the type to ensure the cast is possible.  How else with the invalid cast exception be thrown if it doesn't check the type?

  • (cs)

    The real WTF is people are assuming the name Michelle means someone is female. I had a boss once who's name was Michelle, and he was definitely male. (He was from France, where apparently that is a common guy's name)

    This is the internet, anyone can claim to be anything.

  • (cs) in reply to hank miller

    Michel is a boy's name.  Michelle is a girl's name.

  • (cs) in reply to hank miller

    hank miller:
    The real WTF is people are assuming the name Michelle means someone is female. I had a boss once who's name was Michelle, and he was definitely male. (He was from France, where apparently that is a common guy's name) This is the internet, anyone can claim to be anything.

    I will bet money that if your boss is a male from France, then he spells his name "Michel".

  • (cs)

    So the WTF is using TypeOf?
     

  • (cs) in reply to hank miller

    After reading everyone's replies to my post, I can't stop laughing. I'm not trying to mock.

    All I wanted to do was congratulate women on being competetive in finding these errors. I rarely see a post by a woman.

    Somehow I ended up as "the real WTF"!!! hahahahaha

    You are all so cute sometimes! I adore so many of you. But look, other times you are so nasty to everyone who decided to speak his or her mind, you confuse me to bits.  Would it kill you to respond kindly?? Or at least try to squelch the deep desire to know more than others and criticize even a compliment? Am I alone in this?

    In addition and for kicks - I am a woman. I assume programmers are smart - because it takes some brains to do this, even doing it wrong. I am glad when a woman gets any positive recognition. And if Michelle is not a woman - I can say "Oops I was wrong" without needing a hailstorm of offensive comments. And finally, I give a fig.

    thanks for responding anyway.

    januarys

  • (cs) in reply to diaphanein

    I think there's a difference between suboptimal and WTF, though your code is a definite improvement. 

  • (cs)

    Obviously the right way to do this (for the former team members i mean):

    For Each ctrl In Controls
        Dim prop as Reflection.PropertyInfo = ctrl.getType().GetProperty("Checked", Reflection.BindingFlags.Instance Or
    Reflection.BindingFlags.Public)
        If (Not prop Is Nothing) AndAlso (prop.PropertyType Is GetType(Boolean)) AndAlso prop.IsWritable Then
           prop.SetValue(ctrl, True)
        End If
    Next ctrl

    8-|

    <font size="2">(i'm sure there are more WTF's in this code than in the original one, but hey, who cares? :P)
    </font>

  • (cs) in reply to mouzik

    Spotted one:

    mouzik:

           prop.SetValue(ctrl, True, Nothing)


    But there have to be more, i did this from the top of my head...

  • (cs) in reply to bongo
    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.


    That's all weel & good, except that it doesn't actually do what the original function did. (The revision assume the existence of a "controlName" variable. To actually duplication the original (in C#)

    <FONT face="Courier New" size=2>foreach (ICheckBoxControl c in Control)
    {
           if (c != null)
                 c.Checked = true;
    }</FONT>

    (The foreach automatically handles the "as")

     

     

  • (cs) in reply to Rain dog
    Anonymous:
    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).



    Are you on crack? What should we write web apps in? HTML?

    Don't be so démodé. Everybody knows AJAX is the way to go :)

  • (cs) in reply to zip
    zip:

    A "sausagefest" is a gathering of humans that are predominantly male.

    That sounds so gay.... A gay gathering..... I don't want to imagine what they may using those sausages for...........

  • (cs) in reply to Geoff
    Anonymous:
    '
    You are going to begin to grep a symbol or an 'english equivilent' as an entity completely unrelated to its common definition, regardless of what said symbols actually is: be it the '|' or the AndAlso.

    Well, speaking of ambigous, I'm not sure that I 'grep' your use of the word 'grep' in that context.

    Do you mean 'grok'? (http://en.wikipedia.org/wiki/Grok) 

    And that was Martian, so bonus points for irony by using it in a sentance about english equivilents.

  • Noob (unregistered) in reply to Anonymous
    Anonymous:
    januarys:

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

    It's comments like this that keep us away.



    And it's comments like yours that make me say... good riddance.
  • Noob (unregistered) in reply to Noob
    Anonymous:
    Anonymous:
    januarys:

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

    It's comments like this that keep us away.



    And it's comments like yours that make me say... good riddance.


    Oh, I just had to add that I noticed the original was poster said she was a woman, so I wonder if Anonymous would say the same thing knowing that...but I am sure she made that comment assuming the original poster was male..so probably not.  Shows how pathetic her attitude is, and again, don't let the forum hit your keyboard on the way out, you won't be missed.
  • SDiZ (unregistered) in reply to Casiotone
    Casiotone:

    Maybe because being presented with a page of pure text is incredibly hard to parse, interpret and understand quickly.
    Something =
    If This Or That And OtherThing = Something Then
      SomethingElse = AnotherThing
    End If
    vs.
    if (This || That && Otherthing == Something)
    {
      SomethingElse = AnotherThing;
    }

    which is easier to read? The one with loads of "craaazy symbols" or the one where you can't even tell the difference between a variable name and an operator without reading the word?


    Yes,
    but itn't that the reason for colour syntax highlighting?     
  • Me (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 has to do with short circuiting evaluation.  Same thing with the OrElse operator.  Why doesn't VB have the And & Or operators short circuit by default?  Who knows.....

  • bramster (unregistered) in reply to dhromed
    dhromed:
    SysRq2000:
    So I suppose you think that && is more intuitive at first glance, huh?


    It's true.

    && is not more intuitive than 'AndAlso'.

    && must be learned.

    'AndAlso' has implicit meaning.

    Who cares.

    Point is moot, since a programming language doesn't have to be that intuitive.

    A programmer will learn the language. If he needs to learn that && means a strict AND then he will. End of story. No programmer will complain that a language is crap because he couldn't figure it out at first glance, and nor should he. He should shut up and whip out the reference manual.

    'Making it intuitive' applies to interfaces aimed at the person who needs to perform a task with 0.0 hassle && cannot be required to sit back and learn the interface.
    Example: ticket machines at the train station.
    Example: cash machines
    Example: the on-screen options on your monitor or TV.

    Software interfaces are in the grey zone. You need to make 'em "easy to use", "efficient", "intuitive" but you, as interface designer, can require your users to learn the damn program.

    Photoshop can be hard. Softimage XSI is definitely hard. Public Websites should be easy, at all times, no exceptions.


    Today's "Joel on Software" has some very interesting views about interfaces.
  • (cs) in reply to Enric Naval
    Enric Naval:
    zip:

    A "sausagefest" is a gathering of humans that are predominantly male.

    That sounds so gay.... A gay gathering..... I don't want to imagine what they may using those sausages for...........

    Um, yeah.  It's a derogatory term.

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

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

    It's comments like this that keep us away.


    I'm sure that wasn't what was intended.  If you're still reading, please help me understand what the offensive element was.

    Was it simply calling attention that the submiter was a woman?  I read that as more of an encouragement than a derision.  More like a statment similiar to 'we need more people like you around here'.

    Or was it the use of the term 'chicks'?  To my ear, 'smart chicks' takes on a completely different meaning.  It is completely different than as in "let's  go pick up some chicks".  I see the term 'smart chick' as a term of respect.  Much in the same way that I refer to myself as a 'computer geek' or a female computer game aficionado may refer to herself as a 'gamer grrl'.

    So please don't take offense.  While I can't speak for "januarys", I really don't think that any offense was intended.  (And by all means, submit a WTF if you have any.)

    And if I'm really out of touch and just 'don't get it', you can at least submit my comments as a WTF.
  • KeithSpook (unregistered) in reply to Enric Naval
    Enric Naval:
    Anonymous:
    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).



    Are you on crack? What should we write web apps in? HTML?

    Don't be so démodé. Everybody knows AJAX is the way to go :)



    Hear, Hear.  (Here?).  The Internet was invented for AJAX.  No joke.
  • bramster (unregistered) in reply to marvin_rabbit
    marvin_rabbit:
    Anonymous:
    januarys:

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

    It's comments like this that keep us away.


    I'm sure that wasn't what was intended.  If you're still reading, please help me understand what the offensive element was.

    Was it simply calling attention that the submiter was a woman?  I read that as more of an encouragement than a derision.  More like a statment similiar to 'we need more people like you around here'.

    Or was it the use of the term 'chicks'?  To my ear, 'smart chicks' takes on a completely different meaning.  It is completely different than as in "let's  go pick up some chicks".  I see the term 'smart chick' as a term of respect.  Much in the same way that I refer to myself as a 'computer geek' or a female computer game aficionado may refer to herself as a 'gamer grrl'.

    So please don't take offense.  While I can't speak for "januarys", I really don't think that any offense was intended.  (And by all means, submit a WTF if you have any.)

    And if I'm really out of touch and just 'don't get it', you can at least submit my comments as a WTF.



    You can't win, you can't break even, and you can't get out of the game. . .
  • John Hensley (unregistered) in reply to Craig Lipscomb
    Anonymous:

    Explain to me why curly braces and semicolons cause you to pull your hair out?  I am sure case sensitivity also caused you to pull out your hair then too.  These three things is why I love C like languages.  i had to take a VB course in college and thought it was the most awful thing i seen.  WHILE/WEND ??? IF/END??? there is no structure to that.

    Your course was in which language again? I haven't seen "WEND" since GW-BASIC. Just because VB is called Basic doesn't mean it's the same as whatever you studied.

    I don't know about you, but most of us don't use the delimiters as the main visual cue. We indent blocks.

  • (cs) in reply to diaphanein
    Anonymous:
    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.

    The type is not checked twice.  The type is checked once with some shorthand reflection, and if it is the correct type, then it is type cast once.  Her code is pretty much the most direct equivalent to yours that there would be in VB.

    I disagree.  The type is being checked twice:

    1. TypeOf (thisControl) Is ICheckBoxControl
    2. CType(thisControl, System.Web.UI.ICheckBoxControl)

    Now, granted - what she is doing is good.  She's checking the type to make sure the cast will succeed to avoid an unnecessary exception thrown if the type isn't ICheckBoxControl.  But, the CType function must check the type to ensure the cast is possible.  How else with the invalid cast exception be thrown if it doesn't check the type?



    There are lots of steps in the casting process that TypeOf doesn't do, so it really isn't doing it twice.  Also, CType has some bloat in it to do VB style implicit conversions.  Use DirectCast to get the equivalent of C# casting.

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

    <FONT color=#000000>It also wouldn't be too much of a WTF to simply DirectCast it without testing first and let it throw an exception.  Wrap the whole method in a Try or let Application_Error in Global.asax catch it.  It will NEVER throw an exception unless coded wrong.  So, any performance concerns of using Exceptions are irrelevant.  By coded wrong, I mean that it has zero chance of actually working correctly, ie. the wrong control name was used.  The If will actually swallow the error and make it more difficult to debug.  At least add an Else and log the ocurrance if the debug TraceSwitch is on.</FONT>

    <FONT color=#000000>Think about it, how often have you asked someone to write a block of code that "Sets the Checked property on the ICheckBoxControl interface of an object to True, or simply and silently does nothing if the object doesn't implement ICheckBoxControl"?  Shouldn't the spec for that method say it should throw a "WhatTheHellShouldIDoWithThis" exception?  Remember error are the frameworks way of showing what's wrong with your application.  They aren't some kind of accusation that needs to be swept under the carpet before your boss sees them.</FONT>

  • jbange (unregistered) in reply to Pope
    Pope:

    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?

    Natural language? Programming more closely resembles mathematics than storytelling. Ask a mathematician why they use all those confusing symbols instead of writing out "three times X plus Z squared divided by the square root of Y factorial minus W to the fifth power". If you take the time to learn the symbology, it is really and truly easier to read and understand.

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

Log In or post as a guest

Replying to comment #:

« Return to Article