|
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!!!
|
# ? Sep 26, 2011 19:02 |
|
|
# ? May 16, 2024 22:12 |
|
Hahaha, I like that one.
|
# ? Sep 26, 2011 19:08 |
|
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.
|
# ? Sep 26, 2011 19:22 |
|
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 |
# ? Sep 26, 2011 19:27 |
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. But apparently C# Struct var; is equivalent to something like: char buffer[sizeof(Struct)]; Struct &var = *(Struct*)(void*)buffer;
|
|
# ? Sep 26, 2011 19:35 |
|
Internet Janitor posted:Cloneable is fundamentally a problem because Object.clone() Doesn't specify deep or shallow copy semantics. 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.
|
# ? Sep 26, 2011 19:43 |
|
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?
|
# ? Sep 26, 2011 19:58 |
|
E: way late.
corgski fucked around with this message at 20:10 on Sep 26, 2011 |
# ? Sep 26, 2011 20:03 |
|
nielsm posted:But apparently C# Struct var; is equivalent to something like: 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 |
# ? Sep 26, 2011 20:31 |
|
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... * I mean not really but let's roll with it.
|
# ? Sep 26, 2011 20:32 |
|
nielsm posted:But apparently C# Struct var; is equivalent to something like: 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.)
|
# ? Sep 26, 2011 20:45 |
|
nielsm posted:But apparently C# Struct var; is equivalent to something like: So you're telling me it's like a C++ class without a user-defined default constructor? We've got those too, you know!
|
# ? Sep 26, 2011 21:05 |
|
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!
|
# ? Sep 26, 2011 21:06 |
|
baquerd posted:code:
Jethro fucked around with this message at 21:13 on Sep 26, 2011 |
# ? Sep 26, 2011 21:09 |
|
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.
|
# ? Sep 26, 2011 21:15 |
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.
|
|
# ? Sep 26, 2011 21:17 |
|
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.
|
# ? Sep 26, 2011 21:18 |
|
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.
|
# ? Sep 26, 2011 21:19 |
|
Jethro posted:
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.
|
# ? Sep 26, 2011 21:19 |
|
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?
|
# ? Sep 26, 2011 21:20 |
|
baquerd posted:Variables have names, types, and values. 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.
|
# ? Sep 26, 2011 21:25 |
Toady posted:bar doesn't hold a reference a stack-allocated Object? That code is either C# or Java, not C++.
|
|
# ? Sep 26, 2011 21:26 |
|
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). 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.
|
# ? Sep 26, 2011 21:28 |
|
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:
|
# ? Sep 26, 2011 21:30 |
|
It's just confusing that C# structs have default constructors that aren't called by default
|
# ? Sep 26, 2011 21:32 |
|
Eggnogium posted:In C# and Java, yes. And in C++ with pointers. But what about (C++): code:
|
# ? Sep 26, 2011 21:33 |
|
Brecht posted:
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 |
# ? Sep 26, 2011 21:34 |
|
Brecht posted:
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.
|
# ? Sep 26, 2011 21:35 |
|
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
|
# ? Sep 26, 2011 21:36 |
|
baquerd posted:No, by any sense of the world variable those are different. They only share a type. edit: Eggnogium posted:Oh. Wow, my college professors really failed at explaining C++. Brecht fucked around with this message at 21:44 on Sep 26, 2011 |
# ? Sep 26, 2011 21:37 |
|
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 |
# ? Sep 26, 2011 21:39 |
|
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.
|
# ? Sep 26, 2011 21:46 |
|
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.
|
# ? Sep 26, 2011 21:47 |
|
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".
|
# ? Sep 26, 2011 21:48 |
|
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.
|
# ? Sep 26, 2011 21:50 |
|
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.
|
# ? Sep 26, 2011 21:57 |
|
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 |
# ? Sep 26, 2011 22:01 |
|
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? 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.
|
# ? Sep 26, 2011 22:06 |
|
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.
|
# ? Sep 26, 2011 22:08 |
|
|
# ? May 16, 2024 22:12 |
|
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.
|
# ? Sep 26, 2011 22:11 |