LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 07-24-2003, 10:25 PM   #1
Strike
Member
 
Registered: Jun 2001
Location: Houston, TX, USA
Distribution: Debian
Posts: 569

Rep: Reputation: 31
My perl rant


As promised in the "What languages do you use?" thread, here's my laundry list of perl complaints.

The biggest complaint I have is that the very nature of perl and its community encourages bad/wrong/stupid/poor solutions in general. The syntax encourages it, the structure of the language encourages it, the existing examples encourage it, and "common practice" from what I've seen .. also encourages it.

A classic example is perl golf. Perl golf is when perl coders try to see who can make the shorter script to do a task. Now I'll admit that I've done the same thing and that it can be kind of fun, but it's not useful and many perl coders I've known think that it is. There is something to said for being nice and compact and succinct, but not sacrificing readability and/or doing "black magic" when something more obvious does the equivalent.

Of course, the community credo "TIMTOWTDI" is something I absolutely detest. Having more than one way to do things is fine, but priding yourself on it isn't all that praiseworthy. A better credo would be "There should be one-- and preferably only one --obvious way to do it." (stolen from Tim Peters' The Zen of Python). Note that there's not only one way to do a given task, but there's only one obvious way of doing it, and it should be the best way. A friend of mine pointed me to an Ars Technica Programmers Symposium thread where several perl hackers were hacking up solutions to a poster's problem. He wanted to store all but the first line of a file in an array. Now, the perl hackers came up with weird schemes involving indices and checking if the line was the first line and whatnot. The simpler and easier solution is just to read the first line of the file, throw it away, and THEN start reading all the lines into an array. Between 4 or 5 perl coders, it took one python coder who happened to know perl to set them straight And although this is anecdotal evidence, the problem really is epidemic.

Perl is also not very flexible from a paradigm standpoint. It's pretty much very tied to being a scripting language. The OOP in it stinks to high hell, I've seen no functional bits in it, and even defining functions is cumbersome (IMO). From what I remember, the standard perl idiom for defining functions is just something like:
Code:
sub foo {
    my $arg1 = shift;
    my $arg2 = shift;
    ... etc ...
}
That convention sucks! Contrast that with Python that not only allows default values in a saner syntax, but it also allows variable length arg lists via positional and/or keyword arguments:
Code:
def foo(bar, *args, **kwargs):
Now, I know the asterisk syntax is a bit ugly, but I'll accept that for the power it offers. I can now enter in arg lists like this:
Code:
foo(1, 2, 3, blah="w00", baz=[1, 2, 3], 4, 5)
and they are all easily accessible. Granted, I normally don't need exotic arg lists like this, but it's nice to have the option. Also, I vastly prefer being able to see the arg list in order all on one line with the function name. I don't like having to look inside the function itself and look for "shift"s.

Contexts are another thing I never understood with perl. Why a variable would be something different in different contexts makes no sense to me. What gains are there from having context-sensitivity of variables? Because they are EXTREMELY counterintuitive. For example, if you want the length of an array, the length function is NOT what you want (because of context issues). Instead, you use scalar to bring the array into a scalar context, which for some magical reason is the length of the array. Arrays are the thing you would measure the length of MOST, I would think (if not one of the most). So when the length function doesn't do what it's purported to do by its name for the most common use, I consider that a problem.

The last thing I'll touch on for now (since I think I've hit enough) is just that I find that perl just plain looks ugly. Even "clean perl" looks ugly. It may not look hideous, but it sure doesn't look pretty. Prepending sigils (the characters on the front of variables) is nasty. Having several of them that each actually change the meaning of a variable is even worse. People say "oh but it makes it easier to see that it's a variable". Sorry, but I don't buy it. Well-chosen variable names and well written code should make that VERY clear already. It should be just as obvious that "names_list" is a variable as "$names_list".

Well, I could go into more, but I'll wait for feedback and respond from there.
 
Old 07-25-2003, 02:18 AM   #2
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
I've found perl to be lovely personally. top stuff. as far as functions go:
Code:
sub monkey {
   my ($blah, $foo, $bar) = @_;
   ...
}
simple.... can do exactly the same as under python without any problems at all. The OOP isn't all there, but I've never really been in a position to need to do that much with it.
 
Old 07-25-2003, 02:43 AM   #3
Strike
Member
 
Registered: Jun 2001
Location: Houston, TX, USA
Distribution: Debian
Posts: 569

Original Poster
Rep: Reputation: 31
Quote:
Originally posted by acid_kewpie
I've found perl to be lovely personally. top stuff. as far as functions go:
Code:
sub monkey {
   my ($blah, $foo, $bar) = @_;
   ...
}
simple.... can do exactly the same as under python without any problems at all. The OOP isn't all there, but I've never really been in a position to need to do that much with it.
Okay, that's slightly less ugly than what I have above, but it raises another excellent point that I'm ready to rant about.

AUTOMATIC VARIABLES
Evil. Pure evil. And even more evil are automatic variables with obscure names that are used so as not to pollute the namespace. In short, all the automatic variables that perl sets. $_, @_, $$, etc. Not a single one of those is descriptive of what it is. That violates a fundamental, basic tenet of good programming - name your variables with descriptive (but succinct) names. And using these is often the commonly accepted idiomatic perl solution, so you see them in a majority of programs. As if that weren't bad enough, they aren't just set once per script or anything like that, they change depening on what functions you call! So in a foreach, you'll have $_ reset (many times, probably).

The counterargument is "okay, but any one who wants to be a perl coder can just memorize or look up those few automatic variables when the time comes." Sure, but why should they have to? Besides, not everyone who may have to tinker with code really strives to be able to author and/or maintain that code, so they have no real reason to spend time learning what each of those variables is set to for each function just to tinker with one script to suit their needs. It's an implicit behavior and being explicit in programming is almost always preferable, and it's definitely preferable here.
 
Old 07-25-2003, 03:04 AM   #4
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
you only need to add "use English;" to be able to call $_ $ARG instead (which is obviosuly totally parallel to argc, argv in c) but you can't penalise the use of an effective convention. everyone in perl knows $_, so you're playing on the same field.
 
Old 07-26-2003, 10:42 AM   #5
Strike
Member
 
Registered: Jun 2001
Location: Houston, TX, USA
Distribution: Debian
Posts: 569

Original Poster
Rep: Reputation: 31
Quote:
Originally posted by acid_kewpie
you only need to add "use English;" to be able to call $_ $ARG instead (which is obviosuly totally parallel to argc, argv in c)
This does not make them not get set though. The fact that the language sets variables for you is my biggest beef about the whole thing. Remember, explicit is better than implicit. If a variable is set, for the most part I'd expect that it was set somewhere in the code. And if it isn't set somewhere in the code, I certainly would not want things that occur in the code to CHANGE it unless they do so EXPLICITLY. The magical behavior of $_ for things like foreach does exactly that and it is Bad and Wrong (TM).

Quote:
but you can't penalise the use of an effective convention.
I can and do. It's not an "effective convention". It saves one perl programmer 3 or 4 keystrokes. That does NOT make it effective. Naming all your variables one or two letter variable names would also be an "effective convention" if that's your only argument for efficiency. But I would hope that you would never do that either because it is also very braindead.

Quote:
everyone in perl knows $_, so you're playing on the same field.
That's the problem, even if "everyone in perl" DOES know it, that excludes everyone "outside" of perl. This includes: people who just want to make minor hacks of perl scripts, people learning perl, people who already learned perl but don't use it enough to remember the stupid obscurely named automatic variables. Again, explicit is better than implicit: just DON'T set automatic variables and none of these problems exist. Is it really that hard to do something like this to get argv? (using python as the example)

Code:
import sys
Then all you have to do is use sys.argv to have access to it. That variable name is WAY clearer than $_ and it will always contain argv whereas $_ may or may not, depending upon where you are in your program and what you've done - REGARDLESS OF WHETHER YOU EXPLICITLY ASKED IT TO CHANGE OR NOT.

I'm not arguing that the conventions used in perl don't work for its programmers, because they obviously do. I'm just saying that the conventions followed by perl are bad for programming in general.
 
Old 07-26-2003, 11:15 AM   #6
david_ross
Moderator
 
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047

Rep: Reputation: 79
Use it or lose it. Like acid_kewpie I like perl. I don't always use it but think of it as another weapon in your armoury. There are situations where I'll use several languages to achive a task as many have their advantages.

You can't start saying that because perl calls a subroutine/function different from another language it is worse.
 
Old 07-26-2003, 11:28 AM   #7
Strike
Member
 
Registered: Jun 2001
Location: Houston, TX, USA
Distribution: Debian
Posts: 569

Original Poster
Rep: Reputation: 31
Quote:
Originally posted by david_ross
Use it or lose it. Like acid_kewpie I like perl. I don't always use it but think of it as another weapon in your armoury. There are situations where I'll use several languages to achive a task as many have their advantages.

You can't start saying that because perl calls a subroutine/function different from another language it is worse.
No, and if you'll read what I'm saying you will see that that is not what I'm saying. I'm not saying that it is worse because it is different, I am saying it is worse because it is stupid. It is less clear, harder to read, and less powerful than many alternatives.

Last edited by Strike; 07-26-2003 at 11:55 AM.
 
Old 07-27-2003, 12:40 PM   #8
coolman0stress
Member
 
Registered: Jun 2003
Location: Toronto, Ontario, Canada
Posts: 288

Rep: Reputation: 30
Excellent, you make so good points, some of which i agree with.

From what i've seen so far, Perl seems to be great for small, quick things, but becomes horrible messy with big projects. By messy i mean it becomes harder for other people to read it. My main "issue" is that if you don't know Perl well enough it's very hard to figure out what people are doing in their code. Ie, i find that a lot of the stuff in Perl isn't intuitive. Obviously you DO need to know a lot in any language to do some of the complex stuff. With Perl though it seems that you need to read up on it a lot more. There is just a lot more detail involved to understand stuff.
 
Old 07-27-2003, 01:36 PM   #9
Tesl
Member
 
Registered: Jun 2003
Location: Durham, UK
Distribution: Slackware 9, Mandrake 9.1
Posts: 163

Rep: Reputation: 30
i bought O'Reilly's "Programming Perl" but i havent really got that far through it yet.

I enjoy programming, and am comfortable with C++, and am in the process of improving my Java. As far as those languages go, i like to think that im fairly strong with them

when it came to learning Perl, i just havent been able to make that much sense out of it, and it does at times seem like a really horrible language. I can see how it could prove to be very powerful at times, but i havent really forced myself to learn it.

Maybe eventually i will, but i agree with a lot of the points mentioned about the language structure/syntax
 
Old 07-27-2003, 04:15 PM   #10
Strike
Member
 
Registered: Jun 2001
Location: Houston, TX, USA
Distribution: Debian
Posts: 569

Original Poster
Rep: Reputation: 31
Quote:
Originally posted by Tesl
i bought O'Reilly's "Programming Perl" but i havent really got that far through it yet.

I enjoy programming, and am comfortable with C++, and am in the process of improving my Java. As far as those languages go, i like to think that im fairly strong with them

when it came to learning Perl, i just havent been able to make that much sense out of it, and it does at times seem like a really horrible language. I can see how it could prove to be very powerful at times, but i havent really forced myself to learn it.

Maybe eventually i will, but i agree with a lot of the points mentioned about the language structure/syntax
I strongly suggest that you skip perl entirely and just learn Python. Some resources:

Python tutorial
How To Think Like A Computer Scientist: Learning With Python
Dive Into Python
Python Library Reference (this is essentially all the reference you need for the core python distribution)
Python for Beginners
 
Old 07-27-2003, 04:19 PM   #11
Strike
Member
 
Registered: Jun 2001
Location: Houston, TX, USA
Distribution: Debian
Posts: 569

Original Poster
Rep: Reputation: 31
Quote:
Originally posted by coolman0stress
Excellent, you make so good points, some of which i agree with.

From what i've seen so far, Perl seems to be great for small, quick things, but becomes horrible messy with big projects.
You hit the nail right on the head Only the corollary to that is that there are other things that are great for both, so learning perl itself becomes somewhat of a non-issue.

Quote:
By messy i mean it becomes harder for other people to read it.
It's not just that, perl program structure doesn't encourage modularity very well.

Quote:
My main "issue" is that if you don't know Perl well enough it's very hard to figure out what people are doing in their code. Ie, i find that a lot of the stuff in Perl isn't intuitive.
Yeah, I covered a bit of that above. Plus, every perl programmer has their own way of doing a specific task (TIMTOWTDI, yay).

Quote:
Obviously you DO need to know a lot in any language to do some of the complex stuff.
Well, it depends on the language, really. High-level languages obviously should allow you to do more complex things with less work.

It sounds like you pretty much see where I'm coming from though. And like I posted in the previous post, I strongly recommend Python to anyone who is tempted to learn Perl instead.
 
Old 07-27-2003, 06:08 PM   #12
lackluster
Member
 
Registered: Apr 2002
Location: D.C - USA
Distribution: slackware-current
Posts: 488

Rep: Reputation: 30
yes .... incorporating indentation into a language is a great thing

personally, I LOVE perl. it's quick, easy and has a module for just about everything. I guess at first it was a little strange seeing all those weird symbols all over the place, but it wasn't long before I learned them and their meanings (took much longer in C).

I will admit that for BIG projects I wouldn't use perl. But I certainly wouldn't use python or ruby either. I'd probably use C or C++.

Perl is the shit, but it isn't for everybody. Your rant is irrelavant on the grounds that if you don't like it you shouldn't use it. Perl obviously works well and has a place in the hearts of many people (of the computer sub-culture).
 
Old 07-27-2003, 06:41 PM   #13
Strike
Member
 
Registered: Jun 2001
Location: Houston, TX, USA
Distribution: Debian
Posts: 569

Original Poster
Rep: Reputation: 31
Quote:
Originally posted by lackluster
yes .... incorporating indentation into a language is a great thing
What's wrong with it?

Quote:
personally, I LOVE perl. it's quick, easy and has a module for just about everything.
I don't dispute any of these, but that doesn't make it better than any other quick and easy language with modules for just about everything

Quote:
I guess at first it was a little strange seeing all those weird symbols all over the place, but it wasn't long before I learned them and their meanings (took much longer in C).
Again, why have to learn all these stupid counterintuitive symbols in the first place? They aren't required to make a good language.

Quote:
I will admit that for BIG projects I wouldn't use perl. But I certainly wouldn't use python or ruby either. I'd probably use C or C++.
Why wouldn't you use python? (I wouldn't use ruby either just because it has nothing on Python) Using C and/or C++ is also rarely a "best" choice for projects, in my opinion.

Quote:
Perl is the shit, but it isn't for everybody. Your rant is irrelavant on the grounds that if you don't like it you shouldn't use it.
But my rant isn't so much about the fact that I don't like it as it is WHY it is a crappy language in general. And the fact that it is a crappy language is why I don't like it.

Quote:
Perl obviously works well and has a place in the hearts of many people (of the computer sub-culture).
It doesn't obviously work well. It obviously works well ENOUGH for many, but that doesn't mean that there aren't alternatives that would do just as well and/or better without being a crappy language at the same time.
 
Old 07-27-2003, 07:00 PM   #14
epicurus
LQ Newbie
 
Registered: Jul 2003
Posts: 16

Rep: Reputation: 0
Quote:
Originally posted by lackluster

Your rant is irrelavant on the grounds that if you don't like it you shouldn't use it.
Uh.. what does that even mean? He's explaining exactly why he doesn't use it. So anyone who doesn't like something should not bother explaining why they don't like it? Should we not give explanations or reasons for our feelings?

I use to like perl. I still do. I like all programming languages; they've all got neat naunces which give them unique character. I don't code in perl anymore, and I don't much enjoy looking at other people's perl code, but I still like it.
 
Old 07-27-2003, 07:39 PM   #15
coolman0stress
Member
 
Registered: Jun 2003
Location: Toronto, Ontario, Canada
Posts: 288

Rep: Reputation: 30
Quote:
I use to like perl. I still do. I like all programming languages; they've all got neat naunces which give them unique character. I don't code in perl anymore, and I don't much enjoy looking at other people's perl code, but I still like it.
That's a great observation.
What makes a programmer even more great is knowing these little nuances and picking the right language for the right job.

So Strike tell me, how does Python improve on some of the things you've mentioned are bad about Perl? I've briefly checked out Python and hope to learn more about it once i have some spare time (to many projects at the time). Specifically why is it that everyone praises it as a great prototyping tool? How is the object oriented side?

Thanks in advance
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
My rant Joey.Dale General 10 09-28-2004 07:22 PM
Just a rant! cereal83 General 21 07-17-2004 11:19 PM
rant, rant, rant (dselect) fenderman11111 Debian 2 07-06-2004 06:03 PM
rant emetib General 4 04-16-2004 09:38 PM
perl(Cwd) perl(File::Basename) perl(File::Copy) perl(strict)....What are those? Baldorg Linux - Software 1 11-09-2003 08:09 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

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

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration