Assignment versus binding

Chris Angelico rosuav at gmail.com
Wed Oct 5 02:51:20 EDT 2016


On Wed, Oct 5, 2016 at 5:19 PM, Rustom Mody <rustompmody at gmail.com> wrote:
> Its ironical:
> - Function in Fortran was meant to emulate math-functions
> - C took the same thing and did a ‘small little syntax elision’ viz
> conflating function and subprogram (procedure in Pascal speak) all under
> the heading of function. In Pascal it was certainly a publicised intent
> to sharply distinguish functions — no side-effects — from procedures — no return value.
> - Finally this abuse of notation (and notions) has become such a norm (normal!)
> that people are surprised to find non-abusive languages!

So how do you handle something that, by its nature, has BOTH side
effects and a return value? For instance, writing to a socket has
three results:

1) Data is sent to the socket (side effect), possibly with consequent
changes to visible state
2) Status return saying how much was written
3) Possible error return in the event of failure.

#3 aligns fairly nicely with exceptions, although that doesn't easily
handle the possibility that some data was written prior to the error
occurring. #2 has to be some sort of return value, unless you simply
declare that writing anything less than the full data is an error, and
fold it into exception handling. And thanks to #1, it can't be a pure
function, because you aren't allowed to optimize it away (writing
"spam" to the socket twice is not the same as writing it once and
returning 4 to both callers).

The real world is not pure.

ChrisA



More information about the Python-list mailing list