As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 10 years ago.
Python and Ruby are usually considered to be close cousins (though with quite different historical baggage) with similar expressiveness and power. But some have argued that the immense success of the Rails framework really has a great deal to do with the language it is built on: Ruby itself. So why would Ruby be more suitable for such a framework than Python?
There are probably two major differences:
Ruby has elegant, anonymous closures.
Rails uses them to good effect. Here's an example:
class WeblogController < ActionController::Base
def index
#posts = Post.find :all
respond_to do |format|
format.html
format.xml { render :xml => #posts.to_xml }
format.rss { render :action => "feed.rxml" }
end
end
end
Anonymous closures/lambdas make it easier to emulate new language features that would take blocks. In Python, closures exist, but they must be named in order to be used. So instead of being able to use closures to emulate new language features, you're forced to be explicit about the fact that you're using a closure.
Ruby has cleaner, easier to use metaprogramming.
This is used extensively in Rails, primarily because of how easy it is to use. To be specific, in Ruby, you can execute arbitrary code in the context of the class. The following snippets are equivalent:
class Foo
def self.make_hello_method
class_eval do
def hello
puts "HELLO"
end
end
end
end
class Bar < Foo # snippet 1
make_hello_method
end
class Bar < Foo; end # snippet 2
Bar.make_hello_method
In both cases, you can then do:
Bar.new.hello
which will print "HELLO". The class_eval method also takes a String, so it's possible to create methods on the fly, as a class is being created, that have differing semantics based on the parameters that are passed in.
It is, in fact, possible to do this sort of metaprogramming in Python (and other languages, too), but Ruby has a leg up because metaprogramming isn't a special style of programming. It flows from the fact that in Ruby, everything is an object and all lines of code are directly executed. As a result, Classes are themselves objects, class bodies have a self pointing at the Class, and you can call methods on the class as you are creating one.
This is to large degree responsible for the degree of declarativeness possible in Rails, and the ease by which we are able to implement new declarative features that look like keywords or new block language features.
Those who have argued that
the immense success of the Rails
framework really has a great deal to
do with the language it is built on
are (IMO) mistaken. That success probably owes more to clever and sustained marketing than to any technical prowess. Django arguably does a better job in many areas (e.g. the built-in kick-ass admin) without the need for any features of Ruby. I'm not dissing Ruby at all, just standing up for Python!
The python community believes that doing things the most simple and straight forward way possible is the highest form of elegance. The ruby community believes doing things in clever ways that allow for cool code is the highest form of elegance.
Rails is all about if you follow certain conventions, loads of other things magically happen for you. That jives really well with the ruby way of looking at the world, but doesn't really follow the python way.
Is this debate a new "vim versus emacs" debate?
I am a Python/Django programmer and thus far I've never found a problem in that language/framework that would lead me to switch to Ruby/Rails.
I can imagine that it would be the same if I were experienced with Ruby/Rails.
Both have similar philosophy and do the job in a fast and elegant way. The better choice is what you already know.
Personally, I find ruby to be superior to python in many ways that comprise what I'd call 'consistent expressiveness'. For example, in ruby, join is a method on the array object which outputs a string, so you get something like this:
numlist = [1,2,3,4]
#=> [1, 2, 3, 4]
numlist.join(',')
#=> "1,2,3,4"
In python, join is a method on the string object but which throws an error if you pass it something other than a string as the thing to join, so the same construct is something like:
numlist = [1,2,3,4]
numlist
#=> [1, 2, 3, 4]
",".join([str(i) for i in numlist])
#=> '1,2,3,4'
There are a lot of these little kinds of differences that add up over time.
Also, I cannot think of a better way to introduce invisible logic errors than to make whitespace significant.
The real answer is neither Python or Ruby are better/worse candidates for a web framework. If you want objectivity you need to write some code in both and see which fits your personal preference best, including community.
Most people who argue for one or other have either never used the other language seriously or are 'voting' for their personal preference.
I would guess most people settle on which ever they come in to contact with first because it teaches them something new (MVC, testing, generators etc.) or does something better (plugins, templating etc). I used to develop with PHP and came in to contact with RubyOnRails. If I had have known about MVC before finding Rails I would more than likely never left PHP behind. But once I started using Ruby I enjoyed the syntax, features etc.
If I had have found Python and one of its MVC frameworks first I would more than likely be praising that language instead!
Python has a whole host of Rails-like frameworks. There are so many that a joke goes that during the typical talk at PyCon at least one web framework will see the light.
The argument that Rubys meta programming would make it better suited is IMO incorrect. You don't need metaprogramming for frameworks like this.
So I think we can conclude that Ruby are not better (and likely neither worse) than Python in this respect.
Because Rails is developed to take advantage of Rubys feature set.
A similarly gormless question would be "Why is Python more suitable for Django than Ruby is?".
I suppose we should not discuss the language features per se but rather the accents the respective communities make on the language features. For example, in Python, re-opening a class is perfectly possible but it is not common; in Ruby, however, re-opening a class is something of the daily practice. this allows for a quick and straightforward customization of the framework to the current requirement and renders Ruby more favorable for Rails-like frameworks than any other dynamic language.
Hence my answer: common use of re-opening classes.
Some have said that the type of metaprogramming required to make ActiveRecord (a key component of rails) possible is easier and more natural to do in ruby than in python - I do not know python yet;), so i cannot personally confirm this statement.
I have used rails briefly, and its use of catchalls/interceptors and dynamic evaluation/code injection does allow you to operate at a much higher level of abstraction than some of the other frameworks (before its time). I have little to no experience with Python's framework - but i've heard it's equally capable - and that the python community does a great job supporting and fostering pythonic endeavors.
I think that the syntax is cleaner and Ruby, for me at least, is just a lot more "enjoyable"- as subjective as that is!
Two answers :
a. Because rails was written for ruby.
b. For the same reason C more suitable for Linux than Ruby
All of this is TOTALLY "IMHO"
In Ruby there is ONE web-application framework, so it is the only framework that is advertised for that language.
Python has had several since inception, just to name a few: Zope, Twisted, Django, TurboGears (it itself a mix of other framework components), Pylons (a kinda-clone of the Rails framework), and so on. None of them are python-community-wide supported as "THE one to use" so all the "groundswell" is spread over several projects.
Rails has the community size solely, or at least in the vast majority, because of Rails.
Both Python and Ruby are perfectly capable of doing the job as a web applications framework. Use the one YOU (and your potential development team) like and can align on.
Related
This question already has answers here:
Closed 12 years ago.
Possible Duplicate:
What’s with the love of dynamic Languages
I'm coming from a c#/java background i.e. strongly typed, OOP language.
I'm very much interested in Python, but I need to learn a little more about the advantages of a dynamic language.
What power does it really give me? (in web applications).
Can someone outline some of the advantages and cool tricks I can do?
I don't think of dynamically typed languages as "allowing cool tricks" (they do, but mostly it's not really sound to use "cool" tricks in production software -- they come in handy for testing, debugging, etc, but when it comes to getting good, fast stuff deployed for production, simplicity rules).
Rather, I think of such languages as "not getting in my way" -- in particular, not slowing me down by forcing me to redundantly specify things over and over. Not every statically typed languages does "get in your way" -- good ones with solid, logically correct type systems like Haskell let the compiler deduce types (though you may redundantly specify them if you like redundancy... or, more to the point, if you want stricter constraints than what the compiler can actually deduce from the code). But in Java (and to a lesser extent in C# except when you use the reasonably recent var keyword) redundancy is the rule, and that impacts productivity.
A compromise can be offered by third-party checking systems for Python, like typecheck -- I don't use it, myself, but I can see how somebody who really thinks static type checking adds a lot of value might be happy with it. There's even a syntax (which the Python compiler accepts but does nothing with) in recent Python versions to let you annotate your function arguments and return values -- its purpose is to let such packages as typecheck be extended to merge more naturally with the language proper (though I don't think typecheck does yet).
Edit:
As I wrote here, and I quote:
I love the explanations of Van Roy and
Haridi, p. 104-106 of their book,
though I may or may not agree with
their conclusions (which are basically
that the intrinsic difference is tiny
-- they point to Oz and Alice as interoperable languages without and
with static typing, respectively), all
the points they make are good. Most
importantly, I believe, the way
dynamic typing allows real modularity
(harder with static typing, since type
discipline must be enforced across
module boundaries), and "exploratory
computing in a computation model that
integrates several programming
paradigms".
"Dynamic typing is recommended", they
conclude, "when programs must be as
flexible as possible". I recommend
reading the Agile Manifesto to
understand why maximal flexibility is
crucial in most real-world application
programming -- and therefore why, in
said real world rather than in the
more academic circles Dr. Van Roy and
Dr. Hadidi move in, dynamic typing is
generally preferable, and not such a
tiny issue as they make the difference
to be. Still, they at least show more
awareness of the issues, in devoting 3
excellent pages of discussion about
it, pros and cons, than almost any
other book I've seen -- most books
have clearly delineated and preformed
precedence one way or the other, so
the discussion is rarely as balanced
as that;).
I enjoyed reading this comparison between Python and Java.
In relation with web, I would recommend doing a simple example with Django to see how it works.
Python (like all dynamic languages) defers attribute lookups until runtime. This allows you to break past the ideas of polymorphism and interfaces, and leverage the power of duck-typing, whereby you can use a type that merely looks like it should work, instead of having to worry about its ancestry or what it claims to implement.
Can't speak for python per se, but I was playing around with the PSObject class in Powershell last week which allows you to dynamically add members, methods, etc. Coming from a C++\C# background, this seemed like magic - no need to re-comile to get these constructs in-built making it a much nicer workflow for what I was doing.
Python is strongly typed and object oriented the difference is that Python is also dynamic.
In Python classes are objects like everything else and as every other object you can create and modify them at runtime. This basically means that you can create and change modules, metaclasses, classes, attributes/methods and functions at runtime. You can add base classes to already existing classes and several other things.
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 1 year ago.
Improve this question
It might seem it has been asked numerous times, but in fact it hasn't. I did my research, and now I'm eager to hear others' opinions.
I have experience with PHP 5, both with functional and object oriented programming methods. I created a few feature-minimalistic websites.
Professionals may agree about PHP not being a programming language that encourages good development habits. (I believe it's not the task of the tool, but this doesn't matter.) Furthermore, its performance is also controversial and often said to be poor compared to competitors.
In the 42nd podcast at Stack Overflow blog a developer from Poland asked what language he should learn in order to improve his skills. Jeff and Joel suggested that every one of them would help, altough there are specific ones that are better in some ways.
Despite they made some great points, it didn't help me that much.
From a beginner point of view, there are not one may not see (correction suggested by S. Lott) many differences between Perl & Python. I would like You to emphasize their strenghts and weaknesses and name a few unique services.
Of course, this wouldn't be fair as I could also check both of them. So here's my wishlist and requirements to help You help me.
First of all, I'd like to follow OOP structures and use it fundamentally. I partly planned a multiuser CMS using MySQL and XML, so the greater the implementations are, the better. Due to its foreseen nature, string manipulation will be used intensively.
If there aren't great differences, comparisons should probably mention syntax and other tiny details that don't matter in the first place.
So, here's my question: which one should I try first -- Perl || Python?
Conclusion
Both Perl and Python have their own fans, which is great. I'd like to say I'm grateful for all participation -- there is no trace of any flame war.
I accepted the most valued answer, although there are many great mini-articles below. As suggested more often, I will go with Python first. Then I'll try Perl later on. Let me see which one fits my mind better.
During the development of my special CMS, I'm going to ask more regarding programming doubts -- because developers now can count on each other! Thank you.
Edit: There were some people suggesting to choose Ruby or Java instead. Java has actually disappointed me. Maybe it has great features, maybe it hasn't. I wouldn't enjoy using it.
In addition, I was told to use Ruby. So far, most of the developers I communicate with have quite bad opinion about Ruby. I'll see it myself, but that's the last element on my priority list.
Perl is a very nice language and CPAN has a ton of mature modules that will save you a lot of time. Furthermore, Perl is really moving forwards nowadays with a lot of interesting projects (unlike what uninformed fanboys like to spread around). Even a Perl 6 implementation is by now releasing working Perl 6.
I you want to do OO, I would recommend Moose.
Honestly, the "majority" of my programming has been in Perl and PHP and I recently decided to do my latest project in Python, and I must admit it is very nice to program with. I was hesitant of the whole no curly braces thing as that's what I've always done, but it is really very clean. At the end of the day, though, you can make good web applications with all 3, but if you are dead-set on dropping PHP to try something new I would recommend Python and the Django framework.
I'd go with Perl. Not everyone will agree with me here, but it's a great language well suited to system administration work, and it'll expose you to some more functional programming constructs. It's a great language for learning how to use the smallest amount of code for a given task, as well.
For the usage scenario you mentioned though, I think PHP may be your best bet still. Python does have some great web frameworks, however, so if you just want to try out a new language for developing web applications, Python might be your bet.
I have no experience with Python. I vouch strongly to learn Perl, not out of attrition, but because there is a TON to learn in the platform. The key concepts of Perl are: Do What I Mean (DWIM) and There's More Than One Way To Do It (TMTOWTDI). This means, hypothetically there's often no wrong way to approach a problem if the problem is adequately solved.
Start with learning the base language of Perl, then extend yourself to learning the key Perl modules, like IO::File, DBI, HTML::Template, XML::LibXML, etc. etc. search.cpan.org will be your resource. perlmonks.org will be your guide. Just about everything useful to do will likely have a module published.
Keep in mind that Perl is a dynamic and loosely structured language. Perl is not the platform to enforce draconian OOP standards, but for good reason. You'll find the language extremely flexible.
Where is Perl used? System Admins use it heavily, as already mentioned. You can still do excellent web apps either by simple CGI or MVC framework.
I haven't worked with Python much, but I can tell why I didn't like about Perl when I used it.
OO support feels tacked on. OO in perl is very different from OO support in the other languages I've used (which include things like PHP, Java, and C#)
TMTOWTDI (There's More Than One Way To Do It). Good idea in theory, terrible idea in practice as it reduces code readability.
Perl uses a lot of magic symbols.
Perl doesn't support named function arguments, meaning that you need to dig into the #_ array to get the arguments passed to a function (or rather, a sub as perl doesn't have the function keyword). This means you'll see a lot of things like the example below (moved 'cause SO doesn't like code in numbered lists)
Having said all that, I'd look into Python. Unless you want to go with something heavier-weight like C++ or C#/Java.
Oh, before I forgot: I wanted to put an example for 4 above, but SO doesn't like putting code in numbered lists:
sub mySub {
#extremely common to see in Perl, as built-ins operators operate on the $_ scalar or #_ array implicitly
my $arg1 = shift;
my $arg2 = shift;
}
I recently made the step from Perl over to Python, after a couple of Perl-only years. Soon thereafter I discovered I had started to read through all kinds of Python-code just as it were any other easy to read text — something I've never done with Perl. Having to delve into third-party Perl code has always been kind of a nightmare for me, so this came as a very very nice surprise!
For me, this means Python-code is much easier to maintain, which on the long run makes Python much more attractive than Perl.
Python is clean and elegant, and the fact that LOTS of C APIs have been wrapped, gives you powerful hooks to much. I also like the "Zen of Python".
Beautiful is better than ugly.
Explicit is better than implicit.
Simple is better than complex.
Complex is better than complicated.
Flat is better than nested.
Sparse is better than dense.
Readability counts.
Special cases aren't special enough to break the rules.
Although practicality beats purity.
Errors should never pass silently.
Unless explicitly silenced.
In the face of ambiguity, refuse the temptation to guess.
There should be one-- and preferably only one --obvious way to
do it.
Although that way may not be obvious at first unless you're Dutch.
Now is better than never.
Although never is often better than right now.
If the implementation is hard to explain, it's a bad idea.
If the implementation is easy to explain, it may be a good idea.
Namespaces are one honking great idea -- let's do more of those!
As a Perl programmer, I would normally say Perl. But coming from PHP, I think Perl is too similar and you won't actually get that much out of it. (Not because there isn't a lot to learn, but you are likely to program in Perl using the same style as you program in PHP.)
I'd suggest something completely different: Haskell (suggested by Joel), Lisp, Lua, JavaScript or C. Any one of these would make you a better programmer by opening up new ways of looking at the world.
But there's no reason to stop learning PHP in the meantime.
For a good look at the dark side of these languages, I heartily recommend: What are five things you hate about your favorite language?
I suggest going through a beginner tutorial of each and decide for yourself which fits you better. You'll find you can do what you need to do in either:
Python Tutorial (Python Classes)
Perl Tutorial (Perl Classes)
(Couldn't find a single 'official' perl tutorial, feel free to suggest one)
In my experience python provides a cleaner, more straight-forward experience.
My issues with perl:
'use strict;', Taint, Warnings? - Ideally these shouldn't be needed.
Passing variables: #; vs. $, vs shift
Scoping my, local, ours? (The local defintion seems to particularly point out some confusion with perl, "You really probably want to be using my instead, because local isn't what most people think of as "local".".)
In general with my perl skills I still find my self referencing documentation for built-in features. Where as in python I find this less so. (I've worked in both roughly the same amount of time, but my general programming expereince has grown with time. In other words, I'd probably be a better perl programmer now)
If your a unix command line guru though, perl may come more naturally to you. Or, if your using it mainly as a replacement or extension to command line admin tasks, it may suit your needs fine. In my opinion perl is "faster on the draw" at the command line than python is.
Why isn't there Ruby on your list? Maybe you should give it a try.
"I'd like to follow OOP structure..." advocates for Python or, even more so if you're open, Ruby. On the other hand, in terms of existing libraries, the order is probably Perl > Python >> Ruby. In terms of your career, Perl on your resume is unlikely to make you stand out, while Python and Ruby may catch the eye of a hiring manager.
As a PHP programmer, you are probably going to see all 3 as somewhat "burdensome" to get a Web page up. All have good solutions for Web frameworks, but none is quite as focussed on rendering a Web page as is PHP.
I think that Python is quite likely to be a better choice for you than Perl. It has many good resources, a large community (although not as large as Perl, probably), "stands out" a little on a resume, and has a good reputation.
If those 2 are your only choices, I would choose Python.
Otherwise you should learn javascript.
No I mean really learn it...
If you won't be doing web development with this language, either of them would do. If you are, you may find that doing web development in perl is a bit more complicated, since all of the frameworks require more knowledge of the language.
You can do nice things in both, but my opinion is that perl allows more rapid development. Also, perl's regexes rock!
Every dynamic language is from same family. It does not matter Which is the tool you work with it matter how you do..
PHP VS PYTHON OT PERL OR RUBY? Stop it
As many comments mentioned python is cleaner well sometime whose curly brackets are use full to. You just have to practice.
I am a C++ developer, slowly getting into web development. I like LISP a lot but don't like AllegroCL and web-frameworks available for LISP. I am looking for more freedom and ability to do cool hacks on language level. I don't consider tabs as a crime against nature.
Which one is closer to LISP: Python or Ruby?
I can't seem to be able to choose from Python and Ruby: they seem very similar but apparently Ruby is more functional and object-oriented, which are good things, while Python is more like Perl: a simple scripting language. Do I have the right impression?
PS - This might seem like a flame bait but it's not really, I'm just trying not to go crazy from OCD about switching from RoR to Python/Django and back.
Peter Norvig, a famous and great lisper, converted to Python. He wrote the article Python for Lisp Programmers, which you might find interesting with its detailed comparison of features.
Python looks like executable pseudo-code. It's easy to pick up, and often using your intuition will just work. Python allows you to easily put your ideas into code.
Now, for web development, Python might seem like a more scattered option than Ruby, with the plethora of Python web frameworks available. Still, in general, Python is a very nice and useful language to know. As Ruby and Python's niches overlap, I agree with Kiv that it is partly a matter of personal taste which one you pick.
I'd go with Ruby. It's got all kinds of metaprogramming and duck punching hacks that make it really easy to extend. Features like blocks may not seem like much at first, but they make for some really clean syntax if you use them right. Open classes can be debugging hell if you screw them up, but if you're a responsible programmer, you can do things like 2.days.from_now (example from Rails) really easily (Python can do this too, I think, but with a bit more pain)
PS: Check out "Why Ruby is an acceptable LISP".
Devils Advocate: Who Cares?
They are both good systems and have an ecosystem of good web frameworks and active developer communities. I'm guessing that you're framing your decision based on the wrong criteria. The question sounds like you're fretting about whether you will hit implementation problems or other difficulties by choosing one over the other. Don't.
This is similar to Java/.Net decisions. There may be compelling reasons in a specific instance, but soft factors like the architect's familiarity with the platform are a much stronger predictor of project success.
I will admit that I've used Python much more than Ruby, but I wouldn't say that I have any great preference between the two apart from familiarity. I've used Python off and on since about 1998 and I like the Smalltalkish-ness of Ruby as I used Smalltalk briefly about 15 years ago. They both do similar things slightly differently.
I would like certain features from Ruby (or Smalltalk for that matter) but Python doesn't work that way. Instead, it has other features and language idioms are slightly different from Ruby or Smalltalk. Several of the other posters have linked out to articles that compare the two.
If you're worrying about Rails vs. Django, that suggests you're looking for a platform for web applications. Both languages have good tool support and an active developer community. Django seems to be the winner of the Python web framework melee and Rails seems to be in the process of 'crossing the chasm' and bringing Ruby along with it. Both are reasonably mature systems and have been demonstrated to work well for respectable traffic volumes.
ProTip: The presence of religious wars is a good indicator that neither side has a compelling arguement.
So, I'm going to play devil's advocate and say that worrying about the choice is pointless. The languages have advantages and disadvantages with respect to each other but nothing that could be viewed as compelling in the general case. Fretting about the detailed merits of one platform or the other is framing the decision wrongly.
Pick one and use it. You will be able to build systems effectively with either.
Speaking as a "Rubyist", I'd agree with Kiv. The two languages both grant a nice amount of leeway when it comes to programming paradigms, but are also have benefits/shortcomings. I think that the compromises you make either way are a lot about your own programming style and taste.
Personally, I think Ruby can read more like pseudo-code than Python. First, Python has active whitespace, which while elegant in the eyes of many, doesn't tend to enter the equation when writing pseudo-code. Also, Ruby's syntax is quite flexible. That flexibility causes a lot of quirks that can confuse, but also allows code that's quite expressive and pretty to look at.
Finally, I'd really say that Ruby feels more Perl-ish to me. That's partly because I'm far more comfortable with it, so I can hack out scripts rather quickly. A lot of Ruby's syntax was borrowed from Perl though, and I haven't seen much Python code that feels similar (though again, I have little experience with Python).
Depending on the approach to web programming you'd like to take, I think that the types of web frameworks available in each language could perhaps be a factor in deciding as well. I'd say try them both. You can get a working knowledge of each of them in an afternoon, and while you won't be writing awesome Ruby or Python, you can probably establish a feel for each, and decide which you like more.
Update: I think your question should actually be two separate discussions: one with Ruby, one with Python. The comparisons are less important because you start debating the merits of the differences, as opposed to which language will work better for you. If you have questions about Ruby, I'd be more than happy to answer as best I can.
Both Ruby and Python are fairly distant from the Lisp traditions of immutable data, programs as data, and macros. But Ruby is very nearly a clone of Smalltalk (and I hope will grow more like Smalltalk as the Perlish cruft is deprecated), and Smalltalk, like Lisp, is a language that takes one idea to extremes. Based on your desire to do cool hacks on the language level I'd go with Ruby, as it inherits a lot of the metaprogramming mindset from Smalltalk, and that mindset is connected to the Lisp tradition.
Alex Martelli gives a good analysis of the subject. It's a bit dated now, but I agree with the basic gist of it: Python and Ruby are two different ways of implementing the same thing. Sure there are some things you can do in Ruby that you can't do in Python. And sure Python's syntax is (arguably) better than Ruby's. But when you get down to it, there's not a whole lot of objective, scientific reason to prefer one over the other.
A common thing that you will hear is this: the platform is more important than the language and Python has a better platform than Ruby (this argument works both ways so don't vote me down, all you rubyists). And there is some truth to it. Unfortunately, it's not very relevant though. If you dislike the platform for either languages, there are implementations of both in Java and .Net, so you can use those if you have concerns about the platform.
I also recommend the article by Peter Norvig that namin posted. If you want to look at functional programming in Python check out the functools module in the standard library.
There is also a lot of room to hack around in Python; private variables are by convention and not enforced, so you can poke around in the internal state of objects if you feel like it. Usually this is not necessary, though.
Both Ruby and Python are very object-oriented and support functional programming; I wouldn't say either one is clearly superior for your project; it's partly a matter of personal taste.
I am a Pythonista; however, based on your requirements, especially the "cool hacks on the language level", I would suggest you work on Ruby. Ruby is more flexible in the Perl way and you can do a lot of hacks; Python is targeted towards readability, which is a very good thing, and generally language hacks are a little frowned upon. Ruby's basic types can be modified in a hackish way that typically prototype languages allow, while Python's basic types are more suited for subclassing.
By the way, I would add a minor correction: both Ruby and Python are very, very object-oriented, and neither is intended to be used for quick-and-dirty scripts the Perl way. Among the two, Ruby is syntactically more similar to Perl than Python.
If you need Unicode support, remember to check how well supported it is. AFAIK, Python's support for Unicode is better than Ruby's, especially since Python 3.0. On the other hand, Python 3 is still missing some popular packages and 3rd party libraries, so that might play against.
I'm a Rubyist who chose the language based on very similar criteria. Python is a good language and I enjoy working with it too, but I think Ruby is somewhat more Lispy in the degree of freedom it gives to the programmer. Python seems to impose its opinions a little bit more (which can be a good thing, but isn't according to our criteria here).
Python certainly isn't more Perlish— Ruby is essentially a Smalltalk/Perl mashup (some of its less-used features are pulled directly from Perl), whereas Python is only distantly related to either.
pick the most popular one for your domain so your work gets the most visibility. some might say ruby/rails for web, python for everything else. picking a language just because its like lisp is really not appropriate for a professional.
If you like lisp, I think you'll be better like ruby but c++ reminds me more of python. I've posted a small post about this subject : http://hartator.wordpress.com/2011/06/12/ruby-vs-python-2011/
As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 10 years ago.
Considering the criteria listed below, which of Python, Groovy or Ruby would you use?
Criteria (Importance out of 10, 10 being most important)
Richness of API/libraries available (eg. maths, plotting, networking) (9)
Ability to embed in desktop (java/c++) applications (8)
Ease of deployment (8)
Ability to interface with DLLs/Shared Libraries (7)
Ability to generate GUIs (7)
Community/User support (6)
Portability (6)
Database manipulation (3)
Language/Semantics (2)
I think it's going to be difficult to get an objective comparison. I personally prefer Python. To address one of your criteria, Python was designed from the start to be an embeddable language. It has a very rich C API, and the interpreter is modularized to make it easy to call from C. If Java is your host environment, you should look at Jython, an implementation of Python inside the Java environment (VM and libs).
Having worked with all 3 of them, this is what I can say:
Python
has very mature libraries
libraries are documented
documentation can be accessed from your debugger/shell at runtime through the docstrings
you can develop code without an IDE
Ruby
has some great libraries ( even though some are badly documented )
Ruby's instrospection mechanisms are great. They make writing code pretty easy ( even if documentation is not available )
you can develop code without an IDE
Groovy
you can benefit from everything Java has to offer
syntax is somewhat inspired from Ruby
it's hard to write code without an IDE. You have no way to debug stuff from your console ( this is something you can easily do in Python/Ruby ) and the available Groovy plugins have a lot of catching up to do. I wrote some apps using Groovy and as they get bigger I regret not going with Ruby/Python ( debugging would have been WAY more easier ). If you'll only develop from an IDE, Groovy's a cool language.
Just to muddy the waters...
Groovy give you access to Java. Java has an extremely rich set of APIs/Libraries, applications, etc.
Groovy is embeddable, although easiest in Java.
DLLs/Libraries (if you're talking about non-Groovy/Java) may be somewhat problematic, although there are ways and some APIs to help.
I've done some Python programming, but being more familiar with Java, Groovy comes a lot easier to me.
Groovy? I'm just picking it up; try this (inside the groovyconsole):
File.metaClass.invokeMethod = { String name, args ->
System.out.print ("Call to $name intercepted...");
File.metaClass.getMetaMethod(name, args).invoke(delegate, args);
}
new File("c:/temp").eachFile{
if (it.isFile()) println it.canonicalPath
}
The first code is AOP. All calls to any method of File object will be intercepted. No additional tools required. This is executed against existing Java class dynamically.
In the second block, you remove the 'f' closure parameter. Being just one parameter, it defaults to the built in "it" variable available to the closure context.
Here is what you get:
"Call to isFile intercepted...C:\temp\img.jpg"
etc.
try Groovy .. it has all features that you need there. You can use existing java lib without any modification on its classes.
basically .. groovy is java++, it is more dynamic and fun to learn (just like ruby)
I dont like ruby or python syntax so I will put them behind. Groovy is just like C/C++ syntax so I like him lol :)
Python has all nine criteria. It scores a 56.
I'm sure Ruby has everything Python has. It seems to have fewer libraries. So it scores a 51.
I don't know if Groovy has every feature.
Since Python is 56 and Ruby is a 51, Python just barely edges out Ruby.
However, I think this kind of decision can still boil down to some subjective issues outside these nine criteria.
From your critera, I'd pick JRuby:
Richness of API/libraries available (eg. maths, plotting, networking) (9)
Everything the JVM has access to, which is a lot
Ability to embed in desktop (java/c++) applications (8)
Excellent Monkeybars framework, which lets you design a swing GUI in your GUI designer, and then wire it up using clean ruby code
Ease of deployment (8)
Rawr can package your app as an executable jar
Ability to interface with DLLs/Shared Libraries (7)
Java shared libraries easily, C ones via jna + libffi
Ability to generate GUIs (7)
Swing just works. Not sure how easy it is to use QtJambi, but it's definitely possible.
Community/User support (6)
Lots. Ruby has an excellent community.
Portability (6)
Everywhere the JVM works
Database manipulation (3)
All the ruby database libraries and all the java ones
Language/Semantics (2)
Here's where ruby takes the definite lead over groovy and python. The language has had some really beautiful design decisions taken early on, which shows up in the consistency and power of the standard library. Blocks, in particular, make it a joy to use.
This sort of adding-up-scores-by-features is not a good way to choose a programming language. You'd be better off choosing whichever you know the best. If you don't know any of them, try them out for a little while. If you have a really specific project in mind, then maybe some programming languages would be better, but if you just have general preferences you will never come to a consensus.
That said, Python is pretty flexible, it's the most popular on your list so the easiest to solve whatever sorts of problems you have by searching, so I'd recommend Python.
Perl? Yikes.
As someone has observed Perl is like a big explosion in a punctuation factory. It's terseness is not an advantage if the resultant code is not self documenting.
Have used Groovy for some utility tasks, easy to get going. Full access to Java libraries, plus some cool addtions to it, like listing the files in a directory using a closure:
// process all files printing out full name (. and .. auto excluded)
new File(basedir).eachFile{ f->
if (f.isFile()) println f.canonicalPath
}
I know it's not on your list, but at least look at perl.
Richness of Api/Libraries to sink a ship.
Runs on more systems than most people realise exists.
Works well with Binary libraries.
Has a huge community.
Portability, See above.
Database manipulation: more ways to do it. ( Pick your favorite module )
And one of the most expressive/terse languages around.
As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 11 years ago.
I'm currently primarily a D programmer and am looking to add another language to my toolbox, preferably one that supports the metaprogramming hacks that just can't be done in a statically compiled language like D.
I've read up on Lisp a little and I would love to find a language that allows some of the cool stuff that Lisp does, but without the strange syntax, etc. of Lisp. I don't want to start a language flame war, and I'm sure both Ruby and Python have their tradeoffs, so I'll list what's important to me personally. Please tell me whether Ruby, Python, or some other language would be best for me.
Important:
Good metaprogramming. Ability to create classes, methods, functions, etc. at runtime. Preferably, minimal distinction between code and data, Lisp style.
Nice, clean, sane syntax and consistent, intuitive semantics. Basically a well thought-out, fun to use, modern language.
Multiple paradigms. No one paradigm is right for every project, or even every small subproblem within a project.
An interesting language that actually affects the way one thinks about programming.
Somewhat important:
Performance. It would be nice if performance was decent, but when performance is a real priority, I'll use D instead.
Well-documented.
Not important:
Community size, library availability, etc. None of these are characteristics of the language itself, and all can change very quickly.
Job availability. I am not a full-time, professional programmer. I am a grad student and programming is tangentially relevant to my research.
Any features that are primarily designed with very large projects worked on by a million code monkeys in mind.
I've read up on Lisp a little and I would love to find a language that allows some of the cool stuff that Lisp does, but without the strange syntax, etc. of Lisp.
Wouldn't we all.
minimal distinction between code and data, Lisp style
Sadly, the minimal distinction between code and data and "strange" syntax are consequences of each other.
If you want easy-to-read syntax, you have Python. However, the code is not represented in any of the commonly-used built-in data structures. It fails—as most languages do—in item #1 of your 'important' list. That makes it difficult to provide useful help.
You can't have it all. Remember, you aren't the first to have this thought. If something like your ideal language existed, we'd all be using it. Since the real world falls short of your ideals, you'll have to re-prioritize your wish list. The "important" section has to be rearranged to identify what's really important to you.
Honestly, as far as metaprogramming facilities go, Ruby and Python are a lot more similar than some of their adherent like to admit. This review of both language offers a pretty good comparison/review:
http://regebro.wordpress.com/2009/07/12/python-vs-ruby/
So, just pick one based on some criteria. Maybe you like Rails and want to study that code. Maybe SciPy is your thing. Look at the ecosystem of libraries, community, etc, and pick one. You certainly won't lose out on some metaprogramming nirvana based on your choice of either.
Disclaimer: I only dabble in either language, but I have at least written small working programs (not just quick scripts, for which I use Perl, bash or GNU make) in both.
Ruby can be really nice for the "multiple paradigms" point 3, because it works hard to make it easy to create domain-specific languages. For example, browse online and look at a couple of bits of Ruby on Rails code, and a couple of bits of Rake code. They're both Ruby, and you can see the similarities, but they don't look like what you'd normally think of as the same language.
Python seems to me to be a bit more predictable (possibly correlated to 'clean' and 'sane' point 2), but I don't really know whether that's because of the language itself or just that it's typically used by people with different values. I have never attempted deep magic in Python. I would certainly say that both languages are well thought out.
Both score well in 1 and 4. [Edit: actually 1 is pretty arguable - there is "eval" in both, as common in interpreted languages, but they're hardly conceptually pure. You can define closures, assign methods to objects, and whatnot. Not sure whether this goes as far as you want.]
Personally I find Ruby more fun, but in part that's because it's easier to get distracted thinking of cool ways to do things. I've actually used Python more. Sometimes you don't want cool, you want to get on with it so it's done before bedtime...
Neither of them is difficult to get into, so you could just decide to do your next minor task in one, and the one after that in the other. Or pick up an introductory book on each from the library, skim-read them both and see what grabs you.
There's not really a huge difference between python and ruby at least at an ideological level. For the most part, they're just different flavors of the same thing. Thus, I would recommend seeing which one matches your programming style more.
Have you considered Smalltalk? It offers a very simple, clear and extensible syntax with reflectivity and introspection capabilities and a fully integrated development environment that takes advantage of those capabilities. Have a look at some of the work being done in Squeak Smalltalk for instance. A lot of researchers using Squeak hang out on the Squeak mailing list and #squeak on freenode, so you can get help on complex issues very easily.
Other indicators of its current relevance: it runs on any platform you'd care to name (including the iPhone); Gilad Bracha is basing his Newspeak work on Squeak; the V8 team cut their teeth on Smalltalk VMs; and Dan Ingalls and Randal Schwartz have recently returned to Smalltalk work after years in the wilderness.
Best of luck with your search - let us know what you decide in the end.
Lisp satisfies all your criteria, including performance, and it is the only language that doesn't have (strange) syntax. If you eschew it on such an astoundingly ill-informed/wrong-headed basis and consequently miss out on the experience of using e.g. Emacs+SLIME+CL, you'll be doing yourself a great disservice.
Your 4 "important" points lead to Ruby exactly, while the 2 "somewhat important" points ruled by Python. So be it.
You are describing Ruby.
Good metaprogramming. Ability to create classes, methods, functions,
etc. at runtime. Preferably, minimal
distinction between code and data,
Lisp style.
It's very easy to extend and modify existing primitives at runtime. In ruby everything is an object, strings, integers, even functions.
You can also construct shortcuts for syntactic sugar, for example with class_eval.
Nice, clean, sane syntax and consistent, intuitive semantics.
Basically a well thought-out, fun to
use, modern language.
Ruby follows the principle of less surprise, and when comparing Ruby code vs the equivalent in other language many people consider it more "beautiful".
Multiple paradigms. No one paradigm is right for every project,
or even every small subproblem within
a project.
You can follow imperative, object oriented, functional and reflective.
An interesting language that actually affects the way one thinks
about programming.
That's very subjective, but from my point of view the ability to use many paradigms at the same time allows for very interesting ideas.
I've tried Python and it doesn't fit your important points.
Compare code examples that do the same thing (join with a newline non-empty descriptions of items from a myList list) in different languages (languages are arranged in reverse-alphabetic order):
Ruby:
myList.collect { |f| f.description }.select { |d| d != "" }.join("\n")
Or
myList.map(&:description).reject(&:empty?).join("\n")
Python:
descriptions = (f.description() for f in mylist)
"\n".join(filter(len, descriptions))
Or
"\n".join(f.description() for f in mylist if f.description())
Perl:
join "\n", grep { $_ } map { $_->description } #myList;
Or
join "\n", grep /./, map { $_->description } #myList;
Javascript:
myList.map(function(e) e.description())
.filter(function(e) e).join("\n")
Io:
myList collect(description) select(!="") join("\n")
Here's an Io guide.
Ruby would be better than Lisp in terms of being "mainstream" (whatever that really means, but one realistic concern is how easy it would be to find answers to your questions on Lisp programming if you were to go with that.) In any case, I found Ruby very easy to pick up. In the same amount of time that I had spent first learning Python (or other languages for that matter), I was soon writing better code much more efficiently than I ever had before. That's just one person's opinion, though; take it with a grain of salt, I guess. I know much more about Ruby at this point than I do Python or Lisp, but you should know that I was a Python person for quite a while before I switched.
Lisp is definitely quite cool and worth looking into; as you said, the size of community, etc. can change quite quickly. That being said, the size itself isn't as important as the quality of the community. For example, the #ruby-lang channel is still filled with some incredibly smart people. Lisp seems to attract some really smart people too. I can't speak much about the Python community as I don't have a lot of firsthand experience, but it seems to be "too big" sometimes. (I remember people being quite rude on their IRC channel, and from what I've heard from friends that are really into Python, that seems to be the rule rather than the exception.)
Anyway, some resources that you might find useful are:
1) The Pragmatic Programmers Ruby Metaprogramming series (http://www.pragprog.com/screencasts/v-dtrubyom/the-ruby-object-model-and-metaprogramming) -- not free, but the later episodes are quite intriguing. (The code is free, if you want to download it and see what you'd be learning about.)
2) On Lisp by Paul Graham (http://www.paulgraham.com/onlisp.html). It's a little old, but it's a classic (and downloadable for free).
#Jason I respectively disagree. There are differences that make Ruby superior to Python for metaprogramming - both philosophical and pragmatic. For starters, Ruby gets inheritance right with Single Inheritance and Mixins. And when it comes to metaprogramming you simply need to understand that it's all about the self. The canonical difference here is that in Ruby you have access to the self object at runtime - in Python you do not!
Unlike Python, in Ruby there is no separate compile or runtime phase. In Ruby, every line of code is executed against a particular self object. In Ruby every class inherits from both object and a hidden metaclass. This makes for some interesting dynamics:
class Ninja
def rank
puts "Orange Clan"
end
self.name #=> "Ninja"
end
Using self.name accesses the Ninja classes' metaclass name method to return the class name of Ninja. Does metaprogramming flower so beautiful in Python? I sincerely doubt it!
I am using Python for many projects and I think Python does provide all the features you asked for.
important:
Metaprogramming: Python supports metaclasses and runtime class/method generation etc
Syntax: Well thats somehow subjective. I like Pythons syntax for its simplicity, but some People complain that Python is whitespace-sensitive.
Paradigms: Python supports procedural, object-oriented and basic functional programming.
I think Python has a very practical oriented style, it was very inspiring for me.
Somewhat important:
Performance: Well its a scripting language. But writing C extensions for Python is a common optimization practice.
Documentation: I cannot complain. Its not that detailed as someone may know from Java, but its good enough.
As you are grad student you may want to read this paper claiming that Python is all a scientist needs.
Unfortunately I cannot compare Python to Ruby, since I never used that language.
Regards,
Dennis
Well, if you don't like the lisp syntax perhaps assembler is the way to go. :-)
It certainly has minimal distinction between code and data, is multi-paradigm (or maybe that is no-paradigm) and it's a mind expanding (if tedious) experience both in terms of the learning and the tricks you can do.
Io satisfies all of your "Important" points. I don't think there's a better language out there for doing crazy meta hackery.
one that supports the metaprogramming hacks that just can't be done in a statically compiled language
I would love to find a language that allows some of the cool stuff that Lisp does
Lisp can be compiled.
Did you try Rebol?
My answer would be neither. I know both languages, took a class on Ruby and been programming in python for several years. Lisp is good at metaprogramming due to the fact that its sole purpose is to transform lists, its own source code is just a list of tokens so metaprogramming is natural. The three languages I like best for this type of thing is Rebol, Forth and Factor. Rebol is a very strong dialecting language which takes code from its input stream, runs an expression against it and transforms it using rules written in the language. Very expressive and extremely good at dialecting. Factor and Forth are more or less completely divorced from syntax and you program them by defining and calling words. They are generally mostly written in their own language. You don't write applications in traditional sense, you extend the language by writing your own words to define your particular application. Factor can be especially nice as it has many features I have only seen in smalltalk for evaluating and working with source code. A really nice workspace, interactive documents, etc.
There isn't really a lot to separate Python and Ruby. I'd say the Python community is larger and more mature than the Ruby community, and that's really important for me. Ruby is a more flexible language, which has positive and negative repercussions. However, I'm sure there will be plenty of people to go into detail on both these languages, so I'll throw a third option into the ring. How about JavaScript?
JavaScript was originally designed to be Scheme for the web, and it's prototype-based, which is an advantage over Python and Ruby as far as multi-paradigm and metaprogramming is concerned. The syntax isn't as nice as the other two, but it is probably the most widely deployed language in existence, and performance is getting better every day.
If you like the lisp-style code-is-data concept, but don't like the Lispy syntax, maybe Prolog would be a good choice.
Whether that qualifies as a "fun to use, modern language", I'll leave to others to judge. ;-)
Ruby is my choice after exploring Python, Smalltalk, and Ruby.
What about OCaml ?
OCaml features: a static type system, type inference, parametric polymorphism, tail recursion, pattern matching, first class lexical closures, functors (parametric modules), exception handling, and incremental generational automatic garbage collection.
I think that it satisfies the following:
Important:
Nice, clean, sane syntax and consistent, intuitive semantics. Basically a well thought-out, fun to use, modern language.
Multiple paradigms. No one paradigm is right for every project, or even every small subproblem within a project.
An interesting language that actually affects the way one thinks about programming.
Somewhat important:
Performance. It would be nice if performance was decent, but when performance is a real priority, I'll use D instead.
Well-documented.
I've use Python a very bit, but much more Ruby. However I'd argue they both provide what you asked for.
If I see all your four points then you may at least check:
http://www.iolanguage.com/
And Mozart/Oz may be interesting for you also:
http://mozart.github.io/
Regards
Friedrich
For python-style syntax and lisp-like macros (macros that are real code) and good DSL see converge.
I'm not sure that Python would fulfill all things you desire (especially the point about the minimal distinction between code and data), but there is one argument in favour of python. There is a project out there which makes it easy for you to program extensions for python in D, so you can have the best of both worlds. http://pyd.dsource.org/celerid.html
if you love the rose, you have to learn to live with the thorns :)
I would recommend you go with Ruby.
When I first started to learn it, I found it really easy to pick up.
Do not to mix Ruby Programming Language with Ruby Implementations, thinking that POSIX threads are not possible in ruby.
You can simply compile with pthread support, and this was already possible at the time this thread was created, if you pardon the pun.
The answer to this question is simple. If you like lisp, you will probably prefer ruby. Or, whatever you like.
I suggest that you try out both languages and pick the one that appeals to you. Both Python and Ruby can do what you want.
Also read this thread.
Go with JS just check out AJS (Alternative JavaScript Syntax) at my github http://github.com/visionmedia it will give you some cleaner looking closures etc :D
Concerning your main-point (meta-programming):
Version 1.6 of Groovy has AST (Abstract Syntax Tree) programming built-in as a standard and integrated feature.
Ruby has RubyParser, but it's an add-on.