4 ms·
At its heart, Ruby just doesn’t do static analysis. Program behaviour is defined at runtime and at runtime only. This ethos is why method calls in the language
by gorgoiler 3y ago
At its heart, Ruby just doesn’t do static analysis. Program behaviour is defined at runtime and at runtime only. This ethos is why method calls in the language are implemented with message passing and also why everything is a mutable instance of Object.
The behaviour of a Ruby program, right down to the types and methods available, is only defined by running the program itself. It allows for all the glorious freedom of meta programming for which the language became famous as well as the often times inscrutability of the source code.
With a language like Python, the source code at the start bears a good resemblance to the structure of the program when any particular function executes.
With Ruby, the source code at the start of a program is merely a hint as to what the ObjectSpace will contain when your particular function ends up being called!
- kazinator 3y agoThere is virtually no difference in this regard between Ruby and Python. I can swap those two words in your comment without affecting its quality.
- gorgoiler 3y agoIn my experience most Python I see is amenable to static analysis and type checking. It’s possible to do the same with some Ruby, but the language is designed to make it very easy to programmatically create new types. Do you not find that this drastically reduces the effectiveness and coverage of Ruby type checkers?
- kazinator 3y agoCreating a new class in Python at run time is pretty easy with the three-argument form of the type function: >>> NewClass = type('NewClass', (), {'foo':42}) >>> x = NewClass() >>> x.foo 42