B2T2 icon indicating copy to clipboard operation
B2T2 copied to clipboard

[WIP] Ruby Implementation

Open robertDurst opened this issue 1 year ago • 4 comments

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

robertDurst avatar Apr 09 '23 22:04 robertDurst

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!

bennn avatar Apr 10 '23 17:04 bennn

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).

bennn avatar Apr 12 '23 14:04 bennn

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".

robertDurst avatar Apr 16 '23 15:04 robertDurst

It was fairly straight forward to add tests for QuizScoreFilter and BrownJellyBeans, so that's a plus. However, the following has become clear:

  1. my implementation is inconsistent between class methods and module methods, i.e. nrows is an instance method for tables while header is a module method. This confuses me when I try to use them for the example programs...
  2. talking about confusion, my error messages are trash. If Ruby didn't have stack traces I'd have almost no idea which require or ensure was violated
  3. 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)

robertDurst avatar Apr 22 '23 19:04 robertDurst