3 ms·
Python has Perl beat on the REPL loop out-of-the-box: http://docs.python.org/library/code.html# http://docs.python.org/library/code.html# Python 2.7.1 (r271:
by jerf 16y ago
Python has Perl beat on the REPL loop out-of-the-box: http://docs.python.org/library/code.html# http://docs.python.org/library/code.html#
Python 2.7.1 (r271:86832, Mar 14 2011, 00:19:31) ...
Type "help", "copyright", "credits" or "license" for more information.
>>> import code
>>> code.interact()
Python 2.7.1 (r271:86832, Mar 14 2011, 00:19:31)
[GCC 4.4.4] on linux2
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>> import this
The Zen of Python, by Tim Peters
Beautiful is better than ugly.
Explicit is better than implicit.
...
And there are a variety of ways to extend it with various input and output. Much easier and more flexible than anything Perl will offer without a CPAN module. Which is probably out there.
That said, while I agree with this guy's conclusion his arguments are mixed in quality, trending towards poor. I like Python better, but my professional coding is primarily Perl and has been for nearly a decade now. Many Perl code snippets I looked at had a fatal flaw in it that made Perl look worse than it actually is, or the putative improvement that Python has is a judgment call rather than a good reason. And the reasons I actually like Python better are mostly not to be seen, except for the "classes" one.
(Reasons: The "double underscore" methods may have notoriously bad names, but they work better and more reliably over the last decade than Perl overloading has for me, you can't do more than badly fake Python iterators in Perl 5 last I knew, trivial and across-the-board ability to use arbitrary objects as dict keys, more sensible Unicode handling in Python 3. __str__ and __repr__; Dumper/say is no replacement. And for all the putative benefits of Perl's various syntaxes and sigils and for all that I've programmed in Perl about an order of magnitude more than I've programmed in Perl it's Python features I miss in Perl and never vice-versa. Locally everything in Perl makes sense, yet somehow the global combination of all these locally-slightly-better things does not produce a better language, just a larger one. But Perl's still on the short list of languages I can stand to use.)
- jrockway 16y agoIf you're not willing to use CPAN, there is no point in using Perl. (Incidentally, have you ever read code.py? Very inflexible and largely useless except for the exact purpose it's implemented for, a terminal-based REPL with no history or tab completion. I needed to write something like this: https://github.com/jrockway/stylish-perl https://github.com/jrockway/stylish-perl for Python, and simply couldn't do it without a clever AST rewrite, which added the equivalent of __result__ = <whatever they typed in that can be an rvalue>. Then it was all easy, although it still doesn't quite work right (but I feel if I knew what I was doing and cared, it could be fixed). As to why stylish-python is not on Github; I wrote it for "work Python" instead of real Python. Yes, we have a fork of Python 2.6 that uses an internally-developed Redis clone to store the source code instead of files. This was not my idea and I did not write any of the code :) (Writing your own database and your own IDE is a lot more fun than writing ETL code, I guess.) Also, with respect to repr vs. Data::Dump::Streamer, I'll just paste the following REPL sessions: [~] 0 (jon@snowball2) $ python Python 2.6.6 (r266:84292, Dec 26 2010, 22:31:48) [GCC 4.4.5] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> repr(lambda (x): return x) '<function <lambda> at 0x7f6103dda668>' >>> [~] 0 (jon@snowball2) $ re.pl $ sub { my $x = shift; return $x } $CODE1 = sub { package Devel::REPL::Plugin::Packages::DefaultScratchpad; use warnings; use strict 'refs'; my $x = shift @_; return $x; }; Note how DDS can represent all of Perl's data structures, not just some of them. You now know that you have the identity function instead of a function at memory address 0x7f6103dda668. I guess Python programmers don't care because everything has a name. Also, with re.pl, you can do this later on in your session: $ $CODE1->(42) 42 That lambda you typed in in the python shell is gone forever, which IMHO defeats the purpose of having a REPL.