in reply to Arguments needed for comparision between Perl, ASP and Java
Turn the question back around and ask them the same thing.
And here are some advantages Perl has over ASP and Java (to throw at them while they're still trying to come up with some good reasons for their preferred languages):
- Built-in text processing facilities - regexen, split, etc.
- CPAN - there's probably a module on CPAN that will do what you need, and will do it a lot more reliably since most CPAN modules are subjected to more testing than a handrolled module.
- Communities like PerlMonks
- And most importantly, a saner syntax. For example, let's open a file in Perl and write to it:
open my $fh, ">FILENAME" or die "Can't write FILENAME: $!";
print $fh "We are writing a line of text to a file.\nSecond line";
close $fh;
In ASP:
<%
Dim objFSO, objTextStream, file
file = Server.MapPath("samplefile.txt")
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
Set objTextStream = objFSO.OpenTextFile(file , 2, True)
objTextStream.WriteLine "We are writing a line of text to our text fil
+e" &
VBCfLf & "This is our second line of text" & VBCrLf
objTextStream.Close
Set objTextStream = Nothing
Set objFSO = Nothing
%>
Or Java:
try {
BufferedWriter out = new BufferedWriter(new FileWriter("outfil
+ename"));
out.write("We are writing a line of text to our text file\nThi
+s is our second line of text");
out.close();
} catch (IOException e) {
}
I know which one I'd rather write. The Java example isn't as ludicrously verbose as the ASP sample, but I still find Perl's syntax much more straightforward.
- Perl's interpreter is extremely fast. If you run Perl with mod_perl or ISAPI, you'll get excellent performance. I would suspect this is faster than ASP and strongly suspect that this is faster than Java, but I have no numbers to prove this.
Are you sure it was a book? Are you sure it wasn't.....nothing?
Re: Re: Arguments needed for comparision between Perl, ASP and Java
by Ovid (Cardinal) on Nov 10, 2003 at 16:41 UTC
|
Those are perfect examples of the difference in philosophy between Perl and many other languages. Common things should be as simple as possible. I've always had fun with those whose Java is a little shaky by asking them them to write the code for opening and writing to a file without looking up the syntax. It's surprising how many people blow it.
Now how many people have the same problem in Perl?
| [reply] |
|
| [reply] |
Re: Re: Arguments needed for comparision between Perl, ASP and Java
by Grygonos (Chaplain) on Nov 10, 2003 at 15:26 UTC
|
in all fairness to ASP. you could have written it shorter and you wrote some things in the ASP one that weren't in the perl one.
<%
Dim objFSO, objTextStream, file
file = Server.MapPath("samplefile.txt")
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
Set objTextStream = objFSO.OpenTextFile(file , 2, True)
#If I'm not mistaken you can bump these two writes into one.
objTextStream.WriteLine "We are writing a line of text to our text fil
+e"
objTextStream.Write "This is our second line of text" & VBCrLf
#You didn't echo in the perl example
Response.Write "we have written to our text file"
objTextStream.Close
#Are these neccesary ?
Set objTextStream = Nothing
Set objFSO = Nothing
%>
I myself don't do much ASP or know enough about it to call it "superior" to anything, but let's be fair in our comparison. | [reply] [d/l] |
|
| [reply] |
|
so then the = nothing calls are neccesary to properly close that handle? Way OT, but I'm just making sure I understand why you said they were needed.
| [reply] [d/l] |
Re: Re: Arguments needed for comparision between Perl, ASP and Java
by tilly (Archbishop) on Nov 11, 2003 at 15:38 UTC
|
I prefer advocacy that doesn't provide bad examples of how to do it.
Please add the standard or die "Can't write FILENAME: $!" to your open for the exact reasons that are discussed in perlstyle. | [reply] [d/l] |
|
| [reply] |
|
Yes, but then you are providing error checking. Does the asp example provide error checking? Doesn't look that way to me, thus for a fair comparison you should omit the or die "blah". The point is to compare code with the same function, ya?
| [reply] [d/l] |
|
The point is to compare code with the same function, ya?
My point is that the code should be code that you might wnat to write. I don't know ASP well enough to know whether it provides error checking. The Java example does not, in fact it goes out of the way to fight the language and ensure that it does not! I'll give a Ruby example shortly with error checking that illustrates why I don't know about the ASP example even though no error checking is shown.
Some links on Java's checked exceptions first. James Gosling on why Java has checked exceptions. (I love his quote about, "In Java you can't escape the creepy feeling.") Bruce Eckel on why checked exceptions are bad. And the discussion that I am pulling these links from. In the code example, of course, the exceptions were swallowed, illustrating exactly the issue with checked exceptions.
The long and short of it is that most programmers sadly do not care about doing things right. If you care, then Java makes it easy to make sure that you captured every last case. But most don't, and immediately sabatoge the system. Perl makes it possible to do things right with less work, but the default behaviour does not do things right. Ruby and Python, by contrast, tend to do the right thing without programmers having to care. Here is the above example in Ruby to demonstrate what I mean:
# Method one, passing in a block
File.open(filename, "w") { |aFile|
aFile.print("We are writing a line of text to a file.\nSecond line")
+;
}
# Method two, handling everything yourself
aFile = File.open(filename, "w");
aFile.print("We are writing a line of text to a file.\nSecond line");
aFile.close;
Believe it or not, this example includes all the error checking that you might ever want! It properly will catch cases where you can't open the file, opened it but can't write to it (perhaps you forgot to specify that it was opened for writing), or tried to close it and caught an error there (perhaps the disk is full). Very few programmers will go out of their way to do error checking that carefully. In Ruby you have to go out of your way to avoid error checking!
I don't know where ASP stands on that spectrum since I don't use it. I don't know where Perl 6 will stand either, but I hope that it moves closer to the above Ruby example.
But, I can see you ask, what if I don't care? My answer is that programmers who don't care are hazards to any code-base they are allowed to pollute. If they don't currently care, explain patiently why it is important, and come back to show where it would have saved them work to have cared up front, until they (hopefully) learn better.
So even though adding error checking to one but not the rest may make the comparison unfair, examples without error checking are still bad examples, and I don't like seeing them propagated as illustrations of what code should look like. So add it to the rest as well, since that is what a good programmer will likely want the code to do. | [reply] [d/l] |
|
|
|