Python is going to be hard
rosuav at gmail.com
Thu Sep 4 16:08:22 CEST 2014
On Thu, Sep 4, 2014 at 11:37 PM, Steven D'Aprano
<steve+comp.lang.python at pearwood.info> wrote:
> Chris Angelico wrote:
>> On Thu, Sep 4, 2014 at 4:23 PM, Rustom Mody <rustompmody at gmail.com> wrote:
>>> You seem to think a print hanging out of a program to be ok, normal.
>>> I consider it exceptional.
>> You keep saying that it's exceptional. You haven't really said why.
>> It's the simplest form of "program produces output for the human to
>> see", which all of your subsequent examples are more complicated
>> versions of:
> Out of the Python built-ins, how many functions (apart from print itself!)
> print output instead of, or as well as, returning?
> Out of the standard library, what percentage of functions and methods print
> output instead of, or as well as, returning?
> I haven't counted, but I'm guessing it will be well under 1%. There's a few
> obvious examples: pprint.pprint, calendar.pr*, dis.dis, maybe a few more.
> But I think they should be considered *exceptional*.
This is an unfair comparison, though. There's a vast difference
between library and application code. You also don't find library code
that changes the current directory, but on the flip side, *every* job
control system needs that facility. (With sysvinit, job control is
shell scripts. With upstart and systemd, there are directives to set
the working directory. Etcetera.) It's bad form for a library to
produce console output, because it doesn't own the console; but the
application does. The logger module will, by default, produce stderr
output, because it's assuming the application owns it. Otherwise, it's
generally up to the application to print stuff out.
So a fairer comparison is: How many applications produce non-debug
output on stderr or stdout? And that would be a much larger
percentage. Even GUI programs will, in some cases - for instance, try
firing up your favorite GUI text editor with no X server active, or
with invalid .Xauthority. You'll get some sort of error message - on
the console. Which means that somewhere in the GUI library, there's
fall-back code that produces console output. That's why I say it's the
most basic of all forms of that fundamental of programming, producing
output that a human can read. It's the simple one that you teach
first; everything else is built on that.
More information about the Python-list