Why does perl allow so many different ways of doing essentially thesame thing?

P

Peter J. Holzer

Agreed.

I think this is a more important problem than figuring out how many
ways of programming there are and choosing the best one out of them,

I think you are looking at it the wrong way. You think that just because
Perl provides multiple ways to do something you have to explore all of
them and find out which is best. But that isn't true. You just have to
find one way. And because there are multiple ways, there is likely to be
one way which is very similar to the way you would like to solve the
problem. You don't have to think "Well, I would like to do X, but the
language doesn't let me. But I could do Y and Z and that should do the
same".

Perl is an executable brain dump.

in the sense that once such choice has been figured out in a given
context, then just package it into an API then people don't have to
worry about it in the future.

Have you looked at CPAN yet? A lot of people have packaged stuff into an
API. So you just have to worry about which API to pick :).

hp
 
P

Peter J. Holzer

According to Programming Perl, more than one way may not always be
better. But I just don't see more than one way is better at all.

I think that any code can be encapsulated in a subroutine or a class.
To the end user, the actually implementation doesn't matter.

No, but it does matter to the programmer. Programming languages are
there for the programmer, not the user. Somebody will have to write and
maintain that subroutine and it is important that this person can
express the function of the subroutine in a natural way. Otherwise we
could just have stuck with machine language.

hp
 
P

Peter J. Holzer

Rather than being hypothetically saying there are different ways of
coding for different parameter values. I'd like to see what the best
code is for reading three lines and what is the best code is for
reading 10000 lines?

Three lines I would just slurp into memory. I would probably do the same
for 10000 lines. But for 10000000 lines, I would process them line by
line, keeping only the information absolutely needed.

Then it depends on the frequency of the task. If I have a piece of code
which needs to read the same file pretty frequently (say about once per
second) and the file might change at random moments, then:

* for a 3 line file I would just read the file every time
* for a 10000 line file I would check whether the file has actually
changed before reading it again.

Oh, and this is almost independent of the language. TIMTOWTDI in every
language.

hp
 
P

Peter J. Holzer

I'd say the same is true for Perl. Its power lies in the fact
that it gives the possibility to work one step closer to the
machine than with other competing languages like e.g. Java, C#
or PHP.

For me Java is a lot closer to the machine then Perl.

hp
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,780
Messages
2,569,609
Members
45,253
Latest member
BlytheFant

Latest Threads

Top