Comment On Deep Copy

A little more than a year ago, Nathan T's company decided to outsource a large portion of certain project to a certain country many thousands of miles away. "Even if the code quality isn't as good," one manager would often say, "we'll just pay them to rewrite it and rewrite it again. It'll still be less expensive." [expand full text]
« PrevPage 1 | Page 2 | Page 3Next »

Re: Deep Copy

2008-04-16 08:02 • by anon (unregistered)
classic ... so does that mean that that primitives are now references ... :-s

Re: Deep Copy

2008-04-16 08:02 • by Marketing droids (unregistered)
Wow, that's... deep, man.

Re: Deep Copy

2008-04-16 08:04 • by 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."

Re: Deep Copy

2008-04-16 08:04 • by dude (unregistered)
What's wrong? It just wastes some processor cycles, casting something as a String, then recasting it as a int...

Re: Deep Copy

2008-04-16 08:08 • by 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.

Re: Deep Copy

2008-04-16 08:09 • by Dembinjo (unregistered)
dejavu - from my company ;)

Re: Deep Copy

2008-04-16 08:16 • by vt_mruhlin
int j = int.Parse(i.ToString());


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

Re: Deep Copy

2008-04-16 08:16 • by 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".

Re: Deep Copy

2008-04-16 08:20 • by Jeroen Brattinga (unregistered)
int j = i;    // provides shallow copy of i

Re: Deep Copy

2008-04-16 08:22 • by brazzy
190011 in reply to 190003
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.

Re: Deep Copy

2008-04-16 08:23 • by Talis (unregistered)
190012 in reply to 189999
anon:
classic ... so does that mean that that primitives are now references ... :-s


"clbuttic", I suppose?

Re: Deep Copy

2008-04-16 08:24 • by snoofle
190014 in reply to 190010
I gotta ask - did they also do it for floats and doubles (which always resolve to an absolute value when converting to/from strings)?

Re: Deep Copy

2008-04-16 08:26 • by ounos
i //provides shallow copy of i

Re: Deep Copy

2008-04-16 08:27 • by SomebodyElse
190017 in reply to 190011
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.

Re: Deep Copy

2008-04-16 08:34 • by akatherder
I wonder what any declaration with a magic number would be like.

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

Re: Deep Copy

2008-04-16 08:37 • by brazzy
190022 in reply to 190017
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?

Re: Deep Copy

2008-04-16 08:41 • by Frunobulax (unregistered)
190023 in reply to 190009
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 ;)

Re: Deep Copy

2008-04-16 08:41 • by DOA
190024 in reply to 190022
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!"

Re: Deep Copy

2008-04-16 08:56 • by Roman Kennke (unregistered)
190029 in reply to 190005
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.

Re: Deep Copy

2008-04-16 08:57 • by loe (unregistered)
Perhaps it was providing a copy to someone named Deep?

Re: Deep Copy

2008-04-16 08:58 • by Zecc
190031 in reply to 190022
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).

Re: Deep Copy

2008-04-16 08:59 • by 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));

Re: Deep Copy

2008-04-16 09:06 • by 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!

Re: Deep Copy

2008-04-16 09:06 • by ubersoldat
190035 in reply to 190032
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.

Re: Deep Copy

2008-04-16 09:10 • by 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).

Re: Deep Copy

2008-04-16 09:12 • by Brandon (unregistered)
190039 in reply to 190030
loe:
Perhaps it was providing a copy to someone named Deep?


Epic fail

Re: Deep Copy

2008-04-16 09:12 • by Edward Royce (unregistered)
190040 in reply to 190011
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?

Re: Deep Copy

2008-04-16 09:13 • by brazzy
190041 in reply to 190031
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.

Re: Deep Copy

2008-04-16 09:18 • by snoofle
190042 in reply to 190005
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
...
}
}


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

Re: Deep Copy

2008-04-16 09:18 • by 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.

Re: Deep Copy

2008-04-16 09:24 • by I walked the dinosaur (unregistered)
190046 in reply to 190030
loe:
Perhaps it was providing a copy to someone named Deep?


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

Re: Deep Copy

2008-04-16 09:29 • by brazzy
190047 in reply to 190040
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.

Re: Deep Copy

2008-04-16 09:34 • by CapitalT
Remember kids:
"Cheap Elbonian outsourcing companies suck because they are cheap outsourcing companies, not because they're Elbonians"

</futile attempt to stop racism>

Re: Deep Copy

2008-04-16 09:36 • by 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?

Re: Deep Copy

2008-04-16 09:38 • by operagost
190051 in reply to 190002
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?

Re: Deep Copy

2008-04-16 09:40 • by n9ds
190052 in reply to 190030
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!

Re: Deep Copy

2008-04-16 09:51 • by Zecc
190053 in reply to 190050
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.

Re: Deep Copy

2008-04-16 09:54 • by Pope
190055 in reply to 190050
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());

Re: Deep Copy

2008-04-16 09:56 • by ljj116
190056 in reply to 190038
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.

Re: Deep Copy

2008-04-16 09:57 • by k (unregistered)
190057 in reply to 190050
If i is declared somewhere in scope, then yes it's valid C#.

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

Re: Deep Copy

2008-04-16 09:58 • by Walleye (unregistered)
190058 in reply to 190047
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.

Re: Deep Copy

2008-04-16 10:00 • by k (unregistered)
190059 in reply to 190057
"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*

Re: Deep Copy

2008-04-16 10:03 • by Anonymous (unregistered)
Not exactly similar, but I recently saw some code along the lines of:

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

Re: Deep Copy

2008-04-16 10:11 • by FredSaw
190064 in reply to 190040
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.

Re: Deep Copy

2008-04-16 10:14 • by bryan986
190065 in reply to 190035
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.

Re: Deep Copy

2008-04-16 10:14 • by 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()").

Re: Deep Copy

2008-04-16 10:17 • by dpm
190068 in reply to 190058
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?"

Re: Deep Copy

2008-04-16 10:21 • by olm
190074 in reply to 190042
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
...
}
}

The funny thing is that if the compiler uses any optimizations, the compiled code would probably not be according to specs :o)

Re: Deep Copy

2008-04-16 10:22 • by AMerrickanGirl
190075 in reply to 190046
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?

Re: Deep Copy

2008-04-16 10:34 • by buffi (unregistered)
190078 in reply to 190062
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...).
« PrevPage 1 | Page 2 | Page 3Next »

Add Comment