Default Value

Chris Angelico rosuav at gmail.com
Thu Jun 20 11:38:34 EDT 2013


On Fri, Jun 21, 2013 at 12:49 AM, Rick Johnson
<rantingrickjohnson at gmail.com> wrote:
> When the subroutine is completed, all inputs and local
> variables are expected to be destroyed. If the programmer
> wants a return value, he need simply ask. Data persistence
> is not a function of subroutines!

Funny, C violates your description too.

int counter()
{
    static int count;
    return ++count;
}

Function defaults in Python, being implemented as attributes on the
function object, are very similar in nature to static variables in C.
They're constructed once at function creation time, they're available
to that function (okay, C doesn't have any concept of "reaching into"
a function from the outside, Python does), they out-last any
particular execution of that function.

> Finally, a subroutine
> should never have side effects UNLESS the programmer
> explicitly ask for a side effect.

Bogus.

http://www.postgresql.org/docs/current/static/sql-createfunction.html

By default, a function is assumed to have side effects. The
programmer/sysadmin has to explicitly ask for PostgreSQL to treat the
function as NOT having side effects (the IMMUTABLE attribute, or
possibly its weaker cousin STABLE).

ChrisA



More information about the Python-list mailing list