3 ms·
I have some experience with Python and a lot with Ruby. My experience is similar to djohnstons: For the longest time I just wrote Ruby like I thought it should
by onli 8y ago
I have some experience with Python and a lot with Ruby. My experience is similar to djohnstons: For the longest time I just wrote Ruby like I thought it should work, and it worked, and if not you'd look up that specific thing in the docs. I struggled at first with attr_accessor and instance variables and the difference between String and Symbol, and I needed to see blocks in other code multiple times to understand them, and implicit block passing I got just recently after many years. But overall, Ruby just worked: If you mix "how would I write that in basic english" and "make a mix of all the C-like languages I know" and for the functional aspects "take what I remember from the onetime I learned a lisp", then you write Ruby, and it feels very natural.
Python does not feel natural at all. And I don't mean the indentation, that's in your face enough that it can be handled fast. But Python is just everywhere almost like you'd expect, only to still be different whenever it can. Dicts for example, why is that in there instead of a Hash or what I'd call a assiociative array? Using list instead of Arrays, as if it were a lisp, only that the list behaves like an array with different syntax, and Python is not lisp like at all. Null is of course not null (I already disliked ruby's nil), it's None. Compare how easy ruby makes range, and how inelegant Python makes that.
In the end none of that matters that much and discussing it too much probably only leads to a flame war. What mattered to me: My python program (an audio player for the tray) was completely unstable, it ran into multi-thread issues without me ever understanding why and how to solve them. My first ruby program was enough to pass my employer, my second one is still online (and one of my active projects linked in my profile).
If I want got get something done and have it work well, I use Ruby. Though fact of the matter for ML or even just statistics the ecosystem is way less nice and I will be forced to use Python next time, my try to use Ruby during my last encounter with ML just failed.
- akanet 8y agoFor me the decisive advantage Ruby has over Python is way better map/reduce/select semantics. Python's list comprehensions are just ungainly to me, and I've never understood the reverence for them.
- maksimum 8y agoI think one reason people like comprehensions in python is because they provide an intuitive syntax for both map and select/filter. As I understand it, reduce still provides functionality that you can't get from comprehensions alone. I feel like comprehensions are expressive and readable unless you try to do multiple maps in the same comprehension. I looked up the select/filter syntax in ruby. I guess the main difference is that the name of the element you're iterating over is left implicit compared to comprehensions, but equivalent to filter. details.select{ |item| item[:qty] != "" } [item for item in details if item.qty != ''] filter(lambda item: item.qty != '', items) I'm curious if the implicitness is cumbersome when you need to do a selection that combines multiple lists. How would you express the third line of the following in ruby? A = range(65,69) B = ['A', 'B', 'C', 'D'] [a for a, b in zip(A, B) if b=='C']
- onli 8y agoMy approach would probably be to create the zipped list in the beginning, split it for the comparison and then select the wanted element: A = (65..69).to_a B = ['A', 'B', 'C', 'D'] A.zip(B).select{|x, y| y == 'C' }.map{|x, y| x }
- maksimum 8y agoThanks! That looks equivalent to python without comprehensions. As far as I can tell the difference in the expressiveness of `map/filter/reduce` is mainly about whether you like or don't like comprehensions. Do you have any examples where you believe ruby has cleaner syntax?
- dragonwriter 8y ago> As far as I can tell the difference in the expressiveness of `map/filter/reduce` is mainly about whether you like or don't like comprehensions. Comprehensions don't replace reduce, they are equivalent to a combination of map, filter, and flat_map. The difference is not just about comprehensions, since map/filter/reduce, and friends, in Python are functions, where in Ruby they are methods; so in Python when you can't do it all with comprehensions (reduce, zip, etc.), it's either imperative loops or functional notation (inside-out), while Ruby uses method call notation, which results in operations reading in the order of application.