Allegro.cc - Online Community

Allegro.cc Forums » Off-Topic Ordeals » Comparison of Interpreted Languages

This thread is locked; no one can reply to it. rss feed Print
Comparison of Interpreted Languages
Myrdos
Member #1,772
December 2001

I'd like to learn an interpreted language, and am trying to decide which one I should focus on. Right now I'm looking at Ruby, Python, Perl and PHP. I have a few questions for anyone who has experience with these:

-I understand you can use Python together with C/C++? Can you integrate C/C++ with the others?

-Is there anywhere I can find statistics on the popularity of these languages?

-Is PHP useful other than for writing server-side programs?

My needs: I want to experiment with dynamic web content, say by having the user enter data and then I'll run a server-side program to produce the results.

-I want to be able to rapidly produce small programs in a Linux/Unix environment, that can communicate over a network, and call upon command-line tools. If I could integrate C++ into them, bonus! If they have GUI abilities, that would also be nice.

I've been Googling for a while, trying to get a feel for the language's differences, but I still understand them only in a very general sense. Any advice is welcome!

__________________________________________________

Matthew Leverton
Supreme Loser
January 1999
avatar

All of them can interface with C. Of the four you mentioned, Ruby and Python are similar, as are PHP and Perl.

Perl was designed for writing command line scripts, but it can do more. PHP was designed for writing dynamic web sites, but it can do more.

Python and Ruby are designed to be more elegant, general purpose languages, but neither are used as much as PHP or Perl. (That tells you something about programmers...)

Perl and PHP battle each other for the ugliest syntax award. Perl wins the cryptic contest, while PHP boasts the most bloated, random namespace. Python tries to annoy by treating whitespace like it means something. Ruby is slow and requires a masters in Japanese to read the documentation.

If I were to learn a language (of the four) just for the sake of it, I'd pick Ruby. If I were to learn a language specifically to write websites, I'd pick PHP.

Perl and PHP will basically feel like C with free memory management, basic OOP, and flexible variables. Python and Ruby will probably feel more like different languages.

ReyBrujo
Moderator
January 2001
avatar

I would think Python is more important nowadays than Ruby (the Ruby on Rails bubble kind of disappeared lately). Perl must be the easiest to understand: if you know C and regular expressions, you should be able to write Perl scripts in no time. Packages are used much like Java ones.

Python... well, having to count white spaces (a line beginning with three spaces compiles, a line with four spaces doesn't... etc) is awful and may upset you quickly. As Matthew said, PHP is much better for WWW development, and the syntax is pretty similar to Perl.

I have tried to learn Ruby, it has a pretty and clear syntax. It seems the most professional, although not the most widely used (and thus useful).

--
RB
光子「あたしただ…奪う側に回ろうと思っただけよ」
Mitsuko's last words, Battle Royale

Marcello
Member #1,860
January 2002
avatar

Quote:

It seems the most professional, ...

Isn't marketing amazing? ;)

Marcello

Matthew Leverton
Supreme Loser
January 1999
avatar

Quote:

I would think Python is more important nowadays than Ruby

I don't know Python at all, other than the whitespace issue. ;) That's enough to keep me away.

I really like what you can do with Ruby, especially how everything is open. In fact, Ruby is what I think JavaScript would evolve to if it weren't held back by web browsers. You can actually imitate basic Ruby principles quite well in JavaScript. Here's one example:

Array.prototype.each = function(foo)
{
  for (var i = 0; i<this.length; ++i) foo(this<i>);
}

["Hello", "World"].each(function(bar) { alert(bar)});

That's the same as this in Ruby:

["Hello", "World"].each{ |bar| alert(bar) }

The difference with Ruby is it handles it natively, and thus more gracefully. I'm not sure about Perl, but doing stuff like that in PHP is next to impossible. PHP5 is much better than PHP4, as you can do things like:

class Whatever implements ArrayAccess
{
  public function offsetExists($key) { }
  public function offsetGet($key) { }
  public function offsetSet($key, $val) { }
  public function offsetUnset($key) { }
}

But that is so much more verbose than Ruby:

class Whatever
  def [] (key)
  end
  def []= (key, val)
  end
end

Marcello
Member #1,860
January 2002
avatar

Matthew Leverton
Supreme Loser
January 1999
avatar

I was just pointing out that JavaScript is relatively flexible and powerful considering its simplicity. Yes, the language continues to mature, but it will always be held back by the limitations of browsers.

Evert
Member #794
November 2000
avatar

I'd recommend Perl if you intend to stick to one language. Get the O'Reilly Llama book.
That said, it depends on what you want to do with it: the PHP I learned I learned by customising a PHP script. I learned Perl for two reasons: we have a postdoc here who is very enthusiastic about Perl, and I had a lot of shell scripts for processing output using sed and awk. While those worked and I still use shell scripts, awk and sed, Perl combines all of that functionality in one package.
I learned a bit of Python... it's a nice language in principle, but significant whitespace is really annoying. It didn't actually bother me until I tried using Python seriously and found myself fighting with the indentation whenever I copied a piece of code.
I haven't done much with Ruby, but I've heard good things about it (as a language).
You may want to consider that Perl, Ruby and Python are general-purpose languages, while PHP isn't really.

Finally, I was at a workshop the other day where I heard a talk by a computer scientist advising us on what language would be suitable as a glue language between different larger software packages (some written in C, others in C++, others in FORTRAN). Naturally, given the context, PHP didn't get mentioned at all. Perl was discussed and had a lot of things going for it. The speaker's main reason for not recommending it is `rich syntax' which he apparently didn't like. His personal recommendation was Python ahead of Ruby, mainly because Python has a larger userbase than Ruby.

Oh, another great thing about Perl: you can write very C-like Perl code, which is great if you have a chunk of C code and would like to port it to Perl. I dd that the other day and it was basically as easy as cut&paste, then putting a $ in front of all the variable names. Quite good. :)

Carrus85
Member #2,633
August 2002
avatar

Personally, I would prefer C++/Java in most cases, python when a "quick and dirty" solution would work fine (just because in a few lines you can write relatively complex programs). The whitespace significance issue is annoying (and isn't quite as bad if you use proper tabs instead of spaces so you don't get someone running 2 spaced tabs, and someone else running 4, and another running 3, finding yourself having to run some script to readjust the tabbing to be consistent.)

Sans the weird whitespace issue, it does have some very interesting language features integrated that a lot don't natively support (for example, inline documentation of code that is accessable at runtime (unlike javadoc that has it's documentation as comments within the file)).

As for the execution speed of python, it is quite slow unless you force the majority of your code onto either the internal C api or an external C module you created. Of course, there are enough functions in python that it should be realitively easy to push the vast quantity of the code into the C portion of the API.

amarillion
Member #940
January 2001
avatar

Of the 4 choices, Perl, Python, Php and Ruby, I only know Perl really well so I can't make a balanced judgement, and I won't.

What I can tell you however, is that I've noticed a lot of people bash Perl for the wrong reasons. Perl has an ugly syntax, true. All that means is that it will be a bit harder to learn. But what a lot of people claim, and what is definitely not true, is that Perl makes you write unstructured, unmaintainable code. I'm maintaining a number of large Perl projects and I don't find them any harder to maintain than any of my C++ or java projects.

Perl gives you many ways to shoot yourself in the foot if you like (e.g. you can set all arrays to start at 43 i.o 0), but that is easy to avoid. You just have to be a disciplined coder and you have to know the language well. Always turn on warnings, always use strict mode, always be consistent in your coding style.

And there are some advantages to Perl: it has the longest history, the best open source code repository (CPAN), the best books and tutorials (I recommend "Learning Perl" and "Perl Objects, References & Modules", from O'reilly).

--
Martijn van Iersel | My Blog | Sin & Cos | Tegel tilemap editor | TINS 2017

deps
Member #3,858
September 2003
avatar

On the topic of Ruby, this is the most bizarre and wonderful tutorial I have ever read. http://poignantguide.net/ruby/

---
Layers are good, all good things have layers, like onions. Good things also stink. - Trezker
I now have a page and a blog!

nonnus29
Member #2,606
August 2002
avatar

Quote:

I'd like to learn an interpreted language

That's an odd criteria. It's like saying 'I want to date a girl who likes reality tv'; it's completely arbitrary and not relavent to anything. Besides, all t hose languages suck, make your own :P

CGamesPlay
Member #2,559
July 2002
avatar

On my system, I have a lot of things scripted. Here is a break-down of them with language notes:

  • This script downloads a file, converts it to MP3, and repeats until it has acquired 32MB. This was written in php and makes system calls to wget, unzip, and lame. If I were to rewrite this script today I would almost certainly do it in ruby.

  • This script fetches a file and runs a media player on it, and downloads another in the background (ad infinitum). This was written in bash and makes system calls to wget, unzip, and the media player. It uses job control rather heavily. If I were to rewrite this script today I would almost certainly do it in ruby.

  • This script downloads files from another computer via samba, and saves them locally. This was written in bash and makes system calls to smbmount. This script is so mundane and uses entirely system commands. If I were to rewrite this script today I would almost certainly use bash.

  • This script parses all of my Gaim log files and makes an SQL file detailing them all. This was written in ruby and makes a system call only to the above script (to download log files from my laptop). If I were to rewrite this script today I would almost certainly use ruby.

  • This script handles the above mentioned SQL file to present the data in a friendly format. This was written in php, using only php libraries. If I were to rewrite this script today I would almost certainly use php.

  • This script is an IRC bot that handles a few miscellaneous tasks. This was written in ruby, and uses ruby libraries to handle dynamic loading of other ruby scripts as plugins. If I were to rewrite this script today I would almost certainly use ruby.

So that should give you a general idea of why I chose various languages for various tasks... If you're wondering about a language I didn't prefer, keep in mind that I am only familiar with ruby, php, bash, and compiled languages.

--
Tomasu: Every time you read this: hugging!

Ryan Patterson - <http://cgamesplay.com/>

ReyBrujo
Moderator
January 2001
avatar

Most of my scripts are written with Bash (like one that converts videos to 3gp to watch in a mobile phone). I only use scripting (Perl) when I need to process a lot of text files.

--
RB
光子「あたしただ…奪う側に回ろうと思っただけよ」
Mitsuko's last words, Battle Royale

Myrdos
Member #1,772
December 2001

Thanks for all the replies! It now seems clear that Perl is the correct choice for me. I was originally leaning towards Python because I started drooling on the keyboard when I heard you could interface with C++. I don't know much about the capabilities/limitations of these languages, but if I can access the vast repository of C/C++ libraries, then realistically there are none. But I suspect this business with the whitespace would drive me bananas.

Right now I have a nebulous view of Perl being like a magic glue, allowing you to access all sorts of tools and combine them together. Sounds very high-level, very powerful.

About PHP being better than Perl at building websites: is it a question of being able to do the same thing in less time, or are there features in PHP that aren't present in Perl? Maybe I'll look into PHP after I've gained some confidence in Perl.

Quote:

That's an odd criteria.

It seems reasonable to me. I mean that it should be high-level, enable rapid development, be cross-platform, and work well at interfacing with networks / other technologies. Or were you trolling? ???

__________________________________________________

CGamesPlay
Member #2,559
July 2002
avatar

Why didn't you mention ruby at all? :'(

--
Tomasu: Every time you read this: hugging!

Ryan Patterson - <http://cgamesplay.com/>

Myrdos
Member #1,772
December 2001

Heh. I took too long to post, (ate breakfast in the middle) and missed yours. However, your post (and others that mentioned Ruby) inspired me to do some last-minute research before I set off on my New Language Adventure. So I was reading through the Poignant Guide when I came back to see what responses I got.

But my main concern is that it seems to be the least popular language.

As I see it, the more people who use a language, the more stuff gets built around it. If there were no third-party libraries for C++, it would be pretty darn useless to me. I don't want to get stuck in an obscure language, no matter how elegant, that is less supported or has less active development. Is this a valid concern?

__________________________________________________

CGamesPlay
Member #2,559
July 2002
avatar

Check out ruby gems. There are many libraries. The standard library comes with everything you will ever need for general applications. I mean, it has several XML parsing libraries, a web server, and tons of other things. Then add gems to the mix, which is like CPAN, but for ruby.

--
Tomasu: Every time you read this: hugging!

Ryan Patterson - <http://cgamesplay.com/>

Thomas Fjellstrom
Member #476
June 2000
avatar

Matthew's example in Perl (6 times):

for my $var ("Hello", "World") { alert($var); } # var is local to the for
for $var ("Hello", "World") { alert($var); } # var is "global"
for ("Hello", "World") { alert($_); }
alert($_) for ("Hello", "World");

# if alert() handles $_ as the "default argument", as perl's api does, the following also work:
# with or without the ()s on alert()
for ("Hello", "World") { alert; }
alert for ("Hello", "World");

Quote:

Right now I have a nebulous view of Perl being like a magic glue, allowing you to access all sorts of tools and combine them together. Sounds very high-level, very powerful.

It can be, and it can also be a big mess of spaghetti. like all languages.

--
Thomas Fjellstrom - [website] - [email] - [Allegro Wiki] - [Allegro TODO]
"If you can't think of a better solution, don't try to make a better solution." -- weapon_S
"The less evidence we have for what we believe is certain, the more violently we defend beliefs against those who don't agree" -- https://twitter.com/neiltyson/status/592870205409353730

Go to: