Why not allow empty code blocks?

Chris Angelico rosuav at gmail.com
Sat Jul 30 22:17:04 EDT 2016


On Sun, Jul 31, 2016 at 11:45 AM, Gregory Ewing
<greg.ewing at canterbury.ac.nz> wrote:
> Chris Angelico wrote:
>>
>> So do I need to be able to "call a function as if it
>> were a procedure", or is there a stark difference between the two
>> types of callable?
>
>
> Well, Pascal makes a stark distinction between them -- it's
> a compile-time error to call a procedure as though it were
> a function or vice versa in Pascal -- and it didn't seem to
> cause any great problems.
>
> So it's at least possible to write useful code under such
> circumstances, and it might even help to catch certain
> classes of errors. But the ability to ignore return values
> can be useful as well. Most languages since have decided
> not to make the distinction, and don't seem to have
> suffered noticeably as a result.

Yeah. The distinction means you have a fundamental API difference
between the procedures (which don't return anything) and the functions
(whose return values you mightn't care about). It means you can't
upgrade something from "always returns None" to "returns the number of
objects frobbed" without breaking compat. Conversely, if you decide
that any function can be called "as a procedure" (this is what REXX
does, for instance), then you've just merged the two types of callable
and distinguished them only in usage.

Personally, I don't see any value to the distinction at all.

ChrisA



More information about the Python-list mailing list