tags:

views:

1687

answers:

14

It might seem it has been asked numerous times, but in fact it hasn't. I did my research, and now I'm eager to hear others' opinions.

I have experience with PHP 5, both with functional and object oriented programming methods. I created a few feature-minimalistic websites.

Professionals may agree about PHP not being a programming language that encourages good development habits. (I believe it's not the task of the tool, but this doesn't matter.) Furthermore, its performance is also controversial and often said to be poor compared to competitors.

In the 42nd podcast at Stack Overflow blog a developer from Poland asked what language he should learn in order to improve his skills. Jeff and Joel suggested that every one of them would help, altough there are specific ones that are better in some ways. Despite they made some great points, it didn't help me that much.

From a beginner point of view, there are not one may not see (correction suggested by S. Lott) many differences between Perl & Python. I would like You to emphasize their strenghts and weaknesses and name a few unique services.

Of course, this wouldn't be fair as I could also check both of them. So here's my wishlist and requirements to help You help me.

First of all, I'd like to follow OOP structures and use it fundamentally. I partly planned a multiuser CMS using MySQL and XML, so the greater the implementations are, the better. Due to its foreseen nature, string manipulation will be used intensively.

If there aren't great differences, comparisons should probably mention syntax and other tiny details that don't matter in the first place.

So, here's my question: which one should I try first -- Perl || Python?


Conclusion

Both Perl and Python have their own fans, which is great. I'd like to say I'm grateful for all participation -- there is no trace of any flame war.

I accepted the most valued answer, although there are many great mini-articles below. As suggested more often, I will go with Python first. Then I'll try Perl later on. Let me see which one fits my mind better.

During the development of my special CMS, I'm going to ask more regarding programming doubts -- because developers now can count on each other! Thank you.

Edit: There were some people suggesting to choose Ruby or Java instead. Java has actually disappointed me. Maybe it has great features, maybe it hasn't. I wouldn't enjoy using it.

In addition, I was told to use Ruby. So far, most of the developers I communicate with have quite bad opinion about Ruby. I'll see it myself, but that's the last element on my priority list.

+8  A: 

I'd go with Perl. Not everyone will agree with me here, but it's a great language well suited to system administration work, and it'll expose you to some more functional programming constructs. It's a great language for learning how to use the smallest amount of code for a given task, as well.

For the usage scenario you mentioned though, I think PHP may be your best bet still. Python does have some great web frameworks, however, so if you just want to try out a new language for developing web applications, Python might be your bet.

Alex Fort
+1 I'm glad to finally see some Perlites. Pyvangelism seems to be huge on SO, and even with Perl 6 in the future, some people *ahem* are claiming that "Pearl" is dying...
Chris Lutz
I await Perl 6 with bated breath, but I fear that it's going the way of Duke Nukem Forever..
Alex Fort
We got a Watchmen movie that was 20 years in the making (and sucked), and we got a Guns 'N' Roses album that was 13(-ish?) years in the making (and sucked), what's so insane about hoping for anything else?
Chris Lutz
Taking PHP's performance into consideration... I'd say no... I won't go with that... I really want the speed of light. :)
pestaa
+18  A: 

Considering that you want to do OOP quite extensively and the rather stagnant nature of Perl in recent years I'd rather suggest Python. Also it's (in my humble opinion) much less cluttered with gazillions of different syntactic elements (not to be taken that serious) but instead fresh and simple. Also I've been told, even though I've never tried myself, Perl pretty much sucks for OOP, although I can't verify that.

In terms of the standard library that comes with both languages I doubt you'll be missing much in either language.

Joey
Perl's "gazillions of different syntactic elements" aren't all that gazillion-y. I rather like my postfix conditionals: die "Error: $!" if $!;
Chris Lutz
Well, when reading Perl I often did now know what a given syntax element does, whereas in other languages it'd be just a function with a name you can understand (excluding C). Sure, that may be one source of why Perl can do insane stuff in just a few bytes, but mostly that's not a real goal.
Joey
@Chris: I just assumed he meant things like =~ or <> (which, for those non-Perl people, isn't the not equals operator) or all its magic variables (ignoring use English; for the moment).
R. Bemrose
I can see how <> would be a bit confusing (and rather specialized). Besides, != is a not-equals operator - having <> also be not-equals is redundant (and looks kind of dumb). And I'll admit that even I have to surf http://perldoc.perl.org/perlvar.html to look up what magic variable I need sometimes.
Chris Lutz
Also (coming from someone who uses Perl (beat down on a lot by Python fans) and C (beat down on a lot by C++ fans for some reason)) it seems like a lot of people will apologize or stick up for C++'s horribly ambiguous syntax (cout << "Hello!") but criticize Perl for (almost) the same thing.
Chris Lutz
Python also has its share of operator overloading,to be fair. Think "int: %i float: %f" % (5, 3.14) for example. But it's scarce. And yes, I've seen horrible examples what better not to do in C++ (including Boost) so I can almost understand the Java inventors for leaving op overloading out.
Joey
Perl is only stagnant if you haven't been paying attention. Perl's OO is not "pure", but it is flexible. And with Moose, it's as pure (or more so) than most anything.
runrig
@Johannes Rössel: Are there any other examples of operator overloading beyond "%"? Isn't that the only one?
S.Lott
+ is overloaded for tons of things (numbers, strings, tuples, ...), * works as multiplication but also as repeater. There are more examples.
Leon Timmermans
I suspect that Moose (http://search.cpan.org/perldoc?Moose) is plenty good enough and innovative enough to provide an oop environment par excelence. Also bear in mind that perl is more commonly installed on machines than python too.
singingfish
In my opinion its not accurate to say that Perl is stagnant when you consider CPAN or that it has poor OO when you consider Moose.
Eric Johnson
+10  A: 

Honestly, the "majority" of my programming has been in Perl and PHP and I recently decided to do my latest project in Python, and I must admit it is very nice to program with. I was hesitant of the whole no curly braces thing as that's what I've always done, but it is really very clean. At the end of the day, though, you can make good web applications with all 3, but if you are dead-set on dropping PHP to try something new I would recommend Python and the Django framework.

Paolo Bergantino
Django is repeatedly said to be so cool. Is that really so good, or just a popular framework?
pestaa
It is popular for a reason. :) As far as your PHP concerns on performance, PHP performance can be quite good if you do the right things: memcache, etc.
Paolo Bergantino
@pestaa: good usually leads to popular. Few things can be popular and bad. Unless there's some kind of trade monopoly (like Windows).
S.Lott
@Paolo: and Perl/Python with cache enabled might lead to even better performance. I want a solid base to build on.@S. Lott: please don't start flame wars. :) I can name popular and bad things in the world of PHP. (Zend Framework for example. Or even PHP itself?)
pestaa
@pestaa: I think if Wikipedia and Facebook can make PHP work for them, your performance should be fine. Don't drop the entire language because of a perceived idea that may not necessarily be true.
Paolo Bergantino
@pestaa: I'm not aware of any popular and bad things in the Python world. I'm not interested in a flame war. I'm saying that your question "good or just popular?" doesn't make any sense to me.
S.Lott
@Paolo: I do not have as much resource as Wikimedia Foundation or Facebook's fathers have. It is not a problem to optimize a CMS written in PHP, so it can generate a busy homepage within a second. What if I want it to be rendered within half a second?@S. Lott: You seem one-sided regarding Python.
pestaa
@pestaa: Premature optimization is the root of all evil. PHP is very capable.
Paolo Bergantino
+7  A: 

I have no experience with Python. I vouch strongly to learn Perl, not out of attrition, but because there is a TON to learn in the platform. The key concepts of Perl are: Do What I Mean (DWIM) and There's More Than One Way To Do It (TMTOWTDI). This means, hypothetically there's often no wrong way to approach a problem if the problem is adequately solved.

Start with learning the base language of Perl, then extend yourself to learning the key Perl modules, like IO::File, DBI, HTML::Template, XML::LibXML, etc. etc. search.cpan.org will be your resource. perlmonks.org will be your guide. Just about everything useful to do will likely have a module published.

Keep in mind that Perl is a dynamic and loosely structured language. Perl is not the platform to enforce draconian OOP standards, but for good reason. You'll find the language extremely flexible.

Where is Perl used? System Admins use it heavily, as already mentioned. You can still do excellent web apps either by simple CGI or MVC framework.

spoulson
Why do you have an opinion on which of the two to choose if you have no experience with Python?
Ryan Ginstrom
IO::File? I can't imagine the criteria that would rate that a key module.
ysth
My answer is to educate. The questioner will make their own decision. If you feel so strongly, then I recommend putting in your answer.
spoulson
+3  A: 

As a Perl programmer, I would normally say Perl. But coming from PHP, I think Perl is too similar and you won't actually get that much out of it. (Not because there isn't a lot to learn, but you are likely to program in Perl using the same style as you program in PHP.)

I'd suggest something completely different: Haskell (suggested by Joel), Lisp, Lua, JavaScript or C. Any one of these would make you a better programmer by opening up new ways of looking at the world.

But there's no reason to stop learning PHP in the meantime.

For a good look at the dark side of these languages, I heartily recommend: What are five things you hate about your favorite language?

Jon Ericson
PHP and Perl are C-like and share some language constructs, but only at the surface. There is far more to learn from Perl than PHP. I'm certain there's plenty to learn from a LISP language, but not just because it's unlike C.
spoulson
Yeah. I realized after I posted that the reason for discounting Perl in this case was because of habits, not content.
Jon Ericson
Admittedly, Perl is not for everyone. But I'm fine with that.
spoulson
Perl is very similar to PHP, but they're also very different. I think there are a lot of benefits to learning Perl from PHP (or vice versa, as I'm sortof doing). Just because Python is "more different" doesn't mean learning it will teach you more. But +1 for C - learning memory management is good!
Chris Lutz
Note that I completely side-step Python. The nicest thing I could think to say was that the CPU-hogging Python scripts I've dealt with look very clean, which isn't all that nice.
Jon Ericson
+6  A: 

I haven't worked with Python much, but I can tell why I didn't like about Perl when I used it.

  1. OO support feels tacked on. OO in perl is very different from OO support in the other languages I've used (which include things like PHP, Java, and C#)
  2. TMTOWTDI (There's More Than One Way To Do It). Good idea in theory, terrible idea in practice as it reduces code readability.
  3. Perl uses a lot of magic symbols.
  4. Perl doesn't support named function arguments, meaning that you need to dig into the @_ array to get the arguments passed to a function (or rather, a sub as perl doesn't have the function keyword). This means you'll see a lot of things like the example below (moved 'cause SO doesn't like code in numbered lists)

Having said all that, I'd look into Python. Unless you want to go with something heavier-weight like C++ or C#/Java.

Oh, before I forgot: I wanted to put an example for 4 above, but SO doesn't like putting code in numbered lists:

sub mySub {
    #extremely common to see in Perl, as built-ins operators operate on the $_ scalar or @_ array implicitly
    my $arg1 = shift;
    my $arg2 = shift;
}
R. Bemrose
Nothing is perfect. I happen to think Python's docstrings have a particularly horrid-looking syntax. I mean, seriously. Triple-quoted strings. """This does not look like it should parse"""
Chris Lutz
"TMTOWTDI (There's More Than One Way To Do It). Good idea in theory"? Really? It doesn't sound like a good idea even in theory. Ambiguity is always a problem.
S.Lott
I believe if the language constructs are in the way, you have either not fully learned the language or are misapplying it. Most of these items are problems a novice must learn to deal with.
spoulson
On the mySub example, use "my ($arg1, $arg2) = @_;"
spoulson
@spoulson: True, I didn't think of doing it that way... I haven't dealt with Perl on a regular basis since Summer '06.
R. Bemrose
I, too found the OO aspects of Perl "tacked on" compared to Java, Ruby and even (shudder) C++. A friend I respect greatly, FWIW, calls Python "Perl done right".
Leonard
It's quite easy to pass a hash into a Perl subroutine and use that to supply named arguments (in any order). sub get_dimensions { my %params = @_; my $area = $params{'width'} * $params{'length'}; }
Telemachus
OO WAS tacked on to Perl. Thats why we now have Ruby.
Brad Gilbert
Actually personally, I can hardly wait for Perl6 to leave the other dynamic languages in the dust. There are so many things that you can easily do now, today, with Perl6, that you can't do nearly as easily in other languages. And it's not even done yet.
Brad Gilbert
@Telemachus - Nice trick. I like it.
Chris Lutz
Perl OO was tacked on. It's simple, flexible, and if you want something more "purely" OO, use Moose. OO is not the be-all, end-all of programming paradigms.
runrig
Used properly TMTOWTDI *increases* readability as it gives you the flexibility to select the clearest way to express something. Used improperly... it gives you enough rope to tie a syntactical Gordian knot.
Michael Carman
MooseX::Declare is best for Perl OO
Alexandr Ciornii
+17  A: 

Perl is a very nice language and CPAN has a ton of mature modules that will save you a lot of time. Furthermore, Perl is really moving forwards nowadays with a lot of interesting projects (unlike what uninformed fanboys like to spread around). Even a Perl 6 implementation is by now releasing working Perl 6.

I you want to do OO, I would recommend Moose.

It warms my heart to see the Perl love here. As soon as I saw 'Python or Perl?' I was sure a thousand people were going to post about how Perl is dead. With frameworks like Moose and Perl 6 development moving very quickly, it's far from dead (plus my company uses it all over the place)
rjh
Perl is dead....:P
jjnguy
Careful jjnguy - you saw what happened the last time you said that. ;)
Chris Lutz
Ha, I never learn...
jjnguy
+1  A: 

Why isn't there Ruby on your list? Maybe you should give it a try.

daddz
+1  A: 

If those 2 are your only choices, I would choose Python.

Otherwise you should learn javascript.

No I mean really learn it...

Scott Evernden
Are you familiar with javascript? It isn't a server-side language. Did you mean Java?
pestaa
Why isn't javascript a server-side language? I'm quite sure I'm not the only one using it server-side.
Dustin
Javascript's dirty little secret: hidden under all that DOM/HTML stuff is a very nice language.
ysth
+2  A: 

"I'd like to follow OOP structure..." advocates for Python or, even more so if you're open, Ruby. On the other hand, in terms of existing libraries, the order is probably Perl > Python >> Ruby. In terms of your career, Perl on your resume is unlikely to make you stand out, while Python and Ruby may catch the eye of a hiring manager.

As a PHP programmer, you are probably going to see all 3 as somewhat "burdensome" to get a Web page up. All have good solutions for Web frameworks, but none is quite as focussed on rendering a Web page as is PHP.

I think that Python is quite likely to be a better choice for you than Perl. It has many good resources, a large community (although not as large as Perl, probably), "stands out" a little on a resume, and has a good reputation.

Larry OBrien
"In terms of your career..." That sentence sounds extremely unlikely. A manager won't look for "something cool," they'll look for the languages their company uses to develop software. A company that runs Perl won't hire you for knowing Ruby. Maybe if you know Ruby AND Perl...
Chris Lutz
http://www.pylonshq.com/Have a look
Sybiam
Perl programmers are rare these days. So Perl might actually help you. Unless, of course, you're looking for a Python job. Chris has got a point.
innaM
@Chris Lutz: I tend to disagree. I think (good) hiring managers are looking for signs of engagement with the community and _do_ take notice if a person is using languages / frameworks / approaches that are considered more "current". YMMV.
Larry OBrien
+1  A: 

If you won't be doing web development with this language, either of them would do. If you are, you may find that doing web development in perl is a bit more complicated, since all of the frameworks require more knowledge of the language. You can do nice things in both, but my opinion is that perl allows more rapid development.
Also, perl's regexes rock!

Geo
+2  A: 

I suggest going through a beginner tutorial of each and decide for yourself which fits you better. You'll find you can do what you need to do in either:

Python Tutorial (Python Classes)

Perl Tutorial (Perl Classes) (Couldn't find a single 'official' perl tutorial, feel free to suggest one)


In my experience python provides a cleaner, more straight-forward experience.

My issues with perl:

  • 'use strict;', Taint, Warnings? - Ideally these shouldn't be needed.

  • Passing variables: @; vs. $, vs shift

  • Scoping my, local, ours? (The local defintion seems to particularly point out some confusion with perl, "You really probably want to be using my instead, because local isn't what most people think of as "local".".)

In general with my perl skills I still find my self referencing documentation for built-in features. Where as in python I find this less so. (I've worked in both roughly the same amount of time, but my general programming expereince has grown with time. In other words, I'd probably be a better perl programmer now)

If your a unix command line guru though, perl may come more naturally to you. Or, if your using it mainly as a replacement or extension to command line admin tasks, it may suit your needs fine. In my opinion perl is "faster on the draw" at the command line than python is.

monkut
"use strict;" - it is a sign, if it is missing it means that program rewritten :).
Alexandr Ciornii
+4  A: 

I recently made the step from Perl over to Python, after a couple of Perl-only years. Soon thereafter I discovered I had started to read through all kinds of Python-code just as it were any other easy to read text — something I've never done with Perl. Having to delve into third-party Perl code has always been kind of a nightmare for me, so this came as a very very nice surprise!

For me, this means Python-code is much easier to maintain, which on the long run makes Python much more attractive than Perl.

Guðmundur H
+2  A: 

Python is clean and elegant, and the fact that LOTS of C APIs have been wrapped, gives you powerful hooks to much. I also like the "Zen of Python".

  • Beautiful is better than ugly.
  • Explicit is better than implicit.
  • Simple is better than complex.
  • Complex is better than complicated.
  • Flat is better than nested.
  • Sparse is better than dense.
  • Readability counts.
  • Special cases aren't special enough to break the rules.
  • Although practicality beats purity.
  • Errors should never pass silently.
  • Unless explicitly silenced.
  • In the face of ambiguity, refuse the temptation to guess.
  • There should be one-- and preferably only one --obvious way to do it.
  • Although that way may not be obvious at first unless you're Dutch.
  • Now is better than never.
  • Although never is often better than right now.
  • If the implementation is hard to explain, it's a bad idea.
  • If the implementation is easy to explain, it may be a good idea.
  • Namespaces are one honking great idea -- let's do more of those!
gregturn
I really like your list, although I can't completely understand why many of them are here. Those are widely accepted or recommended programming activities.
pestaa