B2T2
B2T2 copied to clipboard
[WIP] Ruby Implementation
We are interested in using a dynamic language like Ruby to implement B2T2. I am personally interested in also briefly exploring the Sorbet static type checker as I go here. I think it might help me reason about the Table API by allowing me to decorate with types.
Please note: until this is no longer a draft, consider this a work in progress that is messy, unorganized, and likely not a proper or correct representation of the final pull request.
Live List of Unknowns
- [x] ~what do you actually check-in when using Sorbet? (i.e. how do I reduce the 64k diffs 🤦)~ no Sorbet for now
- [x] ~for all r in rs, schema(r) is equal to schema(t1) --> this seems to imply you can call schema on a row and a table?~ consider adding a schema to each row, or having some link between row and schema
- [x] ~is a module a more accurate representation of the Table API? Or can I just create class methods?~ mostly classes with possible a TableAPI module, we'll see how this pans out
Hello Rob, welcome!!
what do you actually check-in when using Sorbet?
Start with just the source code and a README with pointers for installing Sorbet.
We'll test the instructions before merging to see if it makes sense to add more code.
is a module a more accurate representation of the Table API? Or can I just create class methods?
Class methods are fine, go for it!
for all r in rs, schema(r) is equal to schema(t1) --> this seems to imply you can call schema on a row and a table?
Yep.
Though, another option might be to not have row schemas but check somehow that the result table (after adding a row) is correct.
Pyret rows come with schemas (link).
Sure, Ruby is dynamic... but come on, no Boolean class :(
true.class = TrueClass
false.class = FalseClass
Thus, we cannot really enforce sort on Boolean
super cleanly...
StackOverFlow pointed out this can be solved by monkey patching in Boolean
as so:
module Boolean
end
class TrueClass
include Boolean
end
class FalseClass
include Boolean
end
I added this because it irked me. This may begin toeing the line between "implementing B2T2 for Ruby" and "getting Ruby to work with B2T2".
It was fairly straight forward to add tests for QuizScoreFilter
and BrownJellyBeans
, so that's a plus. However, the following has become clear:
- my implementation is inconsistent between class methods and module methods, i.e.
nrows
is an instance method for tables whileheader
is a module method. This confuses me when I try to use them for the example programs... - talking about confusion, my error messages are trash. If Ruby didn't have stack traces I'd have almost no idea which
require
orensure
was violated - I need a table encoding helper class. Creating the table objects by hand (well... I admit GitHub CopPilot has actually helped a ton here) is painful and error prone (errors are almost more confusing when GitHub CoPilot generates seemingly correct text)