• anon (unregistered)

    classic ... so does that mean that that primitives are now references ... :-s

  • Marketing droids (unregistered)

    Wow, that's... deep, man.

  • dpm (cs)

    A little more than three years ago, DPM's country decided to continue outsourcing a large portion of certain decision-making to a certain person many thousands of miles away from reality. "Even if their choices aren't as good," voters would often say, "we'll just re-elect them to decide it again. It'll still be less thinking on our part."

  • dude (unregistered)

    What's wrong? It just wastes some processor cycles, casting something as a String, then recasting it as a int...

  • biziclop (unregistered)

    That's not unlike what I've seen once:

    int param = new Integer( paramString ).parseInt( paramString );

    It gives your code a nice and unique twist.

  • Dembinjo (unregistered)

    dejavu - from my company ;)

  • vt_mruhlin (cs)
    int j = int.Parse(i.ToString());

    Actually provided a "deep copy" of j, rather than i? That IS impressive.

  • Survey User 2338 (unregistered)

    Oh wow this is freaky because that is the same code that I posted to a forum to a question about holding a variable in memory. The chap seemed genuinely grateful when I responded to his request "to do the needful and plz email me teh codez".

  • Jeroen Brattinga (unregistered)
    int j = i;    // provides shallow copy of i
  • brazzy (cs) in reply to dude
    dude:
    What's wrong? It just wastes some processor cycles, casting something as a String, then recasting it as a int...
    It only shows, as does your comment, a fundamental lack of understanding of the mechanics of the programming environment they're using. While this line is not outright erroneous, it allows us to extrapolate that the rest of the code is going to be chock full of idiotical cargo cult programming with hidden bugs - and, of course, a nightmare to maintain.
  • Talis (unregistered) in reply to anon
    anon:
    classic ... so does that mean that that primitives are now references ... :-s

    "clbuttic", I suppose?

  • snoofle (cs) in reply to Jeroen Brattinga

    I gotta ask - did they also do it for floats and doubles (which always resolve to an absolute value when converting to/from strings)?

  • ounos (cs)

    i //provides shallow copy of i

  • SomebodyElse (cs) in reply to brazzy
    brazzy:
    dude:
    What's wrong? It just wastes some processor cycles, casting something as a String, then recasting it as a int...
    It only shows, as does your comment, a fundamental lack of understanding of the mechanics of the programming environment they're using. While this line is not outright erroneous, it allows us to extrapolate that the rest of the code is going to be chock full of idiotical cargo cult programming with hidden bugs - and, of course, a nightmare to maintain.

    Somebody's sarcasm detector is on the fritz. You should get that checked out if you are going to posting to an internet forum.

  • akatherder (cs)

    I wonder what any declaration with a magic number would be like.

    int i = int.Parse(12.ToString()); // global declaration

  • brazzy (cs) in reply to SomebodyElse
    SomebodyElse:
    Somebody's sarcasm detector is on the fritz. You should get that checked out if you are going to posting to an internet forum.
    I suppose the original code was also sarcasm, just a little joke the foreign programmers played on the foolish Americans while holding back the clean, competent, well-designed version to see how far they could take it?
  • Frunobulax (unregistered) in reply to Survey User 2338
    Survey User 2338:
    [snip]... "to do the needful and plz email me teh codez".

    Ha ha. "do the needful"... Yeah, never heard that line before I got into this type of industry... Apparently, there is still some sort of language barrier, though. Here, I thought that "do the needful" meant "do everything that is needed to get the task done correctly, completely, and on time." But, what it actually means is: "do everything in the worst way possible while making sure only half the code works, half of the code is present, and the deadline is exceeded by a minimum of 1.5 months."

    I never knew learning another language would be so darn tricky ;)

  • DOA (cs) in reply to brazzy
    brazzy:
    SomebodyElse:
    Somebody's sarcasm detector is on the fritz. You should get that checked out if you are going to posting to an internet forum.
    I suppose the original code was also sarcasm, just a little joke the foreign programmers played on the foolish Americans while holding back the clean, competent, well-designed version to see how far they could take it?
    "Those snotty Americans thinking they're all superior... If all foreigners write crappy code, then I might as well oblidge you. Here, see how fun it is to maintain this! muhahahahahahah!"
  • Roman Kennke (unregistered) in reply to biziclop
    biziclop:

    int param = new Integer( paramString ).parseInt( paramString );

    It gives your code a nice and unique twist.

    Indeed. Parsing the string twice makes the copy even deeper.

  • loe (unregistered)

    Perhaps it was providing a copy to someone named Deep?

  • Zecc (cs) in reply to brazzy
    brazzy:
    I suppose the original code was also sarcasm, just a little joke the foreign programmers played on the foolish Americans while holding back the clean, competent, well-designed version to see how far they could take it?
    I don't think there's anything on the original post keeping you from thinking that the code might have been outsourced to the Americans from, say, some small island in the Pacific (it's probably expensive to find programmers on Easter Island).
  • Matt (unregistered)

    That reminds me of some code I once saw. The code existed in a test case, but it still hurt my eyes.

    The code that originally existed in the test case had these two lines (which seems unnecessary in itself): string val = "SomeValue"; string copy = (string)val.Clone();

    Well, some developer removed that Clone line and replaced it with the following:

    string copy = val + "x"; copy = copy.Substring(0, copy.Length - 1);

    And then to cap it off... Debug.Assert(!Object.ReferenceEquals(val, copy));

  • mb (unregistered)

    TRWTF is that it provides a deep copy of j not i.

    Or maybe this is the difference to

    int j=i;
    which would a (not so deep?) copy of i.

    Oh no! now I understand, this is code from the southern hemisphere, there lhs and rhs are reversed!

  • ubersoldat (cs) in reply to Matt
    Matt:
    That reminds me of some code I once saw. The code existed in a test case, but it still hurt my eyes.

    The code that originally existed in the test case had these two lines (which seems unnecessary in itself): string val = "SomeValue"; string copy = (string)val.Clone();

    Well, some developer removed that Clone line and replaced it with the following:

    string copy = val + "x"; copy = copy.Substring(0, copy.Length - 1);

    And then to cap it off... Debug.Assert(!Object.ReferenceEquals(val, copy));

    Wow... it this for real? I mean, maybe ONE person can fuck things up, but TWO in TWO lines of code? Yeah! It's traumatic, so much that you recall after it.

  • me (unregistered)

    Too bad Alex doesn't quite grasp what "object oriented" means either -- otherwise he could never write such nonsense about OO and passing by reference vs. by value (hint: not related in the slightest).

  • Brandon (unregistered) in reply to loe
    loe:
    Perhaps it was providing a copy to someone named Deep?

    Epic fail

  • Edward Royce (unregistered) in reply to brazzy
    brazzy:
    dude:
    What's wrong? It just wastes some processor cycles, casting something as a String, then recasting it as a int...
    It only shows, as does your comment, a fundamental lack of understanding of the mechanics of the programming environment they're using. While this line is not outright erroneous, it allows us to extrapolate that the rest of the code is going to be chock full of idiotical cargo cult programming with hidden bugs - and, of course, a nightmare to maintain.

    "idiotical cargo cult programming"

    Ok am I wrong to really like that phrase?

  • brazzy (cs) in reply to Zecc
    Zecc:
    brazzy:
    I suppose the original code was also sarcasm, just a little joke the foreign programmers played on the foolish Americans while holding back the clean, competent, well-designed version to see how far they could take it?
    I don't think there's anything on the original post preventing you from thinking that the code was outsourced to the Americans...
    The submitter's name hints towards the outsorcers being American. Nothing definitive, of course.
  • snoofle (cs) in reply to biziclop

    This reminds me of some code we once had to write (for military security) to erase memory (pseudo):

    for (int i=0; i<MAX_MEMORY; i++) {
        for (int pass=0; pass<3; pass++) { // required by mil spec
            memory[i]=0xa5a5; // dump pattern
            memory[i]=0x5a5a; // invert all bits
            ...
        }
    }
    </pre>
    

    Granted, this has an actual purpose, but still... memories!

  • Edward Royce (unregistered)

    Well this kinda reminds me of my last job, which ended when the work got moved to India. The dev team in India decided instead of having all these pesky data tables they'd just format all the data into XML and then mash everything together into an enormous table with essentially 1 XML column.

    Yeah ugly isn't the word for it.

  • I walked the dinosaur (unregistered) in reply to loe
    loe:
    Perhaps it was providing a copy to someone named Deep?

    Of course...everyone over there is named Sandeep.

  • brazzy (cs) in reply to Edward Royce
    Edward Royce:
    "idiotical cargo cult programming"

    Ok am I wrong to really like that phrase?

    While "idiotical" was my own addition, the term "cargo cult programming" is well established, probably because it's all too fitting and therefore likeable to people who's had to maintain code written in that mindset.

  • CapitalT (cs)

    Remember kids: "Cheap Elbonian outsourcing companies suck because they are cheap outsourcing companies, not because they're Elbonians"

    </futile attempt to stop racism>

  • Andy (unregistered)

    Sorry to get serious here, but I am courious. The code:

      int j = int.Parse(i.ToString()); // provides deep copy of j 
    

    Is not valid java, it shouldnot compile for two separate reasons. Since I don't know c#, can someone tell me if this is actually valid code in any language?

  • operagost (cs) in reply to dpm
    dpm:
    A little more than three years ago, DPM's country decided to continue outsourcing a large portion of certain decision-making to a certain person many thousands of miles away from reality. "Even if their choices aren't as good," voters would often say, "we'll just re-elect them to decide it again. It'll still be less thinking on our part."
    Where?
  • n9ds (cs) in reply to loe
    loe:
    Perhaps it was providing a copy to someone named Deep?
    Hmmm, my father used to be nicknamed "Deep", and that was back in the 1930's. Maybe he was just way ahead of his time!
  • Zecc (cs) in reply to Andy
    Andy:
    Sorry to get serious here, but I am courious. The code:
      int j = int.Parse(i.ToString()); // provides deep copy of j 
    

    Is not valid java, it shouldnot compile for two separate reasons. Since I don't know c#, can someone tell me if this is actually valid code in any language?

    Yes, it is valid c#. If I remember correctly, the primitives are auto-boxed.

  • Pope (cs) in reply to Andy
    Andy:
    Sorry to get serious here, but I am courious. The code:
      int j = int.Parse(i.ToString()); // provides deep copy of j 
    

    Is not valid java, it shouldnot compile for two separate reasons. Since I don't know c#, can someone tell me if this is actually valid code in any language?

    Yep. "Valid" in C#.

    But really, if you're going to do it right, you should take it seriously:

    int j = System.Convert.ToInt32((string)int.Parse(i.ToString()).ToString());

  • ljj116 (cs) in reply to me
    me:
    Too bad Alex doesn't quite grasp what "object oriented" means either -- otherwise he could never write such nonsense about OO and passing by reference vs. by value (hint: not related in the slightest).

    More sarcasm? My sarcasm detector isn't quite sure on this one.

    Value types and reference types are mentioned because of the "deep copy" comment. Value types don't need deep copied. Hence the humor? (We're forced to assume that i is an int here)

    I must say though, if ever an int needed deep copied, this is a great attempt. :)

    The only better solution I could think of would be to write i out to a file and read it back into j. That's uber deep.

  • k (unregistered) in reply to Andy

    If i is declared somewhere in scope, then yes it's valid C#.

    but as previously pointed out they may mean j.ToString()

  • Walleye (unregistered) in reply to brazzy
    brazzy:
    While "idiotical" was my own addition, the term "cargo cult programming" is well established, probably because it's all too fitting and therefore likeable to people who's had to maintain code written in that mindset.

    True. And I find that companies that use "cargo cult programming" also tend to use "voodoo tech support". That's when some unrelated change to a machine's configuration seems to fix an intermittent problem, at least temporarily, so that "fix" becomes the standard.

  • k (unregistered) in reply to k

    "but as previously pointed out they may mean j.ToString()"

    urgh - I WTF'd my own entry! Dunno where that came form . Blame the excess of biscuits floating round the department today...

    shoots self quietly

  • Anonymous (unregistered)

    Not exactly similar, but I recently saw some code along the lines of:

    if (i * 0 == 0) {i = j;}

  • FredSaw (cs) in reply to Edward Royce
    Edward Royce:
    brazzy:
    It only shows, as does your comment, a fundamental lack of understanding of the mechanics of the programming environment they're using. While this line is not outright erroneous, it allows us to extrapolate that the rest of the code is going to be chock full of idiotical cargo cult programming with hidden bugs - and, of course, a nightmare to maintain.

    "idiotical cargo cult programming"

    Ok am I wrong to really like that phrase?

    Don't forget "hidden bugs". As opposed to the ones in plain sight, you understand.

  • bryan986 (cs) in reply to ubersoldat
    ubersoldat:
    Matt:
    That reminds me of some code I once saw. The code existed in a test case, but it still hurt my eyes.

    The code that originally existed in the test case had these two lines (which seems unnecessary in itself): string val = "SomeValue"; string copy = (string)val.Clone();

    Well, some developer removed that Clone line and replaced it with the following:

    string copy = val + "x"; copy = copy.Substring(0, copy.Length - 1);

    And then to cap it off... Debug.Assert(!Object.ReferenceEquals(val, copy));

    Wow... it this for real? I mean, maybe ONE person can fuck things up, but TWO in TWO lines of code? Yeah! It's traumatic, so much that you recall after it.

    Not sure if there was an error in transcription, but there is a lower case 's' on 'string'. Maybe they have their own string class and needed to check that it works properly. Still a WTF in either case.

    Addendum (2008-04-16 10:22): I guess I don't know what language it is, so my comment might not apply.

  • Oleg K (unregistered)

    This particular line of code is perfectly fine, the comment is incorrect. i can be an object, which is converted to a string and then to an integer.

    int j = int.Parse(i.ToString()); // provides deep copy of j

    (btw, it should start with lowercase "t" as in ".toString()").

  • dpm (cs) in reply to Walleye
    Walleye:
    And I find that companies that use "cargo cult programming" also tend to use "voodoo tech support". That's when some unrelated change to a machine's configuration seems to fix an intermittent problem, at least temporarily, so that "fix" becomes the standard.
    "Have you tried rebooting, ma'am?"
  • olm (cs) in reply to snoofle
    snoofle:
    for (int i=0; i<MAX_MEMORY; i++) {
        for (int pass=0; pass<3; pass++) { // required by mil spec
            memory[i]=0xa5a5; // dump pattern
            memory[i]=0x5a5a; // invert all bits
            ...
        }
    }
    </pre>
    The funny thing is that if the compiler uses any optimizations, the compiled code would probably not be according to specs :o)
  • AMerrickanGirl (cs) in reply to I walked the dinosaur
    I walked the dinosaur:
    loe:
    Perhaps it was providing a copy to someone named Deep?

    Of course...everyone over there is named Sandeep.

    Would everyone in Japan be Deep-san?

  • buffi (unregistered) in reply to Anonymous
    Anonymous:
    Not exactly similar, but I recently saw some code along the lines of:

    if (i * 0 == 0) {i = j;}

    It could make sense in a language with operator overloading (python or whatever...).

Leave a comment on “Deep Copy”

Log In or post as a guest

Replying to comment #:

« Return to Article