Re: [Python-ideas] A suggestion for Python 3 vs Python 2

>You probably ought to weigh the ease of typing against readability. Which is more important? By how much? As people are used to python2, I don't think changing print to print() will improve code readability by how much, especially now VIM already highlights the print command in python. Probably you don't use print in python quite often, so you may not sense the difference in typing brackets. If you ever used C/C++/perl frequently, you should sense the inconvenience caused by brackets in loop structures. >Separately, have you measured typing speed rigorously? The typing effort varies from person to person, from beginners to experts, maybe you are too expert to sense the difference which is sensitive to beginners. There's no rule-of-thumb and it's not just a speed issue. It's also related to energy spent by your fingers. So obviously, pressing 2 keys, you need to spend at least twice the amount of energy. And even more if you need to hold down 1 key. Anyway, I am just introducing an alternative form to the print() function. As long as this does not reduce the performance of the interpreter significantly, it should not harm. And it should also improve the downward compatibility. On Tue, Nov 12, 2013 at 1:27 PM, Guido van Rossum <guido@python.org> wrote: > You probably ought to weigh the ease of typing against readability. Which > is more important? By how much? If 10% more effort typing makes for 5% > better readability, but the code is read 5 times as often as it is edited, > is that then worth it? > > Separately, have you measured typing speed rigorously? > > On Monday, November 11, 2013, Xuancong Wang wrote: > >> >An interesting methodology; however, I think PERL already has >> >conquered this corner of the language world. >> >> I think Perl has much lower efficiency than python, especially you need >> to type a $ before every variable. The input effort of $ is very high >> because you need to press shift. >> >> Also, you need to type {} for every function/for/while structure. >> >> In terms of language efficiency, I think Perl is no comparison to Python. >> >> We can roughly estimate the input effort of every key in the following >> way: >> Normal alphabet keys: effort=1 >> Numbers 0~9: effort=1.2 >> Shift/Tab: effort=0.6 >> Ctrl/Alt: effort=0.8 >> {}[];'\,./-=: effort=1.2 >> (effort measures how difficult it is to press the key) >> Therefore, any composed keys like shift+9='(', the input effort is >> 0.6+1.2=1.8 >> that's why we should try to avoid composed keys if it's not necessary. >> >> >>"Advantages of print being a function: >> * You can override it. Can't do that with a special language element. >> * It can be used in map, lambda, and other expression contexts. >> * Precedence etc follows the normal rules of functions - the arguments >> are all tidily enclosed. >> * Keyword arguments, rather than magical syntax, handle the oddities >> like end=" ". >> * You can easily alias it: "p = print; p('Hello, world!')" >> >> I do agree that print should remain as a function logically. But is there >> a way to make it as simple as in python 2, or even simpler, for example: >> pr >>sys.stderr, 'hello world' >> >> xuancong >> >> >> On Tue, Nov 12, 2013 at 11:56 AM, Mark Janssen <dreamingforward@gmail.com >> > wrote: >> >>> On Mon, Nov 11, 2013 at 7:45 PM, Xuancong Wang <xuancong84@gmail.com> >>> wrote: >>> > As you know, reading from and writing to IO is a high frequency >>> operation. >>> > By entropy coding theorem (e.g. Huffman coding), an efficient language >>> > should assign shorter language code to more frequent tasks. Typing a >>> '(' >>> > requires holding SHIFT and pressing 9, the input effort is much higher >>> than >>> > that in Python 2. Also, specifying IO has changed from >>* to file=*, >>> which >>> > also becomes more inconvenient. >>> >>> An interesting methodology; however, I think PERL already has >>> conquered this corner of the language world. >>> -- >>> MarkJ >>> Tacoma, Washington >>> >> >> > > -- > --Guido van Rossum (on iPad) >

On 11/11/2013 09:52 PM, Xuancong Wang wrote:
You probably ought to weigh the ease of typing against readability. Which is more important? By how much?
Readability, a thousand times.
If you don't like `print()`, do a `p = print` and then all you have is `p()` -- of course, you just lost a bunch a readability. But seriously, have often does any real program use print?
`print` is now a function, it's now going back to a keyword, and the interpreter loop isn't changing to support such a tiny use-case. -- ~Ethan~

On 12 November 2013 20:47, Ethan Furman <ethan@stoneleaf.us> wrote:
It's far more common in utility scripts (such as those written by system administrators) than it is in applications. The print change between Python 2 and 3 is one that doesn't really affect application developers all that much in practice (other than when trying things out in the REPL, and apparently not even then if using IPython), but can be more of an issue with those writing scripts where the standard streams are the primary IO mechanism. We tend not to hear from the latter group as much as we do from application developers, though. Cheers, Nick. -- Nick Coghlan | ncoghlan@gmail.com | Brisbane, Australia

On Tue, Nov 12, 2013 at 10:10:31PM +1000, Nick Coghlan wrote:
I've written a few short utility scripts in my time, and I rarely call print directly except for the most basic scripts. Normally I'll have facility to control output, perhaps a verbosity level, or at least a verbose flag, say: def pr(message): if gVerbose: print message So I think even in scripting, calling print directly is less common than it might otherwise seem. -- Steven

On Nov 12, 2013, at 10:10 PM, Nick Coghlan wrote:
Oh yeah, another beautiful thing about the print function: >>> from functools import partial >>> import sys >>> perr = partial(print, file=sys.stderr) >>> perr('you hit a bug') Cheers, -Barry

On Tue, Nov 12, 2013 at 7:10 AM, Nick Coghlan <ncoghlan@gmail.com> wrote:
Having written a lot of applications and both small and large scripts I've almost universally regretted using print instead of a logger. It's (slightly) more setup, but the second you want to make any changes to your output (timestamps, suppressing certain messages) it more than makes up for it.

On 11/11/2013 09:52 PM, Xuancong Wang wrote:
You probably ought to weigh the ease of typing against readability. Which is more important? By how much?
Readability, a thousand times.
If you don't like `print()`, do a `p = print` and then all you have is `p()` -- of course, you just lost a bunch a readability. But seriously, have often does any real program use print?
`print` is now a function, it's now going back to a keyword, and the interpreter loop isn't changing to support such a tiny use-case. -- ~Ethan~

On 12 November 2013 20:47, Ethan Furman <ethan@stoneleaf.us> wrote:
It's far more common in utility scripts (such as those written by system administrators) than it is in applications. The print change between Python 2 and 3 is one that doesn't really affect application developers all that much in practice (other than when trying things out in the REPL, and apparently not even then if using IPython), but can be more of an issue with those writing scripts where the standard streams are the primary IO mechanism. We tend not to hear from the latter group as much as we do from application developers, though. Cheers, Nick. -- Nick Coghlan | ncoghlan@gmail.com | Brisbane, Australia

On Tue, Nov 12, 2013 at 10:10:31PM +1000, Nick Coghlan wrote:
I've written a few short utility scripts in my time, and I rarely call print directly except for the most basic scripts. Normally I'll have facility to control output, perhaps a verbosity level, or at least a verbose flag, say: def pr(message): if gVerbose: print message So I think even in scripting, calling print directly is less common than it might otherwise seem. -- Steven

On Nov 12, 2013, at 10:10 PM, Nick Coghlan wrote:
Oh yeah, another beautiful thing about the print function: >>> from functools import partial >>> import sys >>> perr = partial(print, file=sys.stderr) >>> perr('you hit a bug') Cheers, -Barry

On Tue, Nov 12, 2013 at 7:10 AM, Nick Coghlan <ncoghlan@gmail.com> wrote:
Having written a lot of applications and both small and large scripts I've almost universally regretted using print instead of a logger. It's (slightly) more setup, but the second you want to make any changes to your output (timestamps, suppressing certain messages) it more than makes up for it.
participants (7)
-
Barry Warsaw
-
Ethan Furman
-
Jeff Jenkins
-
Nick Coghlan
-
Steven D'Aprano
-
Xuancong Wang
-
אלעזר