• (nodebb)

    Sometimes I wonder if some of these code samples were made up by submitters to amuse the audience. This one definitely wasn't - it takes true dedication; "you can't make this up".

  • (nodebb)

    No visible loops even needed: Enumerable.Range(0, checks).Select(x => "").Add(checkersummary);

  • Tobias Olofsson (unregistered) in reply to TheCPUWizard

    In the original code if you use a number greater than 19 it behaves as if 0. The Range won´t do that will it?

  • Prime Mover (unregistered)

    TRWTF is needing to set up an array with a specific number (up to 16) empty strings in the first place. We haven't needed to do this sort of thing since Fortran, surely. If your code design does make it necessary to perform this sort of exercise, there's a dead rat with halitosis buried in an excrement and garlic sandwich buried somewhere else in your application.

  • 516052 (unregistered) in reply to Prime Mover

    Or sitting in between your chair and keyboard. Or perhaps more terrifying between your bosses chair and his keyboard.

  • Sole Purpose Of Visit (unregistered)

    I suspect the reason that checkersummary is at the end is that the desired return array is mutable.

    That is to say, this horrid thing is the default state, and an indeterminate number of calling sites are going to insert the checker of their choice at the point of their choice.

    The stenchometer is high on this one, isn't it?

  • akozakie (unregistered)

    That doesn't look like a true WTF - more like an early indicator of a huge toxic pool of WTFs deeper in the code.

  • Cobol_Dude (unregistered)

    This is less about FOR LOOPS and more about not using an array object for all of the values. Besides, why not just build a specific object? Why use the default object? Asking for a friend. I am not a Java programmer.

  • Robin (unregistered) in reply to Prime Mover

    "If your code design does make it necessary to perform this sort of exercise, there's a dead rat with halitosis buried in an excrement and garlic sandwich buried somewhere else in your application."

    You, sir (or madam) win the Internet for today

  • Alistair (unregistered) in reply to Mr. TA

    It only takes a minute to generate the code in Excel

  • ooOOooGa (unregistered)

    At first, I was trying to figure out what this is used for.

    Initially I thought it was doing a string pad of a value. But then noticed that it was creating an array of object to return.

    Perhaps there is some reason why there can only be up to 19 empty entries in the array. Or maybe this will end up being another case of 'we need you to add more days'.

    Given the names of variables, it is possible that this has something to do with testing. Either code testing, or actually testing user input during runtime in production.

    But then I realized that down that path lies madness. I'm just going to close my browser tab now.

  • Carl Witthoft (google) in reply to Alistair
    It only takes a minute to generate the code in Excel

    Writing code in Excel? That's a major WTF all by itself.

  • Naomi (unregistered) in reply to Cobol_Dude

    FWIW, this is C# - it's Object with a capital O in Java.

  • Cheats Never Prosper (unregistered) in reply to Robin

    And quite possibly, for the rest of the week.

    Most excellent code review. Worthy of a sidebar :)

  • (nodebb) in reply to Prime Mover

    Fortran dev here. I feel the pain...

  • Loren Pechtel (unregistered)

    You can use a loop to fill it, you can't use a loop to create it. I think the programmer didn't realize how to make an array of different types.

    Thus:

    object[] Result = new object[checks + 1]; for (int Loop = 0; Loop < checks; Loop++) Result[Loop] = ""; Result[Checks - 1] = checkerSummary; return Result;

  • Wizofaus (unregistered) in reply to Naomi

    Yeah but C# code using K&R brace placement? That's TRWTF right there.

  • Sole Purpose Of Visit (unregistered) in reply to Wizofaus

    Write yourself a little prettifier in something like Python. Job done. Quit bitching.

  • Guus (unregistered)

    It happens to be valid C++20 as well, thanks to https://wg21.link/p1009r2.

  • Prime Mover (unregistered) in reply to R3D3

    Any jobs going where you work?

  • Dan (unregistered)

    I like this "benefit of the doubt" section - gets your mind rolling. Could be a stable feature of your blog posts from now on...

  • What's an array? (unregistered)

    This reminds me of some code I wrote back in middle school. I was writing a digital version of the board game mastermind. Mastermind has 44 different holes that differently colored pegs could go in. I knew about loops but I didn't know about arrays, and I wished that I could iterate over my 44 different "hole_row_10_column_4" variables in some way. If I had been using a language with eval, I probably would have made liberal use of it.

  • Chris (unregistered)

    I remember using an older version of Visual Studio with C++ (2010?), and it wouldn't let you specify an array size at run time. Maybe the coder for today's WTF is used to coding with such restrictions. But then the WTF is not RTFM and being aware of what is permitted by the current language.

    In my case, if you needed dynamically sized arrays, you would just use a vector (and do so for just about any use-case requiring arrays anyway). Even if C# (which I'm guessing is the language here) didn't allow you to have arrays of size unknown at compile time, they still have Lists and other containers.

    The bigger WTF is why this array is even needed, in the format used, which we'll never know sadly.

  • dan (unregistered) in reply to Prime Mover

    I'm pretty sure the empty strings is just a lazy way to avoid having to do null checks in the consuming code.

  • Klimax (unregistered) in reply to Chris

    I assume you mean C-style arrays. Runtime sized array would be C99 feature and this particular feature is not supported by any version of MSVC. IIRC for a long time C99 wasn't referenced by C++ specification. (Only C89 was)

    Note: Current MSVC has switch for support for C17. Maybe Intellisense hasn't been updated for runtime specified arrays.

  • Some Ed (unregistered) in reply to Mr. TA

    I find your comments suggesting things seemed made up on some of the least contrived examples. So I guess it's fair that you've left this comment on one of the easiest examples I've seen to make up.

    Admittedly, I've seen code very similar to this in the wild, so I'm not saying this was made up. But anyone with knowledge of for loops and knowledge of the existence of people who don't know about them could come up with this relatively quickly in most languages with for loops.

  • Is That Really A Crosswalk? (unregistered)

    I'm guessing - it started out as needing perhaps just the first two, and they were separate for testing. Everything worked, and it was left as is. Then someone said another option was needed, and added a new line. Then another one, and another one, and there's probably a comment somewhere saying "when you add another widget don't forget to add another line to this bit of code"

Leave a comment on “For Gotten About Loops”

Log In or post as a guest

Replying to comment #:

« Return to Article