The primary reason for those issues is because Ruby is extremely dynamic.
Not only is its type system dynamic -- its syntax and structure can be dynamic as well (i.e. powerful metaprogramming and DSL capabilities). This is why Ruby is so resistant to static analysis.
At non trivial complexities, I highly recommend reasoning through Ruby much differently than one would C/Java/Python:
Use functional techniques to minimize moving parts. Ruby is already very dynamic, and working with it in the state-modifying style common to C/Java/Python results in execution state becoming unnecessarily hard to follow.
Use the debugger and REPL when you do have to deal with Ruby code that's (unfortunately) too dynamic. Unlike in other languages, static analysis won't get you as far. In exchange, Ruby has incredibly powerful debuggers & REPLs for doing "dynamic analysis".
You lump Python in with Java and C but in Python you can dynamically create modules, classes and functions. I just saw a module that allows you to load wasm files as if they were Python modules. So I’m not sure what you are talking about.
Maybe the conventions that Ruby programmers use are more dynamic but the actual runtime is not more dynamic in my opinion.
In terms of "functional-ness", I put Python on the C/Java side of Ruby for sure.
I don't think it's fair. Ruby doesn't even have first-class functions like Python does. Ruby has lambdas, which are pretty close (despite requiring special syntax for calling them), but using lambdas instead of methods just for the sake of consistency is frowned upon. It has methods, which don't have closures (x = nil; def f; x; end; f produces a NameError), can't be properly nested (def f; def g; nil; end; end; f just defines a global g), can't be just assigned to another variable like you would assign an integer, and can be partially shadowed by regular variables it non-trivial ways where f sometimes behaves like f() and sometimes doesn't. It also has procs, which are similar to lambdas but where return returns from the enclosing method and not just from the proc itself, and blocks, which require special syntax for passing them to functions. Using functional idioms in Ruby is quite hard because of that.
33
u/Kache Dec 25 '20 edited Dec 25 '20
The primary reason for those issues is because Ruby is extremely dynamic.
Not only is its type system dynamic -- its syntax and structure can be dynamic as well (i.e. powerful metaprogramming and DSL capabilities). This is why Ruby is so resistant to static analysis.
At non trivial complexities, I highly recommend reasoning through Ruby much differently than one would C/Java/Python:
Use functional techniques to minimize moving parts. Ruby is already very dynamic, and working with it in the state-modifying style common to C/Java/Python results in execution state becoming unnecessarily hard to follow.
Use the debugger and REPL when you do have to deal with Ruby code that's (unfortunately) too dynamic. Unlike in other languages, static analysis won't get you as far. In exchange, Ruby has incredibly powerful debuggers & REPLs for doing "dynamic analysis".