Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
Cocoa Crispies
Jul 20, 2001

Vehicular Manslaughter!

Pillbug

nielsm posted:

"C++ doesn't need garbage collection, because it doesn't produce garbage."

C++ doesn't have garbage collection, because it would collect itself!!!

Adbot
ADBOT LOVES YOU

Mustach
Mar 2, 2003

In this long line, there's been some real strange genes. You've got 'em all, with some extras thrown in.
Hahaha, I like that one.

Vanadium
Jan 8, 2005

This whole discussion would be moot if more people realised that when you say Object variable; in C# you're saying Object^ variable; in C++/CLI which is fundamentally different. :shobon:

baquerd
Jul 2, 2007

by FactsAreUseless

Brecht posted:

You appear to have a fundamental misunderstanding of type systems, and/or a crippling lack of specificity in your language. There is no "terminology system" in which "An object is a classifying description of a variable" is true as a general statement.

In Java there are objects and there are primitives. I've been with Java since 1997 and the terminology did not start out as ambiguous though recent revisions have practically made everything a bit muddled. I don't see what's so hard to understand why you can have object types and non-object types, from booleans to doubles to... (ok it's not a long list) but anything out there that does not support methods or member variables can be thought of as a non-object, then there are objects, then there are structs which are a sort of specialized object in Java...

edit (from Sun):

quote:

There are two kinds of types in the Java programming language: primitive types and reference types. There are, correspondingly, two kinds of data values that can be stored in variables, passed as arguments, returned by methods, and operated on: primitive values and reference values.

What they are calling reference values are of course, references to objects.

baquerd fucked around with this message at 19:35 on Sep 26, 2011

nielsm
Jun 1, 2009



Vanadium posted:

This whole discussion would be moot if more people realised that when you say Object variable; in C# you're saying Object^ variable; in C++/CLI which is fundamentally different. :shobon:

But apparently C# Struct var; is equivalent to something like:
char buffer[sizeof(Struct)];
Struct &var = *(Struct*)(void*)buffer;

1337JiveTurkey
Feb 17, 2005

Internet Janitor posted:

Cloneable is fundamentally a problem because Object.clone() Doesn't specify deep or shallow copy semantics.

edit: No, we are not having a "mutable state is a horror" rant.

Object.clone() has the additional feature that it does return a new instance of the object being cloned but no constructor is ever actually called. So if your constructor is modifying some non-local state like a static variable, then the clone method needs to as well. Remember, this still applies even if your class isn't Cloneable itself since if it's not final someone can make a Cloneable subclass.

If your constructor is calculating something to set a final field, then you're just out of luck. Copy constructors are probably the best solution in that case.

Cloning mutable objects as an alternative to creating new copies of immutable objects really feels like it's doing the same work in the end. So as a matter of practice I default to making things immutable and can't remember the last time I've cloned anything.

tef
May 30, 2004

-> some l-system crap ->

Eggnogium posted:

Here's a horror: Scrolling past your avatar in IE9 slows the browser down to a crawl.

have you considered installing ie6 instead?

corgski
Feb 6, 2007

Silly goose, you're here forever.

E: way late.

corgski fucked around with this message at 20:10 on Sep 26, 2011

1337JiveTurkey
Feb 17, 2005

nielsm posted:

But apparently C# Struct var; is equivalent to something like:
char buffer[sizeof(Struct)];
Struct &var = *(Struct*)(void*)buffer;


In C# a struct is a value type so it's local to the activation record or the object declaring it. That's the same as how it works in C except it's impossible to make a reference or pointer to a struct. So if you declare a struct in a method it's really just allocating the space on the stack right there.

edit: For what it's worth this is exactly what C++ is doing with objects and why it's always initializing the value to something. CLR/JVM/Objective C simply decided that this wasn't worth the attendant pain and made objects always heap allocated every time.

1337JiveTurkey fucked around with this message at 20:35 on Sep 26, 2011

Brecht
Nov 7, 2009

baquerd posted:

In Java there are objects and there are primitives. I've been with Java since 1997 and the terminology did not start out as ambiguous though recent revisions have practically made everything a bit muddled. I don't see what's so hard to understand why you can have object types and non-object types, from booleans to doubles to... (ok it's not a long list) but anything out there that does not support methods or member variables can be thought of as a non-object, then there are objects, then there are structs which are a sort of specialized object in Java...

edit (from Sun):


What they are calling reference values are of course, references to objects.
The problem here is that you're applying Java's semantic system and terminology to programming languages in general. What Java calls "non-Object types" are more properly (ie. more generally) known as "primitive types." That concept is completely orthogonal to Reference vs. Value semantics, but you seem to conflate the two because of the coincidence that Java has Reference-Object and Primitive-Value semantics only*.

* I mean not really but let's roll with it.

raminasi
Jan 25, 2005

a last drink with no ice

nielsm posted:

But apparently C# Struct var; is equivalent to something like:
char buffer[sizeof(Struct)];
Struct &var = *(Struct*)(void*)buffer;


Well, it's exactly like declaring a POD struct (as far as I can tell; I'm no C# guru). All of this only comes about when the type in question isn't a POD.

1337JiveTurkey posted:

That's the same as how it works in C except it's impossible to make a reference or pointer to a struct.

What? You can totally make a pointer to a struct. (In C, yeah, no references, but you can't make references to anything in C because they don't exist.)

Vanadium
Jan 8, 2005

nielsm posted:

But apparently C# Struct var; is equivalent to something like:
char buffer[sizeof(Struct)];
Struct &var = *(Struct*)(void*)buffer;


So you're telling me it's like a C++ class without a user-defined default constructor? We've got those too, you know!

Vanadium
Jan 8, 2005

So the real horror here is that C++ gives you the option of defining a default constructor for on-the-stack, value, non-reference types? Cripes!

Jethro
Jun 1, 2000

I was raised on the dairy, Bitch!

baquerd posted:

:words:
The problem was that you kept using the word variable wrong.
code:
int i = 0;
Object foo = new Object();
Object bar;
i, foo, and bar are variables. Variables are not objects. Variables have values. The value of i is 1. The value of foo is a reference to an object with type Object. foo is not the object that we created, it is a variable whose value is a reference to that object. bar has no value, since it is uninitialized, but it can hold a value which is a reference to an object of type Object. It is not an uninitialized object, since it is not an object. If the next line of code was this bar = foo;, then both foo and bar would be variables that contain references to the same (unnamed) object created above.

Jethro fucked around with this message at 21:13 on Sep 26, 2011

Vanadium
Jan 8, 2005

Of course, in C++, that is much easier, because when you say Object foo;, you actually get an object of type Object. Which is how C++ is clearly the superior paradigm here.

nielsm
Jun 1, 2009



Vanadium posted:

So the real horror here is that C++ gives you the option of defining a default constructor for on-the-stack, value, non-reference types? Cripes!

Yeah it's terrible isn't it. How can we ever deal with it!

Of course, then C++ lets you do this later on if you really want to:
new(&var) Struct(some, constructor, arguments);
But then you're also responsible for running any destructor yourself...
var.~Struct();

I think the point is just that C++ does useful stuff by default, but you can break the system and do insane poo poo if you really want to.

1337JiveTurkey
Feb 17, 2005

GrumpyDoctor posted:

What? You can totally make a pointer to a struct. (In C, yeah, no references, but you can't make references to anything in C because they don't exist.)

OK, you can make pointers to anything and everything using unsafe code. I was more going for the idea that there's no safe way to have two pieces of code point to the same struct, just a reference type which has the struct as a value. Making pointers to the interior of an object or to the stack are generally recipes for trouble and that's exactly what the data model is trying to preclude with the value/reference distinction.

Vanadium
Jan 8, 2005

Of course, at the point where you use the new operator, placement or other, you've stepped out of the cozy, safe world of RAII and are doing manual resource management anyway.

baquerd
Jul 2, 2007

by FactsAreUseless

Jethro posted:

code:
[fixed]i[/fixed], [fixed]foo[/fixed], and [fixed]bar[/fixed] 
are [i]variables[/i]. Variables are not [i]objects[/i]. 
Variables have [i]values[/i].  
The value of [fixed]i[/fixed] is [fixed]1[/fixed].
The value of [fixed]foo[/fixed] is a [i]reference[/i] 
to an object with [i]type[/i] [fixed]Object[/fixed].
[fixed]foo[/fixed] is not the object that we created, 
it is a variable whose value is a reference to that object.  
[fixed]bar[/fixed] has no value, since it is uninitialized,
 but it can hold a value which is a reference to an 
object of type [fixed]Object[/fixed].  
It is not an uninitialized object, since it is not an object.  
If the next line of code was this [fixed]bar = foo;[/fixed],
 then both [fixed]foo[/fixed] and [fixed]bar[/fixed] would 
be variables that contain references to the same (unnamed) object created above.

Woah, did you type that out? I hit enter a few times to not break tables but that really jumped out at me when I hit quote.

Variables have names, types, and values. An object (not Object in this usage) can be thought of as one potential "meta-type" of a variable, and a variable can therefore be an object in the colloquial tongue. I mean just think about it, don't just repeat what you've been told.

Toady
Jan 12, 2009

Jethro posted:

bar has no value, since it is uninitialized, but it can hold a value which is a reference to an object of type Object.

bar doesn't hold a reference a stack-allocated Object?

Brecht
Nov 7, 2009

baquerd posted:

Variables have names, types, and values.
Yes; not really (the type is a property of the thing the variable refers to, not the variable itself); and not really (same).

quote:

An object (not Object in this usage) can be thought of as one potential "meta-type" of a variable, and a variable can therefore be an object in the colloquial tongue.
A variable refers to an object (in the weak sense of refers). A variable is not the object. It's not an unimportant distinction.

nielsm
Jun 1, 2009



Toady posted:

bar doesn't hold a reference a stack-allocated Object?

That code is either C# or Java, not C++.

baquerd
Jul 2, 2007

by FactsAreUseless

Brecht posted:

Yes; not really (the type is a property of the thing the variable refers to, not the variable itself); and not really (same).

A variable refers to an object (in the weak sense of refers). A variable is not the object. It's not a trivial distinction.

These are just splitting hairs, you have the ability to make the intuitive leap without it being spelled out every single time. Unless you're looking at code reflection it really is a trivial distinction.

Eggnogium
Jun 1, 2010

Never give an inch! Hnnnghhhhhh!

Brecht posted:

A variable refers to an object (in the weak sense of refers). A variable is not the object. It's not an unimportant distinction.

In C# and Java, yes. And in C++ with pointers. But what about (C++):
code:
Bar bar;
That seems like a variable that is also an object.

tractor fanatic
Sep 9, 2005

Pillbug
It's just confusing that C# structs have default constructors that aren't called by default

Brecht
Nov 7, 2009

Eggnogium posted:

In C# and Java, yes. And in C++ with pointers. But what about (C++):
code:
Bar bar;
That seems like a variable that is also an object.
code:
Bar bar1("cake dogg");
Bar bar2("present cat");
bar1 = bar2; // same variable different object

baquerd
Jul 2, 2007

by FactsAreUseless

Brecht posted:

code:
bar1 = bar2; // same variable different object

No, by any sense of the world variable those are different. They only share a type

baquerd fucked around with this message at 21:38 on Sep 26, 2011

Eggnogium
Jun 1, 2010

Never give an inch! Hnnnghhhhhh!

Brecht posted:

code:
Bar bar1("cake dogg");
Bar bar2("present cat");
bar1 = bar2; // same variable different object

Oh. Wow, my college professors really failed at explaining C++.

Edit:

baquerd posted:

No, by any sense of the world variable those are different. They only share a type.

I understood it as meaning bar1 is still the same variable but now a different object than it had been before.

Brain Candy
May 18, 2006

1337JiveTurkey posted:

Object.clone() has the additional feature that it does return a new instance of the object being cloned but no constructor is ever actually called.

Object.clone() is basically just an alias for memcpy.http://ideone.com/LVj2Z

Brecht
Nov 7, 2009

baquerd posted:

No, by any sense of the world variable those are different. They only share a type.
Yes, exactly: bar1 is different than bar2. The point is that the variable bar1, as an entity, refers to two different objects, on line 1 vs. on line 3. The variable is therefore not the same as the object it refers to.

edit:

Eggnogium posted:

Oh. Wow, my college professors really failed at explaining C++.
Well, I'm being a bit vague to illustrate my point. If you get into the details, line 3 invokes cake dogg's operator= (with present cat as the const Bar& parameter) and the behavior of that is totally up to the implementation of the Bar class. Assuming Bar is a struct (ie. class) type, by default it will do a shallow copy of all of present cat's members "into" the same memory that was allocated (on the stack) in line 1 to cake dogg. So by default they're "different object"s in the sense that [any sane] operator== would return false, but no new allocations would take place. Of course you can override any and all of that with a custom operator=.

Brecht fucked around with this message at 21:44 on Sep 26, 2011

baquerd
Jul 2, 2007

by FactsAreUseless

Brecht posted:

Yes, exactly: bar1 is different than bar2. The point is that the variable bar1, as an entity, refers to two different objects, on line 1 vs. on line 3. The variable is therefore not the same as the object it refers to.

I see what you mean and your definition from that point of reference is valid. It is equally valid to say the variable is not the same because the value that is referenced by the variable has changed, it's inferred from the context which meaning is intended.

Edit: it seems to me we just argued each other's points in a roundabout manner. My original argument was that a variable can be an object, by which I mean the term "object" tells us information about the variable (namely that it may support member variables and methods).

baquerd fucked around with this message at 21:46 on Sep 26, 2011

Brecht
Nov 7, 2009

baquerd posted:

I see what you mean and your definition from that point of reference is valid. It is equally valid to say the variable is not the same because the value that is referenced by the variable has changed, it's inferred from the context which meaning is intended.
No, it is not equally valid, it is not valid at all to say that, this is not what the word or concept variable means and this exactly the point that many people are trying to make clear to you.

tractor fanatic
Sep 9, 2005

Pillbug

Brecht posted:


Wait are you saying objects are immutable in your definition because the whole point of operator= is that it does a mutation. The variable will refer to the same instance throughout its lifetime.

baquerd
Jul 2, 2007

by FactsAreUseless

Brecht posted:

No, it is not equally valid, it is not valid at all to say that, this is not what the word or concept variable means and this exactly the point that many people are trying to make clear to you.

It is, it is a colloquial shortcut. Do you always say "the value of the variable has been set to X"? It's an incredibly common shortcut to say "the variable has been set to X".

1337JiveTurkey
Feb 17, 2005

Brain Candy posted:

Object.clone() is basically just an alias for memcpy.http://ideone.com/LVj2Z

Lovely! I like in particular how the original instance can't get garbage collected until the clone does.

Eggnogium
Jun 1, 2010

Never give an inch! Hnnnghhhhhh!

Brecht posted:

Well, I'm being a bit vague to illustrate my point. If you get into the details, line 3 invokes cake dogg's operator= (with present cat as the const Bar& parameter) and the behavior of that is totally up to the implementation of the Bar class. Assuming Bar is a struct (ie. class) type, by default it will do a shallow copy of all of present cat's members "into" the same memory that was allocated (on the stack) in line 1 to cake dogg. So by default they're "different object"s in the sense that [any sane] operator== would return false, but no new allocations would take place. Of course you can override any and all of that with a custom operator=.

Actually I take it back then. If the default behavior is to do a shallow copy then I think bar1 is the same object throughout that code. Changing a field in a mutable object does not make it a new object, that's dumb.

baquerd
Jul 2, 2007

by FactsAreUseless

Eggnogium posted:

Actually I take it back then. If the default behavior is to do a shallow copy then I think bar1 is the same object throughout that code. Changing a field in a mutable object does not make it a new object, that's dumb.

So you are saying that the object reference must change in order to have a distinct object? What if we allow for the mutable object to contain a unique value as part of a programmatically enforced unique collection (set)? Each object is clearly distinct, does the memory location matter or is it not this unique identifier that "defines" the object?

Words can do the most interesting things...

Edit:

Brecht posted:

Yes, exactly: bar1 is different than bar2. The point is that the variable bar1, as an entity, refers to two different objects, on line 1 vs. on line 3. The variable is therefore not the same as the object it refers to.

I just realized you're not bounding time. Suppose we can snapshot a program as in a debugger. Do the lines between variable and object referenced by the variable start to blur (again excluding reflection techniques)?

baquerd fucked around with this message at 22:07 on Sep 26, 2011

Eggnogium
Jun 1, 2010

Never give an inch! Hnnnghhhhhh!

baquerd posted:

So you are saying that the object reference must change in order to have a distinct object? What if we allow for the mutable object to contain a unique value as part of a programmatically enforced unique collection (set)? Each object is clearly distinct, does the memory location matter or is it not this unique identifier that "defines" the object?

Words can do the most interesting things...

Sure, that definition could be valid but mine more accurately represents the real-world analogy for objects. If I scratch out the VIN on my car and carve a new one that doesn't magically make it a "new" car.

Toady
Jan 12, 2009

Brecht posted:

No, it is not equally valid, it is not valid at all to say that, this is not what the word or concept variable means and this exactly the point that many people are trying to make clear to you.

I think you're being a little too pedantic here.

Adbot
ADBOT LOVES YOU

baquerd
Jul 2, 2007

by FactsAreUseless

Eggnogium posted:

Sure, that definition could be valid but mine more accurately represents the real-world analogy for objects. If I scratch out the VIN on my car and carve a new one that doesn't magically make it a "new" car.

I certainly tend to agree and a point well made. But what if you took your car apart in the driveway and built it from the frame up, but it's still in the same place (read: memory location)? It is only a difference of degree don't you think but now the real world example is much more arguable.

:iiaca:

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply