4 ms·
Oh come on, it was funny. You need to lighten up a bit. He gives points on both sides. I do only Ruby and I get what he means.
by immad 17y ago
Oh come on, it was funny.
You need to lighten up a bit. He gives points on both sides. I do only Ruby and I get what he means.
- petercooper 17y agoWhat does he mean then? I've looked at quite a bit of Python and Ruby source code and Python uses square brackets, periods, mathematical symbols, parentheses, and colons in similar ways. Indeed, a method definition in Ruby uses fewer symbols (no need for the colon on the end, or even the parentheses, although that's against common Ruby style). Python even makes nonsense like using double underscores in method names obligatory. Or how about Python's obligatory parentheses on all method calls? How is Ruby really more "line noise" than Python? Seriously. Sure, Ruby allows you to be more lax than Python and write poor, "line noisy" code, but good Ruby is no more "line noise" than good Python.
- sri 17y agoruby uses < (less than) for inheritance; also regular expressions start & end with / (slash). you have %W, %w for arrays and %q, %Q for string. things like "class << self ..." looks weird to those new to ruby. also stuff like "a ||= ...". and of course pre-pending '@' for instance variables and '@@' for class variables. also when i use regexps in ruby i then say "/re(g)ex/ =~ 'string' && $1". in python that would be multiple statements: "m = re.match('re(g)ex', 'string'); m.group(1)" in python existing syntax (or more familiar syntax) is used to accomplish all the above.
- tptacek 17y agoI never use %w for arrays and I never use %Q for strings. After years of schlepping through Python's regular expression support --- support not dissimilar from the regex support C++ has --- /regexes/ are a gift from god. Also, your Ruby vs. Python regex examples aren't even equivalent.
- petercooper 17y agoSigils on variables are a good point. This is an area where I think Python wins out. Dependence on "self" all over the place is irritating at first but ultimately quite comforting - especially when you wonder whether you're going to screw up your attributes when you use the same name for a local variable in your Ruby method ;-) But on inheritance - you have to put the class name in round brackets in Python, no? That's 2 characters to Ruby's 1. Stuff like a ||= shouldn't be considered Ruby-specific noise as Python also has the same idiom as in a += and a -=, just not with ||. || is arguably noise over "or" but it shouldn't seem like cryptic noise with any sort of experience of C, C++, Java, JavaScript, or almost any other mainstream language. Further, that Ruby code of yours does seem more Perlish than Rubyish, but I suspect this is because Ruby style is gradually shifting away from Perl-like styles to more idiomatic approaches. For example, I'd probably choose 'string'[/re(g)ex/, 1] or if I was trying to be "proper" then something like m = string.match(/re(g)ex/); m[1] (or potentially use Regexp#match, but I far prefer String#match). I see those solutions more typically than those you present - and the latter is quite like your Python example - but.. TMTOWTDI and that's Ruby's greatest asset :)
- chairface 17y agoI took him to mean all the built in special variables, like $$ and $! and $?. I don't see them too often in Ruby, but I'm pretty sure the language supports pretty close to Perl's full set. Not a great argument though, unless most of the Ruby I've seen isn't really representative of the whole.