0

My previous question probably wasn't phrased the clearest. I didn't want to know what happened, I wanted to know why the language itself uses this philosophy. Was it an arbitrary choice, or is there some interesting history between this design choice?

The answers that the question was marked as a duplicate to simply stated that Python does this but didn't explain whether there was any reasoning behind it.

ettolrach
  • 23
  • 5
  • [probably relevant](https://youtu.be/_AEJHKGk9ns?t=1248). – timgeb Jun 26 '20 at 13:49
  • 1
    The "Python has names, not variables" thing seems to be a misunderstanding. Python has variables, and variables have names. – kaya3 Jun 26 '20 at 13:49
  • I imagine it was not arbitrary - a choice was made there would have been a reason. You will probably have better luck finding the history by delving through **old** python usenet threads or mailing list threads. – wwii Jun 26 '20 at 14:16

1 Answers1

1

If you know C and C++, you know what pointers and references are. In Java or Python, you have two kinds of things. On one side the native numeric types (integers, characters and floating points) and on the other the complex ones which derive from a basic empty type object.

In fact, the native types are the ones that can fit into a CPU register, and for that reason they are processed as values. But object (sub-)types often require a complex memory frame. For that reason, a register can only contain a pointer to them, and for that reason they are processed as references. The nice point with references for languages that provide a garbage collector, is that they are processed the same as a C++ shared_pointer: the system maintains a reference count, and when the reference count reaches 0, the object can be freed by the GC.

C has a very limited notion of object (struct) and in early K&R versions from the 1970s, you could only process them element by element or as a whole with memcopy but could neither return from a function nor assign them nor pass them by value. The ability to pass struct by values was added into ANSI C during the 1980s, to make the language more object friendly. C++ being from the beginning an object language, allowed to pass objects by value, and the smart pointers shared_ptr and unique_ptr were added to the standard library to allow to easily use references to objects because copying a large object is an expensive operation.

Python (like java) being a post-C++ language decided from the beginning that objects would be processed as references with a reference counter and deleted by a garbage collector when the ref count reaches 0. That way assigning objects is a cheap operation, and the programmer has never to explicitely delete anything.

Carcigenicate
  • 43,494
  • 9
  • 68
  • 117
Serge Ballesta
  • 143,923
  • 11
  • 122
  • 252