Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Python is slightly less powerful but is pretty fine for many tasks, and much easier to learn than Ruby, with a consistent syntax. So you can quickly learn it and then spend the rest of the day focusing on getting things done.


How is Python less powerful ? They both have metaclasses, monkey patching, first class functions, unicode... Ruby has blocks, Python has decorators. You can solve pretty much the same problems with the same number of lines.


I should preface this by saying that I prefer Python for my projects for a few reasons, however I agree with parent that Python is less powerful than Ruby.

Both languages have metaclasses but Ruby's are simpler to grasp and more fluid in how they're applied because they're more run time oriented rather than instantiation time oriented like Python's. In fact Python in general tries to make more of a distinction between the instantiation and runtime environments making it a bit more restricted. All this means the average Ruby coder tends to use metaclasses almost everywhere and certainly a lot more than the average Python coder.

Ironically even string processing with encodings is harder in Python 3 than Ruby 1.9 (these are the versions in which both languages modernised their Unicode support). Python's insistence on Unicode everywhere is problematic in places like Japan where there are still extant competing encoding standards that are not fully recoverable when doing a round trip via Unicode. Even ignoring Japan though, Python has had to put in all sorts of hacks to deal with corner cases like the fact that command line parameters or file system names don't always have to use Unicode encodings. 95% of the time you can be ignorant of all this in Python and stuff will just work... but it's a massive pain when you're dealing with the other 5%. I genuinely still don't know if the Python 3 or Ruby 1.9 approach is better... Python's is purer and initially I liked it better conceptually... but having had to apply it practically I'm no longer so convinced.

Finally, I assume you weren't comparing blocks and decorators as somehow equivalent features. It might be worth adding that it's pretty easy to add syntactically pleasing decorators to Ruby without needing special built in syntax, by leveraging Ruby's metaprogramming capabilities. It just tends not to be used as often in Ruby because there's usually different ways to express the equivalent concept.

But while on the topic, blocks are probably the killer feature that makes Ruby more powerful. They essentially allow you to easily change the context of an individual method call in very arbitrary ways. Yes you can do it by passing in named functions or even function pointers in C, but none of this is as syntactically coherent as blocks in Ruby.

If you want a practical example of how this makes Ruby powerful take a look at Rake. It's basically a Make equivalent written in Ruby. The nice thing is that you never leave Ruby, all you do is add a "require 'rake'" at the top of your Ruby file and you now have enough DSL machinery to be able to write pretty nice rule syntax without ever having to write a parser for a custom language (and leaving the power of Ruby behind).

I don't expect any of this to be particularly convincing. The difference in power only becomes obvious when you start writing idiomatically in both languages. When I first started writing Python I tended to write it more like idiomatic Ruby and it was not pretty. Overall Python and Ruby are at a fairly similar level to each other but Ruby definitely has a bit of an edge in terms of expressiveness.


That's a fairly balanced answer. Thanks.

Being a Python fan myself and a hater of "DSL all the things", I still like to have a good POV from the other side.


It should be possible to delineate a "core" syntax for Ruby as well and leave the language esoterica to more adventurous practitioners.

Why is this not a thing ?

See my previous comment


This is a thing. Ruby has an ISO standard: https://www.iso.org/standard/59579.html


This is a thing. Most "railers" use a very strict subset of ruby features, although Rails itself uses a lot.


I would disagree. For instance, there are at least two syntaxes in use to describe hashes; parentheses are optionally (and inconsistently) used and so on. Rails suffers from the same issues as does the language




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: