|
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
|
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
|
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). -- |
Marcello
Member #1,860
January 2002
|
Quote: It seems the most professional, ... Isn't marketing amazing? Marcello |
Matthew Leverton
Supreme Loser
January 1999
|
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: But that is so much more verbose than Ruby:
|
Marcello
Member #1,860
January 2002
|
Matthew Leverton
Supreme Loser
January 1999
|
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
|
I'd recommend Perl if you intend to stick to one language. Get the O'Reilly Llama book. 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
|
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
|
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). -- |
deps
Member #3,858
September 2003
|
On the topic of Ruby, this is the most bizarre and wonderful tutorial I have ever read. http://poignantguide.net/ruby/ |
nonnus29
Member #2,606
August 2002
|
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 |
CGamesPlay
Member #2,559
July 2002
|
On my system, I have a lot of things scripted. Here is a break-down of them with language notes:
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. -- Ryan Patterson - <http://cgamesplay.com/> |
ReyBrujo
Moderator
January 2001
|
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. -- |
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
|
Why didn't you mention ruby at all? -- 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
|
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. -- Ryan Patterson - <http://cgamesplay.com/> |
Thomas Fjellstrom
Member #476
June 2000
|
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. -- |
|