• Warpedcow (unregistered) in reply to Mason Wheeler
    Mason Wheeler:
    curtmack:
    While I'm here, one of my favorite compiler optimizations ever: GCC can detect soft infinite loops (e.g. while (some_int <= MAX_INT)) and replace the conditional branch at the end of the loop with an unconditional jump.

    That's TRWTF right there. If the compiler can detect something like that, the appropriate response is not to optimize it, but to issue a warning, because the code is most likely wrong.

    Don't you think there might be any number of additional conditional jumps somewhere in the middle of the code in the while loop?

  • (cs) in reply to Mason Wheeler
    Mason Wheeler:
    curtmack:
    While I'm here, one of my favorite compiler optimizations ever: GCC can detect soft infinite loops (e.g. while (some_int <= MAX_INT)) and replace the conditional branch at the end of the loop with an unconditional jump.

    That's TRWTF right there. If the compiler can detect something like that, the appropriate response is not to optimize it, but to issue a warning, because the code is most likely wrong.

    No, some may consider it bad style but it isn't "wrong" to have a loop that doesn't terminate due to the condition but due to a return / break from within the body.

    The day compilers start complaining about bad style, which obviously includes this WTF and most other Code SODs (which work but are badly written code) - well it would be a good day for good software engineers of course but it will never happen because nobody will use such a compiler.

  • (cs) in reply to ObiWayneKenobi

    Well said.

  • Anon (unregistered)

    I do not understand why everybody is recommending an Array as a valid solution (other than because the title of the article suggests it). By using an array, you lose all of the semantics provided by custom properties.

    For example, row1.ResultValues[0] is tells you nothing about what kind of data is stored in that column.

    On the other hand, row1.Col0...

    ... oh. Never mind.

  • keng (unregistered)

    it's worse than you thought....it's 701 columns.

  • Your Name (unregistered) in reply to Cbuttius
    Cbuttius:
    The day compilers start complaining about bad style, which obviously includes this WTF and most other Code SODs (which work but are badly written code) - well it would be a good day for good software engineers of course but it will never happen because nobody will use such a compiler.

    On the contrary, Python is getting increasingly popular.

  • jay (unregistered) in reply to TonyPony
    TonyPony:
    I wonder if this developer got promoted to senior position because the company's performance metrics system hilighted he was one of their most productive (based on lines of code per day)

    Exactly! Years ago I worked for a company that said they were going to start rating programmer productivity on lines/day. My thought was, Hooray! I can easily score very high by this metric. Forget those silly "loop" things: just copy and paste the code 50 times. "x=x+5"? Don't be ridiculous. Write "x=x+1" five times. Etc.

    Sadly, they dropped the idea.

  • (cs) in reply to Anketam
    Anketam:
    Zecc:
    public class HistoryResultRow
    {
        #region Static Variables
        public static readonly int ColsMaxCapacity = 700;
        #endregion
    
    #region Public Properties
    public DateTime Date { get; set; }
    
    // 09-27-12, SenDev: FIXD IDENTATION. MUCH BETTER NOW!!
    public HistoryResultValue Col0 { get; set; }
    public HistoryResultValue Col1 { get; set; }
    public HistoryResultValue Col2 { get; set; }
    public HistoryResultValue Col3 { get; set; }
    public HistoryResultValue Col4 { get; set; }
    ...and so on, ad nauseum...
    public HistoryResultValue Col696 { get; set; }
    public HistoryResultValue Col697 { get; set; }
    public HistoryResultValue Col698 { get; set; }
    public HistoryResultValue Col699 { get; set; }
    #endregion
    

    }

    You just shaved off 2800 lines of code. That is almost an 80% reduction in SLOC. With skills like that you should be promoted to a Senior Developer!

    Doesn't work in C# 1.0. Read spec on C# before making comment like this.

  • Jack (unregistered) in reply to tristique
    tristique:
    The very first time, even if the number of columns was small (e.g. 10), he should have used collections.

    They may not have called them Col0, Col1, etc., in the real code. There could be some anonymizaiton going on here. If they had names that sounded like properties, it wouldn't be so offensive to look at.

  • Sigivald (unregistered) in reply to AGray
    AGray:
    Hey, now. We're being overly critical. Arrays are not the only way to go.

    He could've used a java List<E>. Then, there wouldn't be that pesky 701-element limitation - them Add() and Remove() functions are beasts, y'know!

    #region suggests to me he's using C#.

    Which means he should be using a Generic List, unless this predates Framework 2.

    And even then .Net shipped with real collections.

    Arrays? Avoid whenever possible - use a "real" data structure.

  • ¯\(°_o)/¯ I DUNNO LOL (unregistered) in reply to curtmack
    curtmack:
    This is why you always use -Wall -Werror when using GCC.
    FTFY.

    Those damn -pedantic errors do drive me nuts, though. And then there are the warnings that don't show up until you compile with -O.

  • transverbero (unregistered) in reply to ObiWayneKenobi
    ObiWayneKenobi:
    tristique:
    The very first time, even if the number of columns was small (e.g. 10), he should have used collections. For not using columns, he's a senior dumbass. The 2nd time he was adding properties to this class, since he hadn't taken time to change it to collection, he's a senior dumbass. If the number of columns that first time was larger, he's still a dumbass for not using collections. And you're a dumbass for defending him, even though you maybe had not (since, however, you sound like you had).

    Did I sound like I was defending it? No. I've seen a lot of "senior dumbasses" as you say write code like that, and what I said was the reason why. I've ALWAYS spoken against hacks like that, but as I said I was FIRED from the job because I kept wanting us to NOT write hack code. Rather than do that, they let the problem (i.e. me, the one good developer) go and kept the "senior dumbass" who hacked code via copy and paste because he was too lazy to do it right since that would mean telling the boss "No".

    You're right. That guy was out of line. I'm sure he's sorry.

  • Ben Jammin (unregistered) in reply to Nagesh
    Nagesh:
    Doesn't work in C# 1.0. Read spec on C# before making comment like this.
    I thought you were a java programmer.
  • Ben Jammin (unregistered) in reply to ObiWayneKenobi
    ObiWayneKenobi:
    ... (I was fired two months ago from a job I had for nearly two years for trying to get the team to realize "there has to be a better way") ...

    Did you get fired cause you said "there has to be a better way," or did you get fired for calling that senior developer "a talent-less boob who could be replaced by a high school hack and would contribute more by scrubbing toilets than by producing this filth"? Not saying you'd be wrong by saying that, I'm just curious.

  • Matt P. (unregistered)

    Any idiot can see that you actually have up to 701 columns.

  • Tractor (unregistered) in reply to Cbuttius
    Cbuttius:
    Mason Wheeler:
    curtmack:
    While I'm here, one of my favorite compiler optimizations ever: GCC can detect soft infinite loops (e.g. while (some_int <= MAX_INT)) and replace the conditional branch at the end of the loop with an unconditional jump.

    That's TRWTF right there. If the compiler can detect something like that, the appropriate response is not to optimize it, but to issue a warning, because the code is most likely wrong.

    No, some may consider it bad style but it isn't "wrong" to have a loop that doesn't terminate due to the condition but due to a return / break from within the body.

    The day compilers start complaining about bad style, which obviously includes this WTF and most other Code SODs (which work but are badly written code) - well it would be a good day for good software engineers of course but it will never happen because nobody will use such a compiler.

    It's still quite likely that the programmer meant something else so a warning is nice. An error would be stupid tough.

    Either way, if someone is using weird loop conditions that always evaluate to true he is either handing in a college assignment or he needs to be hit with a hammer. On the head. Hard.

  • gravis (unregistered) in reply to Vin
    Vin:
    I like this kind of coding. You can write it in Excel.
    ="public HistoryResultValue Col"&ROW()-1&"    {        get;        set;    }"
    and that gives you scope for many more columns.
    public HistoryResultValue Col65535    {        get;        set;    }
    Ummmm... if your Excel only has 65536 rows, I think it's time for an upgrade, buddy.
  • Northern Penguins (unregistered)

    That reminds of this one application I have to maintain.

    How it access these values is as such:

    public void setValue(String value, int number) {
        if (number == 0) 
            colums.setValue0(value)
        else if (number == 1)
            colums.setValue1(value)
        else if (number == 2)
            colums.setValue2(value)
        else if (number == 3)
            colums.setValue3(value)
    
       //And so on and on and on and on!
    }
    

    Same poetry when retreiving the values to.

  • foo (unregistered) in reply to Cbuttius
    Cbuttius:
    The day compilers start complaining about bad style, which obviously includes this WTF and most other Code SODs (which work but are badly written code) - well it would be a good day for good software engineers of course but it will never happen because nobody will use such a compiler.
    That's nothing new. GCC has some such warnings, including "-Weffc++" ("Warn about violations of the following style guidelines from Scott Meyers' `Effective C++' book [...]") and others. However, apart from a few uncontroversial ones, they're off by default, so you can decide for which kinds of bad style you want to see warnings or errors. Sure, it's some initial effort to enable such a warning in an existing code base, but once the code is "clean", you get some amount of code review automatically done for you.

    But then, until such warnings can prevent all or most of the WTFs seen here, there will be much work for the compiler writers left to do. (And of course, Alex will have to lobby against this. ;)

  • klueless (unregistered)

    I don't get it. This solution is very refactor-friendly. Imagine you want to change HistoryResultValue's name. One Ctrl + . later and a couple minutes of VS churn and you're done!

  • (cs)

    Arrays??

    This reminds me of the code that someone else (thankfully) write to take 5 readings of a sensor and throw out the highest and lowest, then average the rest. In Basic (on an Apple II) the guy used lots of variables (A1, A2, A3, ...). Obviously he wanted "speed" and used a bunch of IF statements. The whole calculation took over TWO pages. With a little bit of looping and the like, it would be about 10 lines (an exercise left to the reader).

    Yes, a total Code Sod!

  • nimis (unregistered) in reply to Tractor
    Tractor:
    Cbuttius:
    Mason Wheeler:
    curtmack:
    While I'm here, one of my favorite compiler optimizations ever: GCC can detect soft infinite loops (e.g. while (some_int <= MAX_INT)) and replace the conditional branch at the end of the loop with an unconditional jump.

    That's TRWTF right there. If the compiler can detect something like that, the appropriate response is not to optimize it, but to issue a warning, because the code is most likely wrong.

    No, some may consider it bad style but it isn't "wrong" to have a loop that doesn't terminate due to the condition but due to a return / break from within the body.

    The day compilers start complaining about bad style, which obviously includes this WTF and most other Code SODs (which work but are badly written code) - well it would be a good day for good software engineers of course but it will never happen because nobody will use such a compiler.

    It's still quite likely that the programmer meant something else so a warning is nice. An error would be stupid tough.

    Either way, if someone is using weird loop conditions that always evaluate to true he is either handing in a college assignment or he needs to be hit with a hammer. On the head. Hard.

    Dumbsses do not need to be warned. Let their dumbass code ass out.

  • nimis (unregistered) in reply to nimis
    nimis:
    Tractor:
    Cbuttius:
    Mason Wheeler:
    curtmack:
    While I'm here, one of my favorite compiler optimizations ever: GCC can detect soft infinite loops (e.g. while (some_int <= MAX_INT)) and replace the conditional branch at the end of the loop with an unconditional jump.

    That's TRWTF right there. If the compiler can detect something like that, the appropriate response is not to optimize it, but to issue a warning, because the code is most likely wrong.

    No, some may consider it bad style but it isn't "wrong" to have a loop that doesn't terminate due to the condition but due to a return / break from within the body.

    The day compilers start complaining about bad style, which obviously includes this WTF and most other Code SODs (which work but are badly written code) - well it would be a good day for good software engineers of course but it will never happen because nobody will use such a compiler.

    It's still quite likely that the programmer meant something else so a warning is nice. An error would be stupid tough.

    Either way, if someone is using weird loop conditions that always evaluate to true he is either handing in a college assignment or he needs to be hit with a hammer. On the head. Hard.

    Dumbsses do not need to be warned. Let their dumbass code ass out.

    Dumbasses do not DESERVE to be warned - that is.

  • Shinobu (unregistered)

    It's ‘ad nauseam’. In case the pronunciation doesn't make that clear, think about the fact that ‘a sensation of unease and discomfort in the upper stomach with an involuntary urge to vomit’ (think you Wikipedia) is ‘nausea’ (not ‘nauseum’ or ‘nauseus’ or anything of the kind).

  • Shinobu (unregistered) in reply to Shinobu
    Shinobu:
    (think you Wikipedia)
    s/think/thank/ Comment on someone's spelling and you will without fail mess up yourself.
  • Vin (unregistered) in reply to gravis

    Ah, so you spotted that. I wondered if anyone would. Well, an upgrade isn't currently an option here at <name-deleted> Bank. It's 2003 only for now.

  • anonymous (unregistered) in reply to ObiWayneKenobi

    I am sorry, but there is NO valid excuse for this monstrosity.

  • Bob (unregistered)

    There are 701 columns declared (assuming no number was skipped in code that was snipped). Yet MaxColumnCapacity = 700 :)

  • foo (unregistered) in reply to Bob
    Bob:
    There are 701 columns declared (assuming no number was skipped in code that was snipped). Yet MaxColumnCapacity = 700 :)
    Sorry, you're the 701st person to point this out. Only 700 were planned. You fail.
  • (cs) in reply to Junior_G
    Junior_G:
    private string GetRepeatedSourceCode(int numOfRetardation) { string result = ""; for (int i = 0; i <= numOfRetardation; i++) { result += "public HistoryResultValue Col" + i.ToString() +" { get; set; }";
            }
            return result;
        }</div></BLOCKQUOTE>
    

    come on! this is even worse than the initial WTF! don't you know that it should read like this:

    //That's it! return result;
  • chris (unregistered) in reply to Warpedcow
    Warpedcow:
    Mason Wheeler:
    curtmack:
    While I'm here, one of my favorite compiler optimizations ever: GCC can detect soft infinite loops (e.g. while (some_int <= MAX_INT)) and replace the conditional branch at the end of the loop with an unconditional jump.

    That's TRWTF right there. If the compiler can detect something like that, the appropriate response is not to optimize it, but to issue a warning, because the code is most likely wrong.

    Don't you think there might be any number of additional conditional jumps somewhere in the middle of the code in the while loop?

    Sure, but it's clearer to write while(true) or for( ; ; ), rather than some arbitrary construct like while(1 < 2).

  • Cyt (unregistered) in reply to Junior_G
    Junior_G:
    private string GetRepeatedSourceCode(int numOfRetardation) { string result = ""; for (int i = 0; i <= numOfRetardation; i++) { result += "public HistoryResultValue Col" + i.ToString() +" { get; set; }";
            }
            return result;
        }</div></BLOCKQUOTE>
    

    No no no ...

    return String.Join("\r\n", Enumerable.Range(1, cnMaxCols).Select(ix => String.Format("public HistoryResultValue Col{0} { get; set; }", ix).ToArray()));
    

    Now to add some decoration to allow some reflection going - hellzyes - let's make a startup that sells this awesomeness...

  • Robert Hanson (unregistered)

    This could have been an code-gen'ed class based on the columns in the database. If the underlying database table has columns labeld col1, col2, col3..., then this makes perfect sense. Then its not the Senior Developer's fault, but the DBA's fault -- and probably not even his fault, but the BA's fault for failing to understand the requirements and formulate them in terms of the business domain.

    If it were me, and the DB table was structured with these column names, then I'd autogen this class as a DTO object, then create a class that maps this class to a real domain object; and use the real domain object in my business layer.

  • barf 4 eva (unregistered)

    Man, that's some serious grade A-hole code.

  • (cs) in reply to Shinobu
    Shinobu:
    Shinobu:
    (think you Wikipedia)
    s/think/thank/ Comment on someone's spelling and you will without fail mess up yourself.
    Muphry's Law strikes again! ( http://en.wikipedia.org/wiki/Muphry%27s_law )
  • e john (unregistered)

    Yes, I have tried arrays. I like them a lot because the syntax [] makes me think that i am putting things in nice little boxes, just like for Christmas.

    also sometimes the thing that comes out of the box is a big surprise, just like on Christmas.

    captcha - tego: [verb] to strike a pose and sell your piety whenever a camera is turned your way, as for example on a football field.

  • gravis (unregistered) in reply to Vin
    Vin:
    Ah, so you spotted that. I wondered if anyone would. Well, an upgrade isn't currently an option here at <name-deleted> Bank. It's 2003 only for now.
    Hahaha I wonder if it's the same bank I used to work for. When I left there in 2005, they still had NT 4 and Office 97.... and those were developer workstations, I can only imagine what the "regular users" had! ;-)
  • Henrik W. (unregistered)

    This reminds me so much of my first programming assignment at school looong ago.

    Pascal was the primary programming language to learn back then, and I took an assignment to program a bowling score counting program. The program took in bowling scores for two players and then counted "real-time" the sum with strikes etc. It even had nice colors and I made an manual even!

    I think I got a full 10/10 of the assignment, but the teacher commented on my solution; "You could have used arrays.". And I was like "WTF, why didn't you tell me about arrays!", and right away saw a solution in my head reducing 80% of the code.

    I still have the program on a 3.5" floppy disk about 20 years later..

  • causa (unregistered) in reply to Henrik W.

    So have you re-written it using arrays yet? It's not too late, the teacher might still give you extra-credit retroactively. ;-)

  • uns (unregistered) in reply to Dave
    Dave:
    Maybe it was just a matter of poor word choice!

    Developer: "Boss, have you seen this table? I want arrays!"

    Boss: "No way you're getting a raise; just deal with it!"

    =0)

    +27, funny

  • Shark8 (unregistered) in reply to Cbuttius
    Cbuttius:
    The day compilers start complaining about bad style, which obviously includes this WTF and most other Code SODs (which work but are badly written code) - well it would be a good day for good software engineers of course but it will never happen because nobody will use such a compiler.
    Actually GNAT can issue warnings on bad-style, and IIRC automatically correct it. {-gnaty switch for style-checks, IIRC; though I forget the reformat-with-style command.}

    Of course this makes some sense for a compiler for a language that was designed with readability/maintenance in mind. (Ada)

  • PiersyP (unregistered) in reply to ObiWayneKenobi

    Un . . . fucking . . . believable!!!

  • bob_long_nose (unregistered) in reply to ObiWayneKenobi
    ObiWayneKenobi:
    Anonymous Paranoiac:
    Even if you have somehow never heard of data structures that could handle this sort of thing for you, if your brain can produce this kind of code without screaming, "THERE HAS TO BE A BETTER WAY!" (and then searching for said better way), you should not be allowed near source code.

    Besides, TRWTF is tables with 700 columns.

    Having seen this mentality many times in the past (I was fired two months ago from a job I had for nearly two years for trying to get the team to realize "there has to be a better way"), let me explain why it usually happens. The "senior developer" was probably given a task that needed to be done fast, with little or no requirements. Said "senior", not wanting to ever say "No" or "I need more time" or "I need requirements" to his boss, did this in the first thing that came to mind: properties for everything. He never once thought of a better way, because he finished the task as fast as humanly possible and forgot all about it. When he had to add things, he couldn't ask for the day or so to go back and change it to an array, so he did the next logical thing: Simply add to it, that way he could just copy and paste what he had done previously and finish the task in a matter of seconds instead of "wasting" a day or more refactoring.

    That's the mentality of these kind of people. They don't think, because all they focus on is hacking up a solution as fast as possible because they dare not appear to be wasting time to the boss, and they continue to have that mentality by just copying and pasting their poor solutions all over the place.

    And yes, I've dealt with something similar to this, although we didn't even use a class we just accessed the DataSet raw, since there were so many columns. At least that's not as WTFy as this nonsense.

    I don't buy it. It's not that it's an invalid excuse. Management loves brandishing the whip, faster, faster, and if you trip over it's you're fault. However, any programmer who can't even roll up something so trivial with loops, maps and arrays is not worth his salt.

  • hf (unregistered)

    TRWTF is that there are 701 columns there, not 700.

  • (cs) in reply to uns
    uns:
    Dave:
    Maybe it was just a matter of poor word choice!

    Developer: "Boss, have you seen this table? I want arrays!"

    Boss: "No way you're getting a raise; just deal with it!"

    =0)

    +27, funny

    Loved that too. Dilbert-style.

  • Matt (unregistered)

    So WTF does the code that uses this thing look like? Seems like after writing a little of it, even a moron would realize something is wrong and go back and reconsider...

  • Andrei Rinea (unregistered) in reply to ObiWayneKenobi

    I don't get it. Wasn't even faster to use fields instead of properties?!

  • m0lten (unregistered)

    Maaann, this reminds me of a solution I've seen for our in house "shopping cart", developed by an outsourced team.

    We had a small number of products sold at different price points ($27, $37, $47, $67, and $97).

    So instead of having a column for price point the item was sold at, the table had 5 boolean columns like price27, price37, etc... WTFFFFF? WHO THINKS THAT WAY?

  • Haakon (unregistered) in reply to ObiWayneKenobi

    The problem with this idea, is that the code above you takes about 3 minutes to write, if you know Emacs.

    Here's the code, even:

    (defun stupid-codegen (from to)
      (interactive "nGenerate from: \nnGenerate to: ")
      (insert "#region Public Properties\n\n")
      (let ((i from))
        (while (<= i to)
          (progn
            (insert
             (concat
              (format "public HistoryResultValue Col%d" i)
              "{\n"
              "get;\n"
              "set;\n"
              "})\n\n"))
            (incf i)))))
    

    This does not indent the code, nor does it add the date column, but now we don't have to write all of this by hand.

    And any code changes can be done swiftly and neatly by changing the code-generation in Emacs as well, so there's none of that "change four-hundred things" problem that you'd normally have.

    You could in fact rather easily generate an emacs script that finds the #region and #end-region comments, deletes everything between them, and regenerates the code from a template you give in the script-file.

    Which scarily enough, might actually work. (And even more scary, some person reading this will think, "Hey, that's genius!")

  • (cs) in reply to Ben Jammin
    Ben Jammin:
    ObiWayneKenobi:
    ... (I was fired two months ago from a job I had for nearly two years for trying to get the team to realize "there has to be a better way") ...

    Did you get fired cause you said "there has to be a better way," or did you get fired for calling that senior developer "a talent-less boob who could be replaced by a high school hack and would contribute more by scrubbing toilets than by producing this filth"? Not saying you'd be wrong by saying that, I'm just curious.

    Neither. I suspect I was fired because almost weekly when I would meet with the CIO (I was filling the role of team lead after the dev manager quit) I would mention how there were serious structural issues with the code (as in it would crash several times a day) that should be addressed before trivial things such as replacing all popup windows with Ajax sliders because the executives all used iPads (but few, if any, customers did) and popups didn't render correctly.

    The "senior" in question would also take half-days simply because he was antisocial and didn't feel like having a meeting with the rest of the team, and would agree to implementing new things only to go behind the team's back to the CIO and get the idea shot down just before we actually switched to it (i.e. after testing it for days/weeks) because he decided he didn't want to learn something new.

Leave a comment on “Have you Tried Arrays?”

Log In or post as a guest

Replying to comment #:

« Return to Article