Old Man Yells At Cloud

bartc bc at freeuk.com
Tue Sep 19 14:31:47 EDT 2017


On 19/09/2017 17:30, Steve D'Aprano wrote:
> On Tue, 19 Sep 2017 05:56 am, Roel Schroeven wrote:
> 
>> I do prefer Python 3's print-as-a-function because "special cases aren't
>> special enough to break the rules", but I feel there's a case to be made
>>    for Python 2's print-as-a-statement because "(although) practicality
>> beats purity" sometimes.
> 
> Nobody has successfully made the argument that print was *better* as a
> statement, or given any convincing reason why print *should* be a statement.
> 
> (For example, del needs to be a statement, not a function, because it needs to
> operate on *names* not the objects bound to the names.)
> 
> All they have managed to successfully argue is that they're used to print
> without parens and can't unlearn the habit.
> 
> The one advantage of print statement is that you save a single character when
> typing it. Be still my beating heart.
> 
> Compared to that, the disadvantages:
> 
> - it makes print a special thing that can't be treated as a first-class
>    value, it can't be passed to functions or used as a callback or bound
>    to a name;
> 
> - because it is special, beginners have to unlearn the practice of using
>    parens for calling functions, and stop writing print(x);
> 
> - it suffers a silent failure if you inadvertently parenthesise multiple
>    arguments: `print(x, y)` is *not* the same as `print x, y`;
> 
> - it has bizarre syntax that nobody would find normal if it wasn't for
>    long-experience; I mean, really, you end the argument list with a
>    comma to suppress printing newlines? who thought that was a good idea?
> 
> - it is difficult to control the print statement, since you can't
>    pass keyword arguments; it's one size fits all;
> 
> - which is why we ended up with that awful `print >>file, args` hack;
> 
> - it can't be mocked, shadowed, monkey-patched or replaced for testing;
> 
> - and you can't even write help(print) in the interactive interpreter
>    because its a syntax error.

Can't you get around all those with things like sys.stdout.write?

If so, what was the point of having a discrete print statement/function 
at all?

-- 
bartc



More information about the Python-list mailing list