Pointers vs References
Community Forums/Monkey2 Talk/Pointers vs References
| ||
One of the hardest concepts for me to grasp going from BMX to C++ was pointers vs object references. BlitzMax objects act like pointers. It wasn't until I compared references to a regular old variable that I finally "got" it. To review, here are the characteristics of each: Pointer: Defined creation and destruction. Setting to equal equals the same object. References: Declared and go out of scope, but never created or destroyed. Setting equal copies the object. Unlike C++, I would suggest making these two distinct types of containers. I would call pointers "Class" and references a "Struc", keeping all the details hidden from the end user. Struc Vec3 Field x#, y#, z# EndStruc Local a:Vec3, b:Vec3 a.x = 1 b = a b.y=2 Print(a) ' 1,0,0 Print(b) ' 1,0,2 Class Vec3 Field x#, y#, z# EndClass Local a:Vec3 = new Vec3, b:Vec3 = new Vec3 a.x = 1 b = a b.y=2 Print(a) ' 1,0,2 Print(b) ' 1,0,2 |
| ||
That's what immutable types are for. I remember mark mentioning they're going to be added. |
| ||
What you've described as "pointer" is essentially an "object reference" in every garbage collected language, and what you've defined as a "reference" is essentially a value type (struct, etc.) |
| ||
There has been a thread about dynamic adressing in MX2. It could help you understand how far MX2 will go with it. (my conclusion is you won't be able to generate a segmentation fault with MX2 but i'm sure I didn't understand everything in the thread!;) http://www.monkey-x.com/Community/posts.php?topic=9770&page=1 |
| ||
This is very exciting. With other languages, you basically have to choose between Linux and iOS (as an analogy). Mark is making something that has the power of C++ and the ease of use of basic. |
| ||
By the way, strings in BlitzMax behave like your "struct" |