3 ms·
There are a few reasons this wouldn't work for Ruby, mainly the reliance on metaprogramming in some of the more popular libraries. For example, the ORM ActiveR
by maxfurman 6y ago
There are a few reasons this wouldn't work for Ruby, mainly the reliance on metaprogramming in some of the more popular libraries.
For example, the ORM ActiveRecord reads the database schema at runtime and generates the getters and setters for each column for the appropriate class. The class itself doesn't have any code listing these columns. Where would the inline annotation go?
- nerdponx 6y agoYou can do this in Python as well, see SQLAlchemy's "reflection" capability for instance. You can even generate annotations at runtime if you wanted to (but there wouldn't be much point). I'm pretty confused as to why you would want to have annotations baked into your source code anyway, if you are reading the database schema at runtime.
- maxfurman 6y agoFor static analysis, you'd want to know that foo.col_a is an integer, foo.col_b is a string that might be null, and foo.col_c is not valid.
- nerdponx 6y agoI know that, but are you going to read the database schema at "analysis time", i.e. before runtime and likely in a totally different environment from the runtime environment? IMO "reading the database schema at runtime" and "ahead-of-time static typing" are incompatible desires, except in a language that supports runtime access to the type checker.
- anamexis 6y agoThe inline annotation could go anywhere you want it to - in the Rails model example, in the model file. You just need a way to declare methods without defining them.