• (cs)

    public Post getFristPost() {    if ( true )        throw new IllegalPostException( "Everyone hates frist posts" );    return fristPost; }

  • (cs)

    I thought those got deleted these days? my last one did.

    in other news, I am a fan of the count loop.

  • RFox (unregistered)

    Because this method was decommissioned and they weren't quite sure they got all the calls to it yanked out of all the client code...so they made sure any code that still called it would fail dramatically.

    Captcha: plaga - plaga of bad code.

    public DataModel getEditionModel() { if ( true ) throw new IllegalArgumentException( "You shouldn't be here" ); return editionModel; }

  • (cs)

    The timeStampLength: Either misunderstanding 'no-magic-numbers' or someone who grew up with Whitespace

  • (cs) in reply to RFox
    RFox:
    Because this method was decommissioned and they weren't quite sure they got all the calls to it yanked out of all the client code...so they made sure any code that still called it would fail dramatically.

    Captcha: plaga - plaga of bad code.

    public DataModel getEditionModel() { if ( true ) throw new IllegalArgumentException( "You shouldn't be here" ); return editionModel; }

    And, of course, using @Deprecated won't work because everyone ignores warnings.

  • ANON (unregistered) in reply to Zacrath

    Or deleting it, so that it just wouldn't compile anymore.

  • Black Bart (unregistered) in reply to ben_wtf
    ben_wtf:
    The timeStampLength: Either misunderstanding 'no-magic-numbers' or someone who grew up with Whitespace

    I say that the timeStampLength isn't a WTF - since we can't see what followed, it might be that the length was accessed multiple times in the next code block. I do that some times as a more concise way to express the logic, as well as ensuring that the member access is optimized to the max.

  • noland (unregistered)

    Let us refactor this:

    var count =0;
    for ( var i = 0; i < user.documents.length; i++) {
      count++;
    }
    
    for ( var i = 0, count = 0; i < user.documents.length; i++, count++ );
    
    for ( var count=0;  count < user.document.length; count++ );
    
    var count = user.document.length; // unfair! please use a more elaborate scheme!
    
    var temp = user.document.length, count = 0;
    while (temp--) count++;
    
  • Walky_one (unregistered) in reply to Black Bart
    Black Bart:
    ben_wtf:
    The timeStampLength: Either misunderstanding 'no-magic-numbers' or someone who grew up with Whitespace

    I say that the timeStampLength isn't a WTF - since we can't see what followed, it might be that the length was accessed multiple times in the next code block. I do that some times as a more concise way to express the logic, as well as ensuring that the member access is optimized to the max.

    Now if it was something like "YYYY-MM-DD/HH:MM:SS" and then calling "length" on it. I might agree (still has a number of issues though). But using plain Whitespace is just a WTF. No matter how you look at it.

    Note: accessing a constant will always be faster than accessing Array.Length

  • (cs) in reply to Algorythmics
    Algorythmics:
    I thought those got deleted these days? my last one did.
    Beats me. I'm a stranger round here myself.
  • Iggy (unregistered) in reply to noland
    noland:
    Let us refactor this:
    var count =0;
    for ( var i = 0; i < user.documents.length; i++) {
      count++;
    }
    

    for ( var i = 0, count = 0; i < user.documents.length; i++, count++ );

    for ( var count=0; count < user.document.length; count++ );

    var count = user.document.length; // unfair! please use a more elaborate scheme!

    var temp = user.document.length, count = 0; while (temp--) count++;

    i suggest this:

    
    for (i=0;i<MAX_INT;i++)
    {
    try 
       dummy = user.document.content[i];
        Catch ex As Exception
           return (i-1);
        End Try
    }
    </pre>
    
  • noland (unregistered) in reply to Iggy
    Iggy:
    noland:
    Let us refactor this:
    var count =0;
    for ( var i = 0; i < user.documents.length; i++) {
      count++;
    }
    

    for ( var i = 0, count = 0; i < user.documents.length; i++, count++ );

    for ( var count=0; count < user.document.length; count++ );

    var count = user.document.length; // unfair! please use a more elaborate scheme!

    var temp = user.document.length, count = 0; while (temp--) count++;

    i suggest this:

    
    for (i=0;i<MAX_INT;i++)
    {
    try 
       dummy = user.document.content[i];
        Catch ex As Exception
           return (i-1);
        End Try
    }
    </pre>

    Or, combining WTFs:

    var s = "", i = 0;
    while (user.documents[i++]) s += " ";
    var count = s.length;

    Finally, we do not have to trust user.ducuments.length and even the String.length makes some sense ...

  • Trebla (unregistered) in reply to ANON
    ANON:
    Or deleting it, so that it just wouldn't compile anymore.

    Depending on the language (this could easily be Groovy, for instance) code that calls the method could still compile even if the method is missing, then you'd get a much uglier error message.

    That's no excuse for not deprecating the method and noting that it should be removed in future releases... or for checking if(true).

  • The Fury (unregistered)

    The count method I can possibly understand unlike the others. It is possible that it used to do more, i.e. check for some condition on the document before incrementing the count.

    At some point this requirement went away, but the developer didn't bother to do a proper job of refactoring.

  • (cs)

    At least Andrew will be safe when empty expressions will start throwing ArgumentOutOfRangeExceptions...

  • Maurizio (unregistered) in reply to The Fury
    function countDocuments() { var count = 0;
    for ( var i = 0; i < user.documents.length; i++) {
        count++;
    }
    
    return count;
    

    }

    Can't you people read ? The name of the method is "Count Documents", it is not "Tell me how many documents are there". So the code do that, counts documents. What else it should do ?

    Captcha: ullamcorper: ancient exotic sexual practice: "last time we did an ullamcorper, i got back pain for a week".

  • fragile (unregistered)

    Incomplete red/green refactoring

    Mystery solved.

  • noland (unregistered)

    Finally, the unified all-in-one version (here in JS):

    function getTimeStringLength() {
       throw new Error("You really shouldn't be here");
       var dateString = new Date().toString();
       var timeStampLength = "";
       for (var i = 0; i < dateString.length; i++) {
          if (i < 0 || i >= dateString.length) {
             throw new Error("item not found in the string...");
          }
          timeStampLength += " ";
       }
       var lengthOfTimeStamp = timeStampLength.length;
       return lengthOfTimeStamp;
    }
  • ComputerForumUser (unregistered)
    function countDocuments() {
        var count = 0;
    
    for ( var i = 0; i < user.documents.length; i++) {
        count++;
    }
    
    return count;
    

    }

    This probably started out as
    foreach (var document in documents) {
    and then somebody said "You should use documents.length instead of the foreach."

    If TypeOf ex Is ArgumentOutOfRangeException Then
    ... then change its message because it's too hard to tell it apart from all the other ArgumentOutOfRangeExceptions that the code probably throws.
  • Balu (unregistered) in reply to The Fury
    The Fury:
    The count method I can possibly understand unlike the others. It is possible that it used to do more, i.e. check for some condition on the document before incrementing the count.

    At some point this requirement went away, but the developer didn't bother to do a proper job of refactoring.

    Or maybe it is just do make sure that the returned value is always >= 0 in case
    Array.length
    does return a negative value in the future...

    Captcha: tego - Fixing code like that you have a long way tego...

  • faoileag (unregistered)
    the article asked:
    Can you imagine a clearer way to express a numeric length?
    Sheesh, what a stupid question. Of course I can. See countDocuments() further down as an example for getting the length of something.
  • faoileag (unregistered)
    the article said:
    If only there were a built-in method that could tell us the length of an array...
    But whoever wrote that method didn't want to determine the length of an array. He wanted to count documents.

    Count. Documents.

    And that is what the method does.

  • foo (unregistered)
    String timeStampLength = "                          ";
    int lengthOfTimeStamp = timeStampLength.length();

    How confusing! I suggest:

    String sTimeStampLength = "                          ";
    int iLengthOfTimeStamp = timeStampLength.length();
  • faoileag (unregistered)

    Of course TRWTF with Timo's method is that it throws an IllegalArgumentException when it could throw an UnsupportedOperationException.

  • (cs) in reply to Trebla
    Trebla:
    ANON:
    Or deleting it, so that it just wouldn't compile anymore.
    That's no excuse for not deprecating the method and noting that it should be removed in future releases... or for checking if(true).

    Deprecating - perhaps it's possible, perhaps the architecture and/or methodology would make it hard or impossible. Which would imply they have the wrong architecture and/or methodology but hacking this and then patching the resulted faults would be simpler than swapping the entire way how they build whatever system this is.

    As for if (true) - some compilers would complain or actually refuse to compile this method if you just have it as

    public DataModel getEditionModel() {
       throw new IllegalArgumentException( "You shouldn't be here" );
       return editionModel;
    }

    for the return statement is unreachable. Similarly, doing a straight

    public DataModel getEditionModel() {
       throw new IllegalArgumentException( "You shouldn't be here" );
    }

    Would cause the compiler to tell you there is no return statement. The only way to both always throw an exception and have it compile is to have it in a if (true). Now, of course this is not a good way of doing it, but as pointed above may be the best way in the situation which would make it's the...well, correct incorrect way of doing it.

  • faoileag (unregistered) in reply to foo
    foo:
    How confusing! I suggest:
    String sTimeStampLength = "                          ";
    int iLengthOfTimeStamp = timeStampLength.length();
    There's still room for improvement:
    String sTimeStampWith26CharsLength = "                          ";
  • (cs) in reply to foo
    foo:
    String timeStampLength = "                          ";
    int lengthOfTimeStamp = timeStampLength.length();

    How confusing! I suggest:

    String sTimeStampLength = "                          ";
    int iLengthOfTimeStamp = timeStampLength.length();

    Error: timeStampLength cannot be resolved

  • Balu (unregistered) in reply to faoileag
    faoileag:
    But whoever wrote that method didn't want to determine the length of an array. He wanted to count documents.

    Count. Documents.

    And that is what the method does.

    +1.

    That reminds me of the old joke where a physicist goes for a walk in the woods and meets two mathematicians, who are in the middle of an argument.

    "What's up with you two", he asks them. "We are uncertain how high that tree is", one of the others answers.

    The physicist takes is ever present chainsaw and after the tree has fallen he takes a folding meter stick, measures the tree, tells the other two: "45 ft! Have a nice day!" and walks on

    After he has left one mathematician says to the other: "Amateur. We ask for the hight and he tells us the length..."

  • (cs)

    Anglea needs to learn some programming.

  • faoileag (unregistered) in reply to Balu
    Balu:
    That reminds me of the old joke where a physicist goes for a walk in the woods and meets two mathematicians, who are in the middle of an argument.

    "What's up with you two", he asks them. "We are uncertain how high that tree is", one of the others answers.

    The physicist takes is ever present chainsaw and after the tree has fallen he takes a folding meter stick, measures the tree, tells the other two: "45 ft! Have a nice day!" and walks on

    After he has left one mathematician says to the other: "Amateur. We ask for the hight and he tells us the length..."

    +1 as well - didn't know that one and laughed :-)

  • (cs) in reply to faoileag
    faoileag:
    Count Documents.
    Ah yes, the lesser known (and rather less scary) younger brother of Count Dracula.
  • Herr Otto Flick (unregistered) in reply to Balu
    Balu:
    The physicist takes is ever present chainsaw and after the tree has fallen he takes a folding meter stick, measures the tree, tells the other two: "45 ft! Have a nice day!" and walks on

    TRWTF

  • (cs) in reply to Herr Otto Flick
    Herr Otto Flick:
    Balu:
    The physicist takes is ever present chainsaw and after the tree has fallen he takes a folding meter stick, measures the tree, tells the other two: "45 ft! Have a nice day!" and walks on

    TRWTF

    All here are pedantic dickweeds. Balu, don't pay any attention!

  • not an anon (unregistered) in reply to Bobby Tables

    Talk about a blockheaded compiler, complaining about a missing return statement that's really unreachable code in the first place! Also: if there's an @Deprecated, why is there not an @Poisoned (for those extreme cases, where you really do want to instantly break the compile for all callers)?

    CAPTCHA - secundum...portmanteau of 'security' and 'conundrum' from yesterday's article? (+misspelling)

  • Balu (unregistered) in reply to Nagesh
    Nagesh:
    Herr Otto Flick:
    Balu:
    The physicist takes is ever present chainsaw and after the tree has fallen he takes a folding meter stick, measures the tree, tells the other two: "45 ft! Have a nice day!" and walks on

    TRWTF

    All here are pedantic dickweeds. Balu, don't pay any attention!

    Actually I had to laugh, because when I translated the joke I had to look up the word and stumbled across meter, too.

    Dann jedoch, Herr Otto Flick, habe ich erkannt, dass es um das Ver "to meter" geht, welches "messen" bedeutet ;-)

    (Until, Herr Otto Flick, I realized that it was the verb "to meter", which is a synonym for "to measure" :-))

  • Hannes (unregistered)

    I've seen similar code to the one Dennis sent in.

    int newPage = 0; for (int i1 = 0; i1 < (dataGridView1.Rows.Count - 1); i1++) { newPage = i1; }

    Yes. The programmer tried to determine the rows count of the DataGridView. So, to do this, he just wrote a for-loop and used the count of rows in the DataGridView as it's terminator. :(

  • Evan (unregistered) in reply to Walky_one
    Walky_one:
    Black Bart:
    I say that the timeStampLength isn't a WTF - since we can't see what followed, it might be that the length was accessed multiple times in the next code block. I do that some times as a more concise way to express the logic, as well as ensuring that the member access is optimized to the max.
    Now if it was something like "YYYY-MM-DD/HH:MM:SS" and then calling "length" on it. I might agree (still has a number of issues though). But using plain Whitespace is just a WTF. No matter how you look at it.
    If you hadn't said it, I would have. I agree... "YYYY-MM-DD/HH:MM:SS".length() is actually pretty reasonable, at least under certain assumptions (e.g. that they don't call some strftime thing and pass the same string there, or something like that). But " ".length is basically no better than just saying 10.
  • Hannes (unregistered) in reply to Hannes
    Hannes:
    for (int i1 = 0; i1 < (dataGridView1.Rows.Count - 1); i1++)

    Actually, I forgot a '=' sign there. It should read 'i1 <= (dataGridView1.Rows.Count - 1)'

  • Keith (unregistered) in reply to Iggy

    Unless your array is 1-indexed, you're gonna come up a bit short with that code.

    Iggy:
    noland:
    Let us refactor this:
    var count =0;
    for ( var i = 0; i < user.documents.length; i++) {
      count++;
    }
    

    for ( var i = 0, count = 0; i < user.documents.length; i++, count++ );

    for ( var count=0; count < user.document.length; count++ );

    var count = user.document.length; // unfair! please use a more elaborate scheme!

    var temp = user.document.length, count = 0; while (temp--) count++;

    i suggest this:

    
    for (i=0;i<MAX_INT;i++)
    {
    try 
       dummy = user.document.content[i];
        Catch ex As Exception
           return (i-1);
        End Try
    }
    </pre>
  • Balu (unregistered) in reply to dkf
    dkf:
    faoileag:
    Count Documents.
    Ah yes, the lesser known (and rather less scary) younger brother of Count Dracula.
    For two-dimensional lists, is it Count Count?
  • faoileag (unregistered) in reply to dkf
    dkf:
    faoileag:
    Count Documents.
    Ah yes, the lesser known (and rather less scary) younger brother of Count Dracula.
    Nope, the lesser known (and more prone to bureaucracy) older brother of Count von Count.
  • Balu (unregistered) in reply to faoileag
    faoileag:
    dkf:
    faoileag:
    Count Documents.
    Ah yes, the lesser known (and rather less scary) younger brother of Count Dracula.
    Nope, the lesser known (and more prone to bureaucracy) older brother of Count von Count.
    Oh come on - this makes us look like twins...
  • Keith (unregistered) in reply to Keith
    Keith:
    Unless your array is 1-indexed, you're gonna come up a bit short with that code.

    DERP! No you're not.

    CAPTCHA: nulla - Do I even need to say something funny about that one?

  • Developer Dude (unregistered) in reply to RFox

    Or, you could just throw an UnsupportedOperationException instead.

    Since there is no argument, why throw an illegal argument exception?

    Why put the if(true) in there? Just throw it period.

    Better yet, just remove the method and that will tell you if there are still any calls to the method in your code as it will not compile. It is always better to catch a problem at compile time than running time.

  • (cs) in reply to Keith
    Keith:
    Keith:
    Unless your array is 1-indexed, you're gonna come up a bit short with that code.

    DERP! No you're not.

    Fail, yes you are - in a 0-based array the first time i is out of bounds it will equal the count of the items in the array; the suggested code then returns i-1 for a classic out-by-one error.

    Of course, if the array is 1-based then access index 0 of the array may also throw an error, in which case you'd be out by count+1 as you'd return -1. Either way, not useful :p

  • faoileag (unregistered) in reply to Balu

    [quote user="Nagesh"][quote user="Herr Otto Flick"][quote user="Balu"] The physicist takes is ever present chainsaw and after the tree has fallen he takes a folding meter stick, measures the tree, tells the other two: "45 ft! Have a nice day!" and walks on [/quote]

    TRWTF

    [/quote]

    All here are pedantic dickweeds. Balu, don't pay any attention![/quote][/quote] Pffft, why should he? Tell the joke in german and you have the very same problem:

    "Der Physiker ... nimmt einen Zollstock, vermisst den Baum und sagt zu den anderen beiden 13,716 m Guten Tag noch!" (Zoll == inch == not metric)

  • Count Von Count (unregistered) in reply to faoileag
    function countDocuments() {
        var count = 0;
        for ( var i = 0; i < user.documents.length; i++) {
            count++;
            if ((count % 5) == 0)
                Console.WriteLine(count + " hahaha");
            else
                Console.WriteLine(count);
        }
        return count;
    }
  • (cs) in reply to Count Von Count
    Count Von Count:
    function countDocuments() {
        var count = 0;
        for ( var i = 0; i < user.documents.length; i++) {
            count++;
            if ((count % 5) == 0)
                Console.WriteLine(count + " hahaha");
            else
                Console.WriteLine(count);
        }
        return count;
    }
    Not at all that much impression making.
  • YellowOnline (unregistered) in reply to faoileag

    [quote user="faoileag"][quote user="Nagesh"][quote user="Herr Otto Flick"][quote user="Balu"] The physicist takes is ever present chainsaw and after the tree has fallen he takes a folding meter stick, measures the tree, tells the other two: "45 ft! Have a nice day!" and walks on [/quote]

    TRWTF

    [/quote]

    All here are pedantic dickweeds. Balu, don't pay any attention![/quote][/quote] Pffft, why should he? Tell the joke in german and you have the very same problem:

    "Der Physiker ... nimmt einen Zollstock, vermisst den Baum und sagt zu den anderen beiden 13,716 m Guten Tag noch!" (Zoll == inch == not metric)[/quote]

    When measuring in German I use a Meterband. Zollstock should be removed out of the Duden or at least have a mention of being archaic.

    Seriously, I don't understand why one would still use a non-metric system in 2014. Except binary. And hex.

    OT: I had a good laugh with this code, surely the one that will only generate errors when called. If it was deprecated, there are surely better solutions than this.

    Captcha: refoveō. It has a meaning in Latin.

  • PenguinF (unregistered)

    I think there might be another cause for that empty-try kind of WTF, and that's committing a changeset from a merge without a second thought. I've seen lines of code miraculously disappear that way.

Leave a comment on “Sweet Mysteries of Life”

Log In or post as a guest

Replying to comment #:

« Return to Article