Deep vs. shallow copy?

Steven D'Aprano steve+comp.lang.python at pearwood.info
Fri Mar 14 00:43:52 EDT 2014


On Thu, 13 Mar 2014 19:57:53 -0700, Rustom Mody wrote:

> I believe that you, Marko (and I) are saying exactly the same thing:

I believe that you and I are saying practically the same thing.


> Wear language-lawyer hat:
> Python has no procedures -- just functions which may return None

Almost. Functions (or methods) can return None as a regular value, e.g. 
the re.match and re.search functions return a MatchObject if there is a 
match, and None if there is not. Here, the fact the function returns None 
is nothing special -- it could have return 0, or -1, or "Surprise!" if 
the function author had wanted, the important thing is that you use it as 
a function. Normally you call the function for it's return result, even 
if that result happens to be None.

On the other hand, Python also has functions/methods which you call for 
their side-effects, not for their return result. In Pascal, Fortran and 
C, for example, the language provides a special type of subroutine that 
can only be called for it's side-effects. It is common to call these 
subroutines "procedures", and Python does not have them. We only have the 
convention that if a function is intended to be called for it's side-
effects (a procedure), it should return None.


> Wear vanilla programmer hat:
> The concept (Pascal) procedure is simulated by function-returning-None

Yes, agreed on this one.



-- 
Steven



More information about the Python-list mailing list