• Garrison Fiord (unregistered) in reply to Set
    Set:
    TRWTF is a Remy article without a hidden cornify link.
    Don't critcize any of his posts, or you'll get butt-hurt.
  • (cs)

    I kid you not.

          Public Shared Function CheckIfRadioListIsAffirmative(ByVal rdoListControl As RadioButtonList) As Boolean
             Dim retval As Boolean
             Try
                If Not rdoListControl Is Nothing Then
                   For Each r As ListItem In rdoListControl.Items
                      If (r.Text.ToLower = "yes" OrElse r.Text.ToLower = "true") AndAlso r.Selected Then
                         retval = True
                         Exit For
                      End If
                   Next
                End If
             Catch ex As Exception
                ReportException(ex)
             End Try
             Return retval
          End Function
    

    I need to go back in TFS and find the one that is even worse than this, and is closer to the article.

  • Mithrandir (unregistered)
    toAsciiBytes(false)[2] = (byte)'r';
    toAsciiBytes(false)[3] = (byte)'c';

    Fixed.

  • Not (unregistered) in reply to chubertdev
    chubertdev:
    I kid you not.
          Public Shared Function CheckIfRadioListIsAffirmative(ByVal rdoListControl As RadioButtonList) As Boolean
             Dim retval As Boolean
             Try
                If Not rdoListControl Is Nothing Then
                   For Each r As ListItem In rdoListControl.Items
                      If (r.Text.ToLower = "yes" OrElse r.Text.ToLower = "true") AndAlso r.Selected Then
                         retval = True
                         Exit For
                      End If
                   Next
                End If
             Catch ex As Exception
                ReportException(ex)
             End Try
             Return retval
          End Function
    

    I need to go back in TFS and find the one that is even worse than this, and is closer to the article.

    That isn't so bad. retval isn't intialized, but it has test for Nothing and exception handling which makes it better than average for VB.NET

  • Mithrandir (unregistered) in reply to chubertdev

    Well, apart from being in Visual Basic, the main problem I have with that method is that the list items don't have a value set to "true" or "false". And even then, you have to fix the calling code to do it right. (Chances are this method is being called with different lists in different contexts, some of which are "yes/no" and others of which are "true/false".)

    Minor demerit for handling exceptions right in the method; the only exceptions you ought to be able to get off that code are for unexpected Nothings, which can be easily checked for (as long as you're checking the argument for Nothing, why not the Items property and the ListItems contained therein?).

  • (cs) in reply to Not
    Not:
    That isn't so bad. retval isn't intialized, but it has test for Nothing and exception handling which makes it better than average for VB.NET

    This is after a cleanup, but the code wasn't replaced since it's in that "working" state that you don't want to change.

    Btw, I've found that C# developers make worse mistakes than VB developers. Maybe that's just my experience.

    The developer for the above code is the exception, though. I could write a book with all of his WTFs, like this one:

           If LoginInfo.ErrorMessage = "The remote name could not be resolved: 'www.testdomain.com'" Then
                    Response.Redirect("CannotConnect.html", True)
                    HttpContext.Current.ApplicationInstance.CompleteRequest()
                End If
    
  • qbolec (unregistered)

    I like the idea that these are bytes because this needs to be serialized for someone who expects this typeo.

  • (cs) in reply to qbolec
    qbolec:
    I like the idea that these are bytes because this needs to be serialized for someone who expects this typeo.

    would that be considered a "fasle assumption"?

  • (cs) in reply to Yazeran
    Yazeran:
    At least he/she didn't simulate a g-string

    I recently broke my g-string while I was fingering a minor.

  • (cs) in reply to Coyne
    Coyne:
    Come on! You just made ['t','r','u','e'] into ['t','r','e','u']!! What kind of fix is that?

    Yeah, just because "blue" translates into French as "bleu" doesn't mean that it is treu that if a Francophone steps into the darkness without a torch that he will be eaten by a greu... everyone knows that grues hate the taste of French people! Get a cleu!

    BTW, am I missing something obvious about Java, or does allocating some teensy tiny little byte arrays REALLY cause Java to run out of memory after a few hours? Or was the crash coming from being unable to parse "fasle" as a boolean properly? You'd think THAT would happen more often than that...

  • Norman Diamond (unregistered)

    I once inherited (and later disinherited) a VB program that compared a Boolean variable to FLASE. Since FLASE wasn't declared and wasn't assigned a value, it was 0, and the program worked.

  • jack yell (unregistered)

    The writer of the function has made it perfectly clear about its purpose, i.e. to convert boolean to byte array. What's wrong with that?

    (Yes I know about the typo, but it could have been just Carl mistyped it)

  • (cs) in reply to Evo
    Evo:
    Yazeran:
    At least he/she didn't simulate a g-string

    I recently broke my g-string while I was fingering a minor.

    Are you talking about the one you ran off to France with last week?

  • Marmite (unregistered) in reply to Tom Hawtin
    Tom Hawtin:
    Well we can fix that.
        toAsciiByte(false)[3] = (byte)'l';
        toAsciiByte(false)[4] = (byte)'s';

    No, that's not the way.

    public static void fixBytes() {
        byte temp               = toAsciiBytes(false)[2];
        toAsciiBytes(false)[2]  = toAsciiBytes(false)[3];
        toAsciiBytes(false)[3]  = temp;
    }

    Just call the above method any time you need to use toAsciiBytes.

  • chris (unregistered) in reply to QJo
    QJo:
    Evo:
    Yazeran:
    At least he/she didn't simulate a g-string

    I recently broke my g-string while I was fingering a minor.

    Are you talking about the one you ran off to France with last week?

    Don't worry, they've both been suspended since.

  • Trollinator (unregistered) in reply to tolamaps
    public static byte[] toAsciiBytes(boolean v) {
      return Boolean.valueOf(v).toString().getBytes(Charset.forName("US-ASCII"));
    }
    

    I made it shorter just for you :)

    In that case, trwtf is that the UnsupportedEncodingException thrown by String.getBytes is a checked exception while the IllegalCharsetNameException and UnsupportedCharsetExceptionn thrown by Charset.forName aren't.
  • AN AMAZING CODER (unregistered)

    The method itself is really not that WTFish if you consider the possible context.

    This is a tomcat server. Therefore there's a high chance this web service also made external requests. Therefore it's possible that there was some kind of layer between application services that made representations of objects as POST bodies, which are transfered in bytes.

    Many POJOs have Boolean values, but when that value is a part of a POST body for transport, you probably want it to be the words "true" or "false" (i.e. human readable). IF I'm writing a layer of code to marshall my POJOS in a consistent manner, I proably have a function somewhere to turn boolean fields into the correct text representation.

    Now, misspelling false? Yeah, that's a WTF. But instead of blaming "code that seems to not do anything in my small understanding of what's going on with the app" instead of profiling and monitoring to find the issues is also a WTF.

  • (cs) in reply to Embiggen
    Embiggen:
    As usual with Remy articles, it gets even more absurd if you view source:

    (byte)'t', (byte)'r', (byte)'u', (byte)'e'

    All that to say "true"? WTF!

    Syntax highlighting. What's the WTF? Of course the markup would be a bit shorter by using classes instead of inline style, but not anywhere near a WTF.

  • theNewGuy (unregistered) in reply to MrBester
    MrBester:
    I'll see your tri-state boolean and raise you another two: MsoTriState Enumeration

    Akismet may be right occasionally.

    This seems to be perfect example of new n-state Boolean approach, they should upgrade Tomcat to cope with it.

  • (cs) in reply to Nagesh
    Nagesh:
    But still, a spelling error in the implementation does not tell anything about whether or not there's a good reason...

    Actually it PROVES why this is bad... For the most part, with today's computers. It isn't about whether this line of code runs it 5 cycles or 6... It is how easy it is to maintain down the road. How easy or hard it is to write buggy code.

    Tell me how good this code is, when you can't figure out why "false" isn't doing what you think it would.

  • Bernie The Bernie (unregistered)

    "Fasle" - sounds very similar to German "faseln" - and that means: drivel (talk nonsense). What a true statement for that code!

  • Neil (unregistered) in reply to tolamaps
    tolamaps:
    Trollinator:
    TRWTF is Java in that an idiomatic implementation isn't even much shorter than the implementation in the article due to checked exceptions.
      public static byte[] toAsciiBytes(boolean v) {
        try {
          return Boolean.valueOf(v).toString().getBytes("US-ASCII");
        } catch (java.io.UnsupportedEncodingException e) { 
          return null;
        }
      }
    public static byte[] toAsciiBytes(boolean v) {
      return Boolean.valueOf(v).toString().getBytes(Charset.forName("US-ASCII"));
    }
    I made it shorter just for you :)
    public static byte[] toAsciiBytes(boolean v) {
      return ("" + v).getBytes();
    }
  • (cs) in reply to Neil
    Neil:
    tolamaps:
    Trollinator:
    TRWTF is Java in that an idiomatic implementation isn't even much shorter than the implementation in the article due to checked exceptions.
      public static byte[] toAsciiBytes(boolean v) {
        try {
          return Boolean.valueOf(v).toString().getBytes("US-ASCII");
        } catch (java.io.UnsupportedEncodingException e) { 
          return null;
        }
      }
    public static byte[] toAsciiBytes(boolean v) {
      return Boolean.valueOf(v).toString().getBytes(Charset.forName("US-ASCII"));
    }
    I made it shorter just for you :)
    public static byte[] toAsciiBytes(boolean v) {
      return ("" + v).getBytes();
    }
    Now you return a result that relies on the platform's default encoding. Good job. :)
  • Shark8 (unregistered) in reply to chubertdev
    chubertdev:
    This is after a cleanup, but the code wasn't replaced since it's in that "working" state that you don't want to change.

    Btw, I've found that C# developers make worse mistakes than VB developers. Maybe that's just my experience.

    Nah, I'll verify that for you. Just last week I cleaned up a form with a bunch of combo-box handlers of the form

    private void COMBONAME_KeyUp(object sender, KeyEventArgs e)
    {
        handle_combobox_enter( COMBONAME, e );
    }
    

    For each and every single combobox on the form. Never mind that it's a million times more maintainable to, you know, use the sender parameter and have a general handler to handle all of them:

    private void general_combobox_KeyUp(object sender, KeyEventArgs e)
    {
        if (sender is ComboBox)
            handle_combobox_enter( sender, e );
    }
    

Leave a comment on “A Byte of Booleans”

Log In or post as a guest

Replying to comment #:

« Return to Article