Quote:
Originally Posted by Shoe Lace
it protects me from the most common errors (typo in the method name and wrong # of args) without extra annotations.
I think you're mistakenly thinking that this is some kind of special class of errors that's easier to catch, but it's not. To catch this in every possible instance, it has to know the narrowest possible static type of every variable, at which point you're done with all type checking. I don't have the time to explain in detail how type inference can be done, but this is the general approach:
http://en.wikipedia.org/wiki/Unifica...puter_science)
With a few gotchas - full unification algorithm is really slow in the degenerate case and does not really work in languages like Ruby because variance issues. For example, if you have:
a = b
In normal unification algorithm, if b is of type X, it can logically constrain a to be of type X as well. But in Ruby, b is not just of type X, but of every class X inherits from including Object. Thus a cannot logically be constrained any further from this alone. In fact, just treating everything as an Object satisfies every constraint - it's just not strict enough. There are other approaches but they all involve searching through the constraint space as in unification. A more opportunistic algorithm will try to assume that a is X and see if everything can be unified, then gradually relax. But even a simple assignment (because assignment is covariant, see:
http://en.wikipedia.org/wiki/Covaria...puter_science)) screws up complete type inference, whereas in languages without subtyping, all operations and functions are invariant, which allows for full unification.
In Ruby, there are a few things that have a meaningful static type - self, classes, modules, literals, lambdas and methods but by and large most Ruby constructs cannot be constrained except with type inference. And because there are a few show stoppers (covariance/contravariance), complete type inference simply isn't possible and we're mostly in the realm of guessing.
I don't have any experience with RubyMine, but not only is the problem theoretically intractable, the general state of the art in type inference for dynamic languages is quite poor (I do read these papers). This is why a lot of research is going into optional typing. So I think when you're saying it catches wrong method names and wrong # of arguments, you're probably saying that it can check if some method names are literally not used anywhere and thus cannot possibly apply to the given object. I'm sure it can in some limited cases, figure out the actual object type too. But this is extremely trivial and quite frankly almost never happens to me in any language even without any IDE assistance. And in a large codebase, lots of random wrong method names will be actual method names somewhere else, allowing you to proceed. What you do want to check is whether you have the right object in the first place and no, despite your protestations, this is virtually impossible in Ruby without huge amounts of annotations.
Last edited by candybar; 03-05-2014 at 04:22 PM.