4 ms·
> I am constantly running into things which I like just a bit less as I am trying it for side projects. Things just don't quite work the way I expect them to.
by maksimum 8y ago
> I am constantly running into things which I like just a bit less as I am trying it for side projects. Things just don't quite work the way I expect them to.
How much of your like/dislike do you think comes down to familiarity with the language?
When I was first learning python, I definitely didn't like it as much because I was unfamiliar with some fairly basic syntax. Exactly the feeling that you're describing (I was coming from matlab). I've been using python for two years now and expressing most 'programs' feels like second nature. I.e. if I am to describe an algorithm on a whiteboard I may as well do it in python because then I don't have to worry about coming up with pseudo-code conventions on the fly, and there is little syntax getting in the way of me expressing semantics.
Based no the link, it seems like ruby is largely similar to python, but it has slightly different choices. I'm curious what someone who's experienced with both would have to say about the stylistic features of the languages (ignoring libraries).
- onli 8y agoI 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?
- 8y ago