LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Perl or Python ? (https://www.linuxquestions.org/questions/programming-9/perl-or-python-828635/)

vbx_wx 08-26-2010 10:45 AM

Perl or Python ?
 
Whats its best to learn, Pear or Python ?

ghostdog74 08-26-2010 10:52 AM

This topic is subjective and argumentative. The only solution to your problem, is to learn both and then find the one best suited for yourself.

David1357 08-26-2010 12:02 PM

Quote:

Originally Posted by vbx_wx (Post 4078603)
Whats its best to learn, Perl or Python?

Perl gives you a lot of ways of doing essentially the same thing. This is a feature that Perl users are proud of.

Python is deliberately more terse, requires a specific type of indentation, and has no way of indicating the end of a function.

If you want ultimate flexibility at the cost of having to spend more time choosing which method you want to use to solve a problem, use Perl.

If you are more interested in solving problems quickly and don't mind being forced to write your code in a specific style, use Python.

Sergei Steshenko 08-26-2010 12:32 PM

The difference is that Perl has in it much more from functional programming paradigm ( http://en.wikipedia.org/wiki/Functional_programming ). Python is slowly catching up (i.e. Python 3.* vs Python 2.*).

I find the functional features quite convenient.

This may sound odd, but in order to appreciate Perl read on Higher Order Perl: http://hop.perl.plover.com/ .

b0uncer 08-26-2010 02:56 PM

I'm learning both. I'd like to say "know", but as it is, there's so very much I don't master yet (in both languages) even though I do get results and have built up scripts/programs that are hundreds of lines long. The thing is, neither was very difficult to learn and neither took long to learn to use. Pros: I can now work with either of them, depending on which one I have available or want to use or suits better for the given situation. Cons: knowing only one would probably have been sufficient, so I've "thrown away" some time by learning both. Not a con really.

In short, learn both of them. You're not going to lose anything. Instead if you only learn either one, but not both, you very probably will be haunted by the thought "was this really the best choice?" for the rest of your life, or up to the point where you do learn the other as well.

Next question you're going to ask is "should I learn Python 2 or Python 3, or Perl 5 or Perl 6?". Answer: all of them :)

Sergei Steshenko 08-26-2010 03:37 PM

Quote:

Originally Posted by b0uncer (Post 4078802)
... Perl 5 or Perl 6?". Answer: all of them :)

I am looking at Perl6, and my feelings are getting sadder and sadder, even though they've made a usable release. The sad feelings about Perl 6 are coming from its early testers' reports - it is slow and bloated, though it shouldn't necessarily be.

And the main developer wrote that strict typing, when used, makes the code slower though conceptually it should enable faster code.

So, my intent to learn OCaml instead of Perl 6 steadily grows; Perl 5 is still my favorite language at the moment.

SaintDanBert 08-26-2010 05:14 PM

Quote:

Originally Posted by b0uncer (Post 4078802)
...
In short, learn both of them. You're not going to lose anything. Instead if you only learn either one, but not both, you very probably will be haunted by the thought "was this really the best choice?" for the rest of your life, or up to the point where you do learn the other as well.
...

Most programming languages are very similar. Make sure that you learn enough to be able to read both Perl and Python. Then read, read, ... read software learning coding styles and common patterns
of statements and expressions.

As with natural languages (English, Greek, Persian, etc), it is much harder to learn to speak and write the language than it is to hear and read that same language. As you read, you'll find that either Perl or Python suits your personal style.

Cheers,
~~~ 0;-Dan

ghostdog74 08-26-2010 07:34 PM

Quote:

Originally Posted by David1357 (Post 4078669)
Perl gives you a lot of ways of doing essentially the same thing. This is a feature that Perl users are proud of.

there's more than one ways to do it. But some ways are not obvious and "beats around the bush" before solving the problem. There should be only just one obvious way to do it without beating about the bush.

Quote:

Python is deliberately more terse, requires a specific type of indentation, and has no way of indicating the end of a function.
Indentation to the first timer may seem irksome, but it all takes time to get used to. what do you mean by "doesn't know how to end a function"?

pr_deltoid 08-26-2010 07:57 PM

Quote:

Originally Posted by Sergei Steshenko (Post 4078838)
So, my intent to learn OCaml instead of Perl 6 steadily grows;

Do you have any specific problems with Ruby? It seems like a very good language to me, and it borrows ideas from Python, Perl, Smalltalk, etc. I've been having a hard time making a decision between Ruby and Python, but Python is used so much and for so many different things that it seems like a better language to learn as far as existing software being written in it or using it.

grail 08-26-2010 08:04 PM

I am in the learn as much as you can group, although as pointed out in earlier posts this can make it difficult to become a guru in any language
quickly. I agree with Dan's post too that most languages use a commonish ground work (not trying to start a flame here) so to this end you can also look at it that
if you become accomplished in one language it will generally be less of an arduous task to learn another.

Sergei Steshenko 08-26-2010 08:28 PM

Quote:

Originally Posted by prdeltoid (Post 4078987)
Do you have any specific problems with Ruby? It seems like a very good language to me, and it borrows ideas from Python, Perl, Smalltalk, etc. I've been having a hard time making a decision between Ruby and Python, but Python is used so much and for so many different things that it seems like a better language to learn as far as existing software being written in it or using it.

I am using Perl since 1993 or 1994. Until very recently Ruby used to be very slow.

What can Ruby do Perl can't ? I mean not only built-in functions, but things like closures, anonymity, scoping rules and the like.

...

I've been looking closely at Perl6 because I want a language which allows both loose and strict typing - Perl6 allows. It looks like I'll look for strict typing in OCaml, and will still be using Perl5 for loosely typed programs.

Sergei Steshenko 08-26-2010 08:48 PM

Quote:

Originally Posted by ghostdog74 (Post 4078971)
... There should be only just one obvious way to do it without beating about the bush. ...

Because as a person who knows Perl I also know that a string can be split both using 'split' and regular expression, and because Python allows both these ways two, there is more than one way to it in Python too.

ghostdog74 08-26-2010 09:26 PM

Quote:

Originally Posted by Sergei Steshenko (Post 4079007)
Because as a person who knows Perl I also know that a string can be split both using 'split' and regular expression, and because Python allows both these ways two, there is more than one way to it in Python too.

wrong. Python's split doesn't allow regular expression. It shows you don't know Python enough to fairly comment on this. If one wants to use regex, he has import the re module and then use re.split(). Python's design encourage one to produce consistent code.

An example out of the many, see this FAQ for Perl to count substrings. True to Perl's mantra, there are a few ways to do it as stated in the FAQ.
With Python, there is only one obvious way (note the word obvious),
Code:

>>> string = "ThisXlineXhasXsomeXx'sXinXit"
>>> string.count('X')
6

Another example, you can open filehandles with 2 ways, one with brackets, one without
Code:

open FILE, '<', "foo.txt" or die "Can't open: $!";
open(FILE,"<foo.txt") or die "....";

In Python, you only need to use one way.
Code:

open('foo.txt')
These are examples of why Perl can encourage inconsistency in code programming.

you really have no reason to argue with me on this point of "more than one ways in Perl vs that in Python", if you have used Python long enough as you had used Perl.

Sergei Steshenko 08-26-2010 10:18 PM

Quote:

Originally Posted by ghostdog74 (Post 4079026)
wrong. Python's split doesn't allow regular expression. ...

I didn't mean that. I meant that using regular expressions (not in the 'split'' function) a string can be split - because matches in regular expression can be collected in buffers (what in Perl is called $1, $2, etc).

So, conceptually there is a 'split' way to split a string and a regular expression way to split a string - both way are present in both langauges.

So, as I said, there is more than one way to do it.

ghostdog74 08-26-2010 10:36 PM

Quote:

Originally Posted by Sergei Steshenko (Post 4079049)
So, as I said, there is more than one way to do it.

There's more than one way to do it, but sometimes consistency is not a bad thing either (TIMTOWTDIBSCINABTE). You can follow TIMTOWTDI mantra all you want, that's your business and i don't care.


All times are GMT -5. The time now is 02:02 AM.