by faraaz98 · 4y ago · 0 comments
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.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.
One important advantage of symbols versus strings is that Symbol#== is constant time.
At that point though why not use integer constants?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.
I get it that the hype around Ruby and Rails has—thankfully—subsided but Ruby is even better today than it was then.
Sure when it was hype a decade ago you'd get lots of flashy tools and library every other days, but a large part of it was really wonky.
Now that the dust settled, the tools that remain largely used are much higher quality.
Ruby gets results.
This is not the case today. And most of those startups also had to then migrate to Go/Java/etc. to scale.
I love Elixir as a language but I still find myself coming back to Ruby frequently.
Python exists, but there’s nothing about the language that makes me want to use it. Quite the opposite. I find myself avoiding it whenever possible.
As a prominent Python dev told me, “It’s the okayest language out there.”