• (cs)

    "An array consumes too much memory! That would be terribly inefficient." "This implementation provides much more extensibility!"

    I can see the 'Senior Developer' was practicing Leveraged Synergies.

  • (cs)

    I won't have to support this once I'm done making it!

  • (cs)

    That's 701 columns.

  • Anon (unregistered)

    public static readonly int ColsMaxCapacity = 700;

    Yet the columns start at Col0 and finish at Col700. That's the real WTF... well that and the whole bloody thing.

  • Gary (unregistered)

    What isn't shown is the wrapper method:

    public HistoryResultValue getHistoryResult(string col) {
      return eval("this.col" + col);
    }
    

    Yeah, and I don't care if there is no eval and I don't know how to do string concatenation. It's a joke. So there.

  • Anon2 (unregistered) in reply to Anon

    Ah, but 701 columns makes it flexible so that it can handle sets that start with column 0 or column 1! Brillant!

  • (cs)
    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
    }
    
  • Tim (unregistered)

    Thats just terribad but unfortunately not unlikely...

  • Highwire (unregistered)

    Why stop here? Support for variable column amounts is easily implemented!

    -HistoryResultRowWith001Cols.cs -HistoryResultRowWith002Cols.cs

    ...and so on, ad nauseum...

    -HistoryResultRowWith699Cols.cs -HistoryResultRowWith700Cols.cs

  • Toolbag (unregistered)

    I think my brain just puked

  • Smug Unix User (unregistered)

    This is done for security.

  • Pista (unregistered)

    Now, it's this kind of coding that makes me think that death penalty (to which I'm firmly opposed) is not such a bad idea, after all.

  • AGray (unregistered)

    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!

  • (cs) in reply to Zecc
    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!
  • Bernie The Bernie (unregistered)

    Hey, that guy is missing the private variables for storing the value internally. And the Property Changed events! He has to re-write all those things, like:

        private HistoryResultValue _Col0;
        public HistoryResultValue Col0
        {
            get { return _Col0; }
            set 
            {
                if (value != _Col0)
                {
                    _Col0 = value;
                    if (this.PropertyChanged != null)
                    {
                       this.PropertyChanged("Col0");
                    }
                }
            }
        }
    
  • Wolfraider (unregistered) in reply to Anketam
    Anketam:
    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!

    Your line count is down for the day, you have been demoted to coffee boy

  • Anonymous Paranoiac (unregistered)

    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.

  • ¯\(°_o)/¯ I DUNNO LOL (unregistered)

    Apparently the "senior developer" had a "senior moment" when he wrote that.

  • Ho Miscreant! (unregistered)

    The data set has up to 700 columns because the senior developer also developed the database. He decided to just use one big flat table to cut down on joins. This was presumably done for "performance" reasons.

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

  • Delve (unregistered)

    Data normalization is for PFYs. Even they should have better things to do. Like fetching the senior developer's coffee and combing the bits of donut out of his beard so he can concentrate on adding support for an additional 324 columns (forwards compatible with expanding business requirements and powers of 2 are more efficient).

  • Old fart (unregistered)

    This will be much easier to later maintain if we ever need to add pre-processing rules to a column of data.

  • pantsman (unregistered)

    TRWTF is #region. Who needs types or semantics when you can express everything in terms of IDE code folding?

  • Harald (unregistered)

    The comments speaking about regions reek of someone being socialized in the mainframe world. This would not explain the absence of arrays, though - even COBOL allowed them. ;-)

  • dan_linder (unregistered)
    public HistoryResultValue

    "My God! It's full of HistoryResultValues..."

    • Dave, 2012 "A Senior Odyssey"
  • Harald (unregistered) in reply to Harald
    Harald:
    The comments speaking about regions reek of someone being socialized in the mainframe world. This would not explain the absence of arrays, though - even COBOL allowed them. ;-)
    Oops, it was the region directive and not a comment. Sorry.
  • dan_linder (unregistered) in reply to dan_linder

    Dang...that should have been a "Diego" quote. :(

  • RandomGuy (unregistered) in reply to Gary
    Gary:
    What isn't shown is the wrapper method:
    public HistoryResultValue getHistoryResult(string col) {
      return eval("this.col" + col);
    }

    But that's way to inefficient. You can achieve the same with a simple if/elseif construct:

    public HistoryResultValue getHistoryResult(string col) {
      if(col=="0")
        return Col0;
      else if(col=="1")
        return Col1;
      // ...
      else print "Invalid column!";
    }
  • Contractor (unregistered) 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!

    You see, that's why you will never get promoted to senior developer or management roles... All you have managed by doing this is to increase the bugs per line metric.

    Me also thinks the senior developer was once a contractor paid by lines of code... Offcourse, the company could not let him go after this, and hired and promoted him ... Story of life ...

  • Dave (unregistered)

    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)

  • Your Name (unregistered) 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!

    No, I'm pretty sure that the SLOC metrics in place there would indicate that an 80% reduction in SLOC indicates that the project is now 80% farther from completion! Any reduction indicates low productivity, don't you know.

  • Ben Jammin (unregistered)

    This was obviously written in the brief span of time that C# didn't support arrays, but did support automatic properties.

  • TonyPony (unregistered)

    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)

  • Junior_G (unregistered)

    private string GetRepeatedSourceCode(int numOfRetardation) { string result = ""; for (int i = 0; i <= numOfRetardation; i++) { result += "public HistoryResultValue Col" + i.ToString() +" { get; set; }";

            }
            return result;
        }
    
  • (cs)

    Not sure what language this is, but in Java he could just use reflection to access the columns. Build another class that accepts something like obj.getHistoryResult(34) and it would use reflection to call the correct method.

    Or, of course, he could just do something lame like implement it as an array...

  • (cs)

    The sad thing is that I've seen people implement this pattern because they think it'll save time over arrays. Yeah, no. Although it might save a single arithmetic instruction on a compiler that's terrible at optimizing, the cache performance, along with the getter/setter function overhead, will result in an overall drop in performance, guaranteed.

    Nowadays, with optimizing compilers and well-designed standard libraries, it's incredibly unlikely that small optimizations to your existing algorithm are going to make a difference.

    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.

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

    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).

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

    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).

    "For not using columns" = "For not using collections"

  • Vin (unregistered)

    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;    }
  • Vin (unregistered)

    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;    }

  • chfexcel (unregistered)

    An excellent table...

    *captcha: ludus Let's play with arrays ?

  • (cs)

    Is it just me, or is anyone else dying to see how HistoryResultValue is defined?

  • (cs) in reply to JamesCurran
    JamesCurran:
    Is it just me, or is anyone else dying to see how HistoryResultValue is defined?

    As an enum that stores every possible 64-bit int.

    Of course that's impossible, so they just kinda had to add values to it as they went. As a result, INT_300000 has the actual value 3255.

    Addendum (2012-09-27 12:52): And for the record, when I say "impossible," I mean that if you were able to find a place to buy 128 GB microSD cards en masse, you would over 17 billion of them to store such a file, and that's with some pretty conservative estimates for how large such an enum declaration would be.

    Incidentally, that many micro SD cards would occupy a cube 11.23 meters to each side and would weigh 4.3 kilotons.

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

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

    It does under -Wall, I think the warning is "condition is always true due to data type limits" or something like that.

    This is why you always use -Wall when using GCC.

  • Faded (unregistered)

    I am not a senior developer. I am self taught script kiddy. Even I know better than to do this. If this is what senior developers do I am glad I am not one.

  • (cs) in reply to Cbuttius
    Cbuttius:
    That's 701 columns.
    He's probably missing column 267 or something dumb. Wondered why he was getting an error and just added another one.
  • (cs) 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. 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".

  • Vlad Patryshev (unregistered) in reply to ObiWayneKenobi

    Agreeing re: TRWTF, I wonder whether normalization would lead to 350 tables or 699 tables. It depends, I guess.

  • C-Derb (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".

    There's never time to do it right, but there's always time to do it over.

    It is very demoralizing when you constantly have to justify and explain why a quick hack is a bad approach to people who pretend to understand programming. More so when one of those people is the "Senior Dumbass".

Leave a comment on “Have you Tried Arrays?”

Log In or post as a guest

Replying to comment #:

« Return to Article