Do you find perl code "messy" ?

drag

Elite Member
Jul 4, 2002
8,708
0
0
No, I find perl programmers messy.

You can make it anyway you want. Perl is all about freedom (as a scripting language), sometimes it's easier for people to make messy code, so they do.

They don't have to. I bet you can find very clean looking programs out there.

(I like Python myself)
 

notfred

Lifer
Feb 12, 2001
38,241
4
0
Java is inherently very neat looking. It's also extremely verbose. It takes 5 times as many characters to do a lot of simple things in java as it does in perl. Perl can be neat, or it can be messy. Here's an example that I wrote, which I don't find particularly messy. This parses CSV files:
 

Alternex

Senior member
Oct 9, 1999
531
0
0
whoa.. never seen that embedded code thing in this forum before!
I find more verbose languages (such as java and c#) a lot nicer. A little extra typing goes a long ways towards readability.

If you choose a compact language such as perl, then projects become unreadable. Sure everyone says their code is clean but tell that to the maintanence guys (or yourself when you're working on someone else's code)
 

notfred

Lifer
Feb 12, 2001
38,241
4
0
Originally posted by: Alternex
whoa.. never seen that embedded code thing in this forum before!
I find more verbose languages (such as java and c#) a lot nicer. A little extra typing goes a long ways towards readability.

If you choose a compact language such as perl, then projects become unreadable. Sure everyone says their code is clean but tell that to the maintanence guys (or yourself when you're working on someone else's code)

So are you saying the code I posted is unreadable?
 

MrChad

Lifer
Aug 22, 2001
13,507
3
81
Originally posted by: notfred
So are you saying the code I posted is unreadable?

It's not unreadable, but for someone who's not familiar with Perl syntax, it doesn't make a lot of sense. I have no idea what these four lines mean:

# Set up all the initial vars.
my $csvdata = shift @_;
my @alldata = ();
my @thisline = ();
my $thisfield = '';
 

WannaFly

Platinum Member
Jan 14, 2003
2,811
1
0
Originally posted by: MrChad
Originally posted by: notfred
So are you saying the code I posted is unreadable?

It's not unreadable, but for someone who's not familiar with Perl syntax, it doesn't make a lot of sense. I have no idea what these four lines mean:

# Set up all the initial vars.
my $csvdata = shift @_;
my @alldata = ();
my @thisline = ();
my $thisfield = '';

Well this makes me wonder if you know any programming at all, thats pretty standard usage right there.
 

AFB

Lifer
Jan 10, 2004
10,718
3
0
Originally posted by: MrChad
Originally posted by: notfred
So are you saying the code I posted is unreadable?

It's not unreadable, but for someone who's not familiar with Perl syntax, it doesn't make a lot of sense. I have no idea what these four lines mean:

# Set up all the initial vars.
my $csvdata = shift @_;
my @alldata = ();
my @thisline = ();
my $thisfield = '';

But you wouldn't be working on perl then ;):)
 

MrChad

Lifer
Aug 22, 2001
13,507
3
81
Originally posted by: amdfanboy
Originally posted by: MrChad
Originally posted by: notfred
So are you saying the code I posted is unreadable?

It's not unreadable, but for someone who's not familiar with Perl syntax, it doesn't make a lot of sense. I have no idea what these four lines mean:

# Set up all the initial vars.
my $csvdata = shift @_;
my @alldata = ();
my @thisline = ();
my $thisfield = '';

But you wouldn't be working on perl then ;):)

Right, but my point is that I can read Java or C# without knowing the language and still figure out what's going on.

Nevertheless, notfred's example represents some pretty well documented and formatted code, regardless of the language. :)
 

notfred

Lifer
Feb 12, 2001
38,241
4
0
Originally posted by: MrChad
Originally posted by: notfred
So are you saying the code I posted is unreadable?

It's not unreadable, but for someone who's not familiar with Perl syntax, it doesn't make a lot of sense. I have no idea what these four lines mean:

# Set up all the initial vars.
my $csvdata = shift @_;
my @alldata = ();
my @thisline = ();
my $thisfield = '';

Of course you don't if you don't know perl. They're extremely fundamental to the langauge though.

In java, that would look something like:

String csvdata = somearray[0];
Object [] alldata = new Object[];
String [] thisline = new String [];
String thisfield = new String();

If you show someone who's never looked at C before a file full of * and & they're not going to know what the hell they do either.
 

Alternex

Senior member
Oct 9, 1999
531
0
0
Originally posted by: notfred
Originally posted by: Alternex
whoa.. never seen that embedded code thing in this forum before!
I find more verbose languages (such as java and c#) a lot nicer. A little extra typing goes a long ways towards readability.

If you choose a compact language such as perl, then projects become unreadable. Sure everyone says their code is clean but tell that to the maintanence guys (or yourself when you're working on someone else's code)

So are you saying the code I posted is unreadable?

No.. but you did get to pick the code snippet to show yourself. Generally speaking most code is badly documented. If you didn't have those comments there I'd have no clue whatsover the code did.. if it was in java/c# it should be somewhat easier (given that the developer is the same)
 

Alternex

Senior member
Oct 9, 1999
531
0
0
Originally posted by: notfred
Originally posted by: MrChad
Originally posted by: notfred
So are you saying the code I posted is unreadable?

It's not unreadable, but for someone who's not familiar with Perl syntax, it doesn't make a lot of sense. I have no idea what these four lines mean:

# Set up all the initial vars.
my $csvdata = shift @_;
my @alldata = ();
my @thisline = ();
my $thisfield = '';

Of course you don't if you don't know perl. They're extremely fundamental to the langauge though.

In java, that would look something like:

String csvdata = somearray[0];
Object [] alldata = new Object[];
String [] thisline = new String [];
String thisfield = new String();

If you show someone who's never looked at C before a file full of * and & they're not going to know what the hell they do either.


who said C was readable? :p
Solving the 8 queens problem in one line of C code is an eye sore
 

notfred

Lifer
Feb 12, 2001
38,241
4
0
Originally posted by: Alternex
Originally posted by: notfred
Originally posted by: Alternex
whoa.. never seen that embedded code thing in this forum before!
I find more verbose languages (such as java and c#) a lot nicer. A little extra typing goes a long ways towards readability.

If you choose a compact language such as perl, then projects become unreadable. Sure everyone says their code is clean but tell that to the maintanence guys (or yourself when you're working on someone else's code)

So are you saying the code I posted is unreadable?

No.. but you did get to pick the code snippet to show yourself. Generally speaking most code is badly documented. If you didn't have those comments there I'd have no clue whatsover the code did.. if it was in java/c# it should be somewhat easier (given that the developer is the same)

Yes, I did pick the code sample myself, but the point is that it's not an inherent property of the language that it's difficult to read. The reason you'd be more familiar with java or C# is because you're familiar with those languages, which look nearly identical. If you had been programming perl up until now and hadn't looked at java or C#, you'd think java looked just as weird. Just because the syntax is different doesn't make the language less readable. Japanese probably confuses the hell out of you, but that doesn't mean it's a less readable language than English.
 

Barnaby W. Füi

Elite Member
Aug 14, 2001
12,343
0
0
yeah; perl is messy, java is verbose. Of course anything is more readable once you know it, but there's something to be said for simplicity. Well-designed simplicity doesn't require hacks to expand its usefulness. Perl's syntax is the total inverse of that. IMO, of course.
 

skace

Lifer
Jan 23, 2001
14,488
7
81
perl regex is messy but also EXTREMELY functional. People looking at it for the first time won't understand it. But once they realize that perl is practically parsing stuff 24/7 with regex, it all adds up. Java may look pretty, but... I still don't like it.
 

Armitage

Banned
Feb 23, 2001
8,086
0
0
Whether a particular language is "messy" or not is up to the programmer. That said, the syntax of certain languages tends to encourage messy code. Perl is certainly an example of this.
 

notfred

Lifer
Feb 12, 2001
38,241
4
0
Originally posted by: skace
perl regex is messy but also EXTREMELY functional. People looking at it for the first time won't understand it. But once they realize that perl is practically parsing stuff 24/7 with regex, it all adds up. Java may look pretty, but... I still don't like it.

regular expressions look messy in any language.
 

Perl programmers tend to beat the crap out of regex, causing messy code everywhere. Any language can make messy code, even Java. It really depends on the programmer.
 

Alternex

Senior member
Oct 9, 1999
531
0
0
What I'm saying is that if you take a programmer equally skilled in Perl and Java and have them read their own code a year after they write it, they would probably have an easier time reading their own Java code than their Perl code because Perl is more condensed.
 

notfred

Lifer
Feb 12, 2001
38,241
4
0
Originally posted by: Alternex
What I'm saying is that if you take a programmer equally skilled in Perl and Java and have them read their own code a year after they write it, they would probably have an easier time reading their own Java code than their Perl code because Perl is more condensed.

Depends on how well they write thier code. The code I posted above will still make perfect sense a year from now.
 

skace

Lifer
Jan 23, 2001
14,488
7
81
A proficient Perl programmer is going to use regex as efficiently as possible. The cool thing about Perl is you could write something in 20 lines, someone else would do it in 5, and then yet another person might do it in 1 line.

The Perl programmer that truely understands what he is writing, won't have any problem 1 year later reading his code. It is just the regex that looks confusing to an outsider who doesn't understand said code.

Edit: And yes I realize in other languages you can write something in 20 lines that might end up taking 5. But only to a certain degree, where as I believe Perl takes it to the extreme with versatility.
 

PricklyPete

Lifer
Sep 17, 2002
14,582
162
106
Originally posted by: notfred
Originally posted by: skace
perl regex is messy but also EXTREMELY functional. People looking at it for the first time won't understand it. But once they realize that perl is practically parsing stuff 24/7 with regex, it all adds up. Java may look pretty, but... I still don't like it.

regular expressions look messy in any language.

agreed. It seems that they could have come up with a more readable syntax for reg exp. Regardless, they are insanely useful.
 

Alternex

Senior member
Oct 9, 1999
531
0
0
Just wondering but how often do you guys use regular expressions? Is everyone doing data mining and/or maintaining old data?

Suppose in the future data gets stabilized and everything is in databases or XML - then there wouldn't be as much a focus on regular expressions.