4 ms·
I really, really like Ruby-the-language, and prefer it over python. I don't love that it's joined at the hip with Rails. compared to Python, Ruby has: - fi
by philsnow 4y ago
I really, really like Ruby-the-language, and prefer it over python. I don't love that it's joined at the hip with Rails.
compared to Python, Ruby has:
- first-class symbols (yes python has sys.intern but it would take a PEP giving them a pithy syntax to make them usable, plus python has 25 years of stdlib and libraries using "strings" or enums for constants instead of :symbols)
- procs/blocks and better-than-python lambdas
- "open classes" / monkey-patching of builtins (for better or for worse)
- trivial metaprogramming with method_missing (for better or for worse)
some of these make fun one-off projects easier or faster, some of them would be less welcome in large, mature codebases.
- inferiorhuman 4y agoSo I'm a Ruby fan and I largely agree with you. I started dicking around with Stable Diffusion recently and was almost immediately reminded of so many things I dislike about Python. But just to be a bit contrary: - I don't see a huge value in symbols. In Ruby they are literally just static strings which means they use memory you'll never get back – potentially important if you're e.g. parsing something large into a hash and symbolizing the keys. If you have to put a non-alphanumeric character in a symbol you still need to use quotes. - Procs, blocks, and lambdas – yes. - Metaprogramming and monkey patching? dfjasdjldfjkdfjlkfdjldfoh4houfhufl. A double edged sword at best and 100% not something I'd want to see in a larger codebase. Javascript folks largely learned this lesson with the shift from Prototype to jQuery. You can do some really neat-o things but they're almost always unintuitive to the uninitiated.
- rco8786 4y agoMonkey patching I agree with but IMO it's unfair to lump metaprogramming into that same bucket.
- djur 4y agoYou can dynamically create symbols and expect them to be garbage collected as of Ruby 2.2. They only become "immortal" if you use them to define a method, instance variable, or constant. So the common use case of hash keys is fine. One important advantage of symbols versus strings is that Symbol#== is constant time.
- inferiorhuman 4y agoAh hah, you've discovered how long it's been since I've thought about Ruby performance. One important advantage of symbols versus strings is that Symbol#== is constant time. At that point though why not use integer constants?
- knodi123 4y agosyntactic sugar- you don't have to pre-declare them or worry about conflicting values. And occasionally the symbol.to_s method is useful in logging or whatnot. That's pretty much it.
- chillfox 4y agoI think monkey patching is a nice tool to have. I once had to deal with a vendor provided gem that assumed the product was configured in a specific way (it was not) deep in an internal method. Patching that one method was all I needed to do to get it working.
- knodi123 4y agoexactly. And when writing a test suite, I monkey-patch at will, which makes it sooo much easier to have self-contained tests without side effects or complicated dependencies.
- philsnow 4y ago> A double edged sword at best and 100% not something I'd want to see in a larger codebase. the real footgun is dependencies that monkey patch things you don't know about / don't expect, and then the order you require those dependencies becomes important. augughghhhhh I hate that part.
- deleted 4y ago[deleted]
- googlryas 4y agoThe ruby proc passing style seems so ergonomic in curly paren style languages that I just can't understand my I haven't seen it anywhere else.
- est 4y agoHaven't used Ruby in years, the one thing I miss in Ruby is decorators.