Democratic Underground Latest Greatest Lobby Journals Search Options Help Login
Google

Deep Copy

Printer-friendly format Printer-friendly format
Printer-friendly format Email this thread to a friend
Printer-friendly format Bookmark this thread
This topic is archived.
Home » Discuss » Topic Forums » Science Donate to DU
 
bananas Donating Member (1000+ posts) Send PM | Profile | Ignore Sat Apr-26-08 07:35 AM
Original message
Deep Copy
Some people say that education in science in technology will eliminate superstitious beliefs.
I don't think so...we just get new and more bizarre superstitious beliefs.
Is there any difference between the coders in this article and B.F. Skinner's pigeons?

http://thedailywtf.com/Articles/Deep-Copy.aspx

Deep Copy 2008-04-16
by Alex Papadimoulis in Representative Line (149 Comments)

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

Extended that logic even further, management decided to not only outsource overseas, but outsource to the cheapest overseas firm they could find. Eventually, they'd end up with solid code, right?

As it turned out, each iteration of their code got more and more... interesting. The developers across the pond didn't quite grasp the basics of object-oriented programming (especially the whole "reference type" versus "value type" thing), and ended up writing a lot of "superstitious" code to make sure the compiler would do exactly what they wanted. Of course, being that the outsourcing firm delivered well over hundreds of thousands of lines of superstitious code, there's really only one way to represent it all:

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

At least that line worked... if only the other 99,999 lines would.

Printer Friendly | Permalink |  | Top
Dogmudgeon Donating Member (1000+ posts) Send PM | Profile | Ignore Sat Apr-26-08 08:15 AM
Response to Original message
1. Is it Superstition, or is it Microsoft?
That looks like C# code intended to appear as a Big Honkin' Deal in a code profiler, even if the native bytecode format is being profiled to get around the old code format tricks. But ghosts in the machine are not required for this WTF, only the incentive "500 lines of code a day with the highest fan-out you can manage -- or you're fired!" When you're paying "http://en.wikipedia.org/wiki/Cyclomatic_complexity">cyclomatically" -- by the amount of things the code (looks like it) is doing -- you get stuff (and I do mean stuff) like this.

Two things that keep an art at a high level are the pride of its artists and the honesty of its craftsmen. Our generation of middle-level managers learned the word "metrics" but never heard the old writer's maxim, "I would have written less, but I didn't have enough time." Under our current regime, money beats elegance every time, all over the world. That could be one of the main reasons why Open Source software works better with a lot less coding -- it's more of an art and less of a paycheck.

That's a cool site, too -- thanks for the heads-up!

--p!
Today, a mighty dinosaur. Tomorrow, a bird that poops on your car.
Printer Friendly | Permalink |  | Top
 
Jim__ Donating Member (1000+ posts) Send PM | Profile | Ignore Sat Apr-26-08 09:30 AM
Response to Original message
2. I think there is a big difference between the code line and Skinner's pigeons.
Edited on Sat Apr-26-08 09:49 AM by Jim__
Response #1 says that this is C# and I don't know C#, so I may be misinterpeting that line, and the possible alternative code. I'm also guessing that "int" is a class rather than a primitive in C#, based on the i.ToString(). But, there is usually a difference between making a deep copy and setting 2 references to the same object.

I'm guessing that the alternative to this code is:

int j = i ; // j now references the same object as i

But then, suppose I just want to initialize j to the value of i and then alter the value of j, but not change the value of i. Using the above statement, when I change the value of j, I also change the value of i.

If I create a deep copy:

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

I can now do anything I want to j without effecting i.

Of course, the whole point of the statement (especially the whole "reference type" versus "value type" thing), may be that in C#, "int" is a value type rather than a reference type, in which case, both code statements do the same thing. In Java for instance, for a primitive type like "int", there is no int.Parse or i.ToString when i is an int. But, in that case the coder's problem is not superstition, and not necessarily a lack of understanding of OO concepts, but a lack of understanding of the specific language.


Printer Friendly | Permalink |  | Top
 
mcg Donating Member (1000+ posts) Send PM | Profile | Ignore Sat Apr-26-08 11:01 AM
Response to Reply #2
3. An int in C# is a value type, even though ToString() is allowed.
Having to become a pro C# programmer quickly, I'm interested in this.
A Java background is both helpful and confusing when approaching
C# programming. There are some big differences in terms of types.

Doing 'int j = i;' makes a copy of i's value because j is a value type,
even though doing 'j.toString();' is possible. Using the word 'deep'
isn't really applicable because there is no depth to an int, it doesn't
reference anything. The term 'deep copy' involves cloning objects that
reference other objects.

Excerpts from web pages:

http://www.csharpfriends.com/Spec/index.aspx?specID=11.1.3.htm

1 C# provides a set of predefined struct types called the simple types.
2 The simple types are identified through reserved words, but these
reserved words are simply aliases for predefined struct types in the
System namespace, as described in the table below.
...
int System.Int32
...
1 Because a simple type aliases a struct type, every simple type has members.
2 For example, int has the members declared in System.Int32 and the members
inherited from System.Object...
...
string t = 123.ToString(); // System.Int32.ToString() instance method

http://www.csharpfriends.com/Spec/index.aspx?specID=11.htm
1 Value types differ from reference types in that variables of the
value types directly contain their data, whereas variables of the
reference types store references to their data, the latter being known
as objects.
2 With reference types, it is possible for two variables to reference
the same object, and thus possible for operations on one variable to
affect the object referenced by the other variable.
3 With value types, the variables each have their own copy of the data,
and it is not possible for operations on one to affect the other.

http://www.csharpfriends.com/Spec/index.aspx?specID=11.1.htm#value-type

1 A value type is either a struct type or an enumeration type.
2 C# provides a set of predefined struct types called the simple types.
3 The simple types are identified through reserved words.
...
1 All value types implicitly inherit from class object.
...
1 A variable of a value type always contains a value of that type.
...
1 Assignment to a variable of a value type creates a copy of the value being assigned.
...

http://en.csharp-online.net/Glossary_of_.NET_/_CSharp_Terms

Refers to a method of cloning—copying—an object in which the clone contains the complete encapsulated data of the original instance. Thus, the clone can be used independently of the original object. In other words, a deep copy contains copies not only of instance variables but, also, of any objects pointed to by reference variables.

more...

http://www.jaggersoft.com/pubs/AProgrammersOverviewOfCSharp.htm

http://www.harding.edu/fmccown/java1_5_csharp_comparison.html

http://www.albahari.com/value%20vs%20reference%20types.html
Printer Friendly | Permalink |  | Top
 
htuttle Donating Member (1000+ posts) Send PM | Profile | Ignore Sat Apr-26-08 01:23 PM
Response to Reply #2
4. Kids nowadays just don't understand what pointers are!
Printer Friendly | Permalink |  | Top
 
Lithos Donating Member (1000+ posts) Send PM | Profile | Ignore Mon Apr-28-08 12:17 AM
Response to Reply #4
6. Have you pointed it out to them?
Addressed their memory to this lack of knowledge?
Printer Friendly | Permalink |  | Top
 
BlooInBloo Donating Member (1000+ posts) Send PM | Profile | Ignore Mon Apr-28-08 12:04 AM
Response to Reply #2
5. int is a struct is a lightweight class.
Printer Friendly | Permalink |  | Top
 
Lithos Donating Member (1000+ posts) Send PM | Profile | Ignore Mon Apr-28-08 12:27 AM
Response to Original message
7. There is an assumption here
that "i" is an int. This type of technique is a way to generically convert objects to type int. It is just really stupid to use this if "i" is an int.

So, if "i" were of type Double, then this would convert it to the integer floor.

As for it being a "Deep Copy", that is just plain ignorant.


L-
Printer Friendly | Permalink |  | Top
 
DU AdBot (1000+ posts) Click to send private message to this author Click to view 
this author's profile Click to add 
this author to your buddy list Click to add 
this author to your Ignore list Tue Apr 30th 2024, 01:13 AM
Response to Original message
Advertisements [?]
 Top

Home » Discuss » Topic Forums » Science Donate to DU

Powered by DCForum+ Version 1.1 Copyright 1997-2002 DCScripts.com
Software has been extensively modified by the DU administrators


Important Notices: By participating on this discussion board, visitors agree to abide by the rules outlined on our Rules page. Messages posted on the Democratic Underground Discussion Forums are the opinions of the individuals who post them, and do not necessarily represent the opinions of Democratic Underground, LLC.

Home  |  Discussion Forums  |  Journals |  Store  |  Donate

About DU  |  Contact Us  |  Privacy Policy

Got a message for Democratic Underground? Click here to send us a message.

© 2001 - 2011 Democratic Underground, LLC