anything like C++ references?

Stephen Horne intentionally at blank.co.uk
Mon Jul 14 19:22:15 EDT 2003


On 14 Jul 2003 11:35:57 -0700, owski at hotmail.com (Adam Ruth) wrote:

>Stephen Horne <intentionally at blank.co.uk> wrote in message news:<7dc4hvslh7a8fk9p6cvsfqa1c8d44rmmnv at 4ax.com>...
>> On 13 Jul 2003 21:03:59 -0700, owski at hotmail.com (Adam Ruth) wrote:
>> 
>
>> C++ has precisely one type of variable. That variable is a placeholder
>> for a value of a datatype which is specified in the declaration. The
>> datatype may be a pointer datatype, but so what? Pointer datatypes are
>> not treated any differently than other datatype except that they, like
>> all datatypes, they have their own set of functionality.
>
>Granted.  Pointers are no different than other data types, but they
>are typically used for operations that are semantically very different
>than other datatypes are used for.  In that sense, they are, at a high
>level, different data types.

A different data type is nothing special. Mathematics has the concept
of abstract data types. That's the point. There's no need to invent
different kinds of variable, only different types of data. The fact
that C and C++ variables are restricted in the set of values they can
bind to (ie those with a particular data type) is not a problem.

>It's like how c programming is taught has having pass by reference and
>pass by value, when there is only pass by value at the implementation
>level.  Pass by reference is a concept added on top of the language.

No. C programmers always pass by value. Sometimes that value is a
pointer.

Pascal programmers sometimes pass by reference. They do so explicitly,
however - using the keyword 'var'. There is a big difference between
*choosing* to have variables bound to an object, and having it happen
automatically whether you want it or not.

>> C++ references are tellingly also called self-dereferencing pointers.
>> They are not a distinct concept - they are syntactic sugar. I suspect
>> they mainly arise out of the modern desire to disguise pointers and
>> fantasize that they're not there, though they certainly work very well
>> in certain contexts.
>
>Syntactic sugar or no, they still behave differently than other
>datatypes and are therefore not consistent... IMHO.

They behave exactly like pointers. You just use different notation to
get that behaviour. That is what makes them syntactic sugar.

>> Funny thing. When I use algebra, the variables I define don't end up
>> referring to different values, functions or whatever unless I
>> explicitly redefine them. When I write a definition on one piece of
>> paper, the things I wrote earlier on another sheet don't change.
>> 
>> Seems to me that the math equivalent of assignment (defining named
>> things) works very much like the 'static language definitions' as you
>> put it.
>
>The devil is in the details.  Math assignment is static assignment is
>dynamic assignment.  They really are all the same thing at a high
>level, but it's the implementation and the subtleties that make them
>vary.

Not true. Maths has the concept of an algorithm, and it has the
concept of assignment.

In maths, a variable binds to a value. In Python, a variable binds to
an object in a way that does no correctly implement binding to a value
unless the object happens to be immutable.





More information about the Python-list mailing list