3 ms·
Ruby's blocks and built in regular-expressions are two examples of things you're missing. if result =~ /regex/ that kind of thing is awesome for readability,
by wcarss 15y ago
Ruby's blocks and built in regular-expressions are two examples of things you're missing.
if result =~ /regex/
that kind of thing is awesome for readability, but it can also be pretty darn slow.
There's also some interesting things about the ruby object model and interpreter that are different from python's approach. Whereas in the python REPL you type help(object) to get the docs on that object, in ruby you type object.methods or object.public_methods, etc. It's less documentation oriented, and more code-exploration oriented, but the two end up delivering the same sort of information.
Hope that's helpful! Ruby's a lot of fun to tool around with, and there are (in my opinion) fewer things about it to trip you up completely than there are when first learning python. But once you use it for a while and get beyond the basics, it becomes clear that there's a lot of unfocused cruft foating about, which fits no rhyme nor reason. Much more than Python has.
(cautionary note: I'm not an expert with either language)
- shazow 15y agoHave a look at IPython for a more code-exploration oriented experience. http://en.wikipedia.org/wiki/Ipython http://en.wikipedia.org/wiki/Ipython (Sadly the homepage doesn't quite get the simpler sell points across as well. http://ipython.org/ http://ipython.org/)
- maxerickson 15y agoIt sounds like object.public_methods and object.methods are a lot like dir(object) in python.
- zem 15y agoruby does have its share of cruft, but it also has some inspired features that make a far bigger difference than you'd think they would. blocks are the biggest (specifically, syntactic support for attaching a lexical closure to every method call, which the object can choose to use or not), but here's another cute one: the case statement case object when matcher1; ... when matcher2; ... end performs a method call on the matchers, with the object as an argument, rather than vice versa. so you can say things like case name when "John Smith"; puts "hello again" when / Smith$/; puts "are you related to john?" end the string "John Smith" and the regexp / Smith$/ will each call a different matcher to see if they match your name - a far cleaner design than the string class having to provide matchers for everything you might want to use in a case statement.
- hcarvalhoalves 15y agoAs a programmer who knows both languages, while I like regex as a native type with it's own notation, I don't miss ruby blocks at all. Most Ruby code I see abuses blocks pretty badly instead of refactoring behaviour into a function, and soon you have a code base littered with the same algorithm over and over again. I think Guido has a point on making lambdas one-liners exclusively. Also, Ruby programmers talk about how readable Ruby is, but I disagree. The lack of consistency between using parenthesis or not, how to separate arguments, or even string formating syntax makes reading Ruby code wrote by someone else much more prone to "WTF" moments than Python.