I know Perl 5. What are the advantages of learning

2019-03-17 12:21发布

Coming from a Perl 5 background, what are the advantages of moving to Perl 6 or Python?

Edit: If you downvoted this because you think it's just flamebait, read the answers below. They're not raving arguments; they're well-written discussions of the pros and cons of each language. Give the Stack Overflow community some credit.

9条回答
2楼-- · 2019-03-17 13:03

There is no advantage to be gained by switching from Perl to Python. There is also no advantage to be gained by switching from Python to Perl. They are both equally capable. Choose your tools based on what you know and the problem you are trying to solve rather than on some sort of notion that one is somehow inherently better than the other.

The only real advantage is if you are switching from a language you don't know to a language you do know, in which case your productivity will likely go up.

查看更多
Melony?
3楼-- · 2019-03-17 13:09

In my opinion, Python's syntax is much cleaner, simpler, and consistent. You can define nested data structures the same everywhere, whether you plan to pass them to a function (or return them from one) or use them directly. I like Perl a lot, but as soon as I learned enough Python to "get" it, I never turned back.

In my experience, random snippets of Python tend to be more readable than random snippets of Perl. The difference really comes down to the culture around each language, where Perl users often appreciate cleverness while Python users more often prefer clarity. That's not to say you can't have clear Perl or devious Python, but those are much less common.

Both are fine languages and solve many of the same problems. I personally lean toward Python, if for no other reason in that it seems to be gaining momentum while Perl seems to be losing users to Python and Ruby.

Note the abundance of weasel words in the above. Honestly, it's really going to come down to personal preference.

查看更多
Luminary・发光体
4楼-- · 2019-03-17 13:11

Python has a major advantage of being available in a production-ready format today.

Python has Jython and IronPython, if you need to work closely with Java or the .net clr.

Perl 6 has the advantages of being based on the same principles as Perl (1-5); If you like Perl, you'll like Perl 6 for the same reasons. (There's more than one way to do it, etc.)

Perl 6 also has an advantage of being only partially implemented: If you want to hack on language internals or help to define the standard libraries, this is a great time to get started in Perl 6.

Edit: (2011) It's still a great time to hack on the Perl6 internals, but there is now a much more mature, usable Perl6 distribution, Rakudo Star. If you want to use Perl6 today, that's a great choice.

查看更多
劳资没心,怎么记你
5楼-- · 2019-03-17 13:11

IMO python's regexing, esp. when you try to represent something like perl's /e operator as in s/whatever/somethingelse/e, becomes quite slow. So in doubt, you may need to stay with Perl5 :-)

查看更多
三岁会撩人
6楼-- · 2019-03-17 13:20

Perl 6 has some great features over python. I think these are all features that Python 3 doesn't have:

  • an extensible, but optional type system
    • including multi-method dispatch and type checking
    • even for builtins and "operators"
    • with subset types
  • Roles: Non-instantiable classes for code reuse (aka mixins)
    • with some additional advantages over most mixins:
    • compile-time method name collision checking,
    • the ability to require, in a role definition, that certain methods are present in the host class, and subsequently to call methods of the host class in the implementation of the role.
  • Grammars (compositions of regexes that return structured data)
  • Powerful extended regexes. Fancier than python's built-in regex capabilities.
  • Junctions and type junctions
  • Metaoperators
  • The ability to define circumfix, postcircumfix, infix, prefix, and postfix operators.
  • Theoretically, the ability to work with the AST as structured data. (Aka: lisp macros)
  • Block scoping
  • The * term for generating closures out of any expression
  • Implicit concurrency constructs ([] meta, junctions)
  • Declarative concurrency constructs (hyper for)
  • The MAIN sub turns its function signature into a command line interface and a command line usage guide.
  • Lazy lists (but you can roll your own with generators)

And it shares with Python the following advantages over Perl 5:

  • The concept of a "class", the class keyword, and associated sugar**:
    • The self keyword
    • getter/setter sugar with the concept of private data
  • a well defined, accessible meta-object protocol
  • great unicode support
  • great date/time support built in
  • In general, "batteries included" - lots of builtin functions
  • non-globally scoped variables by default

Perl6's implementation is not 100% complete, or tuned enough to use for certain values of "performance sensitive" applications. But the 80-90% of the spec that is needed for 95-99% of use cases is complete in Rakudo, right now*

*One glaring omission is any provision for asynchronous I/O. That part of the spec is in flux.

** Though the popular Moose project provides this in Perl 5.

查看更多
放荡不羁爱自由
7楼-- · 2019-03-17 13:24

Perl is generally better than python for quick one liners, especially involve text/regular expressions
http://novosial.org/perl/one-liner/

查看更多
登录 后发表回答