The Battle of the Scripts
[ rakaur on Fri Sep 17 at 11:00 PM // category: programming, technology ]
Oh right, I have a Webpage.
I’ve been pretty “busy” the last few days between school and infatuation and reading up on some scripting languages. This is going to be a pretty long post… and may turn into a rant if it keeps going the way it is.
Here’s a note before I get started: I use the term “scripting” in reference to any language which is either interpreted or compiled into bytecode and interpreted. I use the term “coding” or “programming” to refer to any language which is compiled into native code and executed directly. Please spare me the “but you can compile Python scripts into executables by linking them with the Python libraries!” because that’s clearly not what I mean. Pedantry city is thataway.
I program as a hobby. It’s interesting, but I don’t think I could stand to do it for a living. One reason being that I randomly stop “feeling like it” and just don’t code for a really long time. That’s usually not so good for the monies.
The first “language” I ever had experience with was mIRCScript. mIRC is an IRC client, as you might have guessed. Its language is pretty defunct and mentally retarded to the point that you’d sometimes rather gouge your eyes out with straws than attempt to accomplish anything in. But, I must admit, it was a useful introduction to programming.
After that, I moved on to PHP. I believe that PHP was in the PHP3 days when I was first introduced to it. As with mIRCScript, I pretty much taught myself and learned as I went. PHP is pretty damned intuitive and you can usually just “figure it out.” Some time later, I actually bought a few PHP4 books and learned it the “correct” way. PHP serves its purpose as a Web development language very aptly. PHP elitists: I am very much aware that PHP can be used to do many things that have nothing to do with Web development. In fact, I saw a project a few months ago where someone had written not only a PHP HTTP server, but a TCP/IP stack to be used with the server. This is pretty astounding. But, for the sake of my sanity and this discussion, I’m going to go ahead and limit PHP’s usefulness to Web development. That’s what it was written for; that’s what it excels in. I don’t want to hear all of your PHP success stories on how you wrote an operating system using only the PHP interpreter. You can all rest assured that:
- I’ve heard it before, and;
- I didn’t care the first time.
After that, I moved on to C. I’ve done all of my “serious” programs in C. So, my history is pretty much one useless scripting language, one mostly-useless scripting language, and one old school programming language.
Now, jump from that to diving into Python and Ruby. Naturally, I was astounded at how simple in made things. Think of going from a few thousand lines of code to write a socket library in C, to three lines of importing modules in Python or Ruby. Yeah.
Perl
I’m going to mention this one first just to get it out of the way. I know about Perl, and I’ve tried very hard to forget about Perl. My friends, along with most of the Unix community, know and love Perl. I just don’t get it. I’ve tried to read books on it; I’ve tried to read references; I’ve tried to read tutorials; I’ve tried to read giant Websites that explain why Perl is so awesome and why it takes a steaming shit on every other scripting language ever, but; I just don’t get it. If you put aside that the language is absolutely deplorable in terms of aesthetics, well, I guess you have a useful language then, wouldn’t you?
I absolutely cannot stand neither Perl’s syntax nor the never ending philisophy of “there’s more than one way to do it, and every single one of them reminds you vaguely of that time you stepped in dog shit outside and then dog piss and then sixty billion cockroaches and wiped it off on your head.” Perl and Perl hackers are pretty much summed up by “you can do it sixty different ways… that is, so long as you never want to look back and your code and be able to know what the hell you just did. Isn’t that grand?!”
Spare me on the “Perl can be elgant if you want it to be,” because, in my opinion, it cannot. That’s it; case closed.
PHP
I’m going to go ahead and get this out of the way too. I find PHP infinitely useful for Web development. That’s what it was made for, and that’s what I use it for. PHP is simply not a plausible language to use for everyday things, in my opinion.
Notice how I keep stressing that? Everything that anyone ever says is quite obviously their opinion. Let’s make life easier and assume that from now on.
Ruby
I’m going to admit this straight off: I’ve read about two chapters worth of information on Ruby. I’m in the middle of reading another book at the moment, and I fully intend to pick up on Ruby after I’m finished with this one.
Over the past year or so I keep hearing about this infinitely wonderful new scripting language called Ruby. From what I can tell, it looks like Perl and Python had a catfight, and Ruby is the result. I’m not entirely sure if I like this language or not yet. It seems to lean more on the Perl side of things (variable prefixes, regular expression integration (id est =~ and /regex/), weird globals (eg: $_, et al), along with other things) than anything else. Since I can’t stand Perl, I’m not sure how well I’ll receive a language that so far acts a lot like it.
All in all, it looks to be an interesting read if nothing else.
Python
I’ll also come out and say that I haven’t finished reading up on this language completely. Most people don’t like Python for one of three reasons:
- They think it has strictly pedantic indentation rules;
- They think it’s inferrior to the god we know as Perl;
- They think the syntax is too weird.
I’m going to address those right here.
One: Python doesn’t have any indentation rules, per se. Python uses indentation to decide where code blocks start and end. Some languages (like C) use {braces} to determine this. Some languages (like Ruby) use keywords such as begin and end to determine this. Python uses indentation. The indentation can be one space or sixty spaces or one tab or sixty tabs; it doesn’t matter, so long as you’re consistant throughout the code block. Even this tiny rule may seem like it forces style upon you, which, in a way it does. It definitely leads to more readable code, id est, by everyone that reads it. Coming from a C programmer, you’ll not only get used to, but appreciate this. Trust me.
Two: It seems that Python is indeed slower with simple tasks, in terms of processing speed. However, Python tends to match if not excel Perl’s performance with larger, more complex operations. Also, Python doesn’t use nearly as much memory as Perl. I have no idea how the Perl interpreter works, but I do know that Python manages memory through both a reference-count garbage collector, and a mark-and-sweep garbage collector. Of course, this is simply memory management, not memory overhead. If you’re interested, Ruby outperforms Perl in speed in most cases. I’m not too sure about memory usage though.
Three: This is actually pretty valid. I’ll be the first to admit that Python’s syntax seems a little backwards. For example:
print [(k, v) for k, v in dict.items() if k == 'key']
This doesn’t really make much sense until you learn the Python syntax. I said earlier that it looks backwards, well, it is, a lot of times. This particular line of code would print a list of tuples of (key, value) for every entry in the dictionary “dict” if and only if the key is the string “key.” Yeah, that is pretty confusing. After you get used to the syntax you’ll find it’s pretty easy to slip into and start using.
So far, I’ve found Python to be very nice. If I have any serious scripting projects in the future, I’ll be using Python (unless of course I finish the Python book and read the Ruby book to find that I like it better ;).
On another note, I’m extremely tired. I started this post some time ago and I’m going to go ahead and post it like this until I have the stamina to write up a rant/article. Check back soon!
No one hears you.
-- rakaur // 2004.09.17 @ 11:00 PM
0 TrackBacks
Listed below are links to blogs that reference this entry.
TrackBack URL for this entry: http://mt.ericw.org/mt-tb.cgi/23
