Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Ruby Implementation #44

Draft
wants to merge 43 commits into
base: main
Choose a base branch
from

Conversation

robertDurst
Copy link

@robertDurst robertDurst commented Apr 9, 2023

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

  • what do you actually check-in when using Sorbet? (i.e. how do I reduce the 64k diffs 🤦) no Sorbet for now
  • 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
  • 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

@bennn
Copy link
Member

bennn commented Apr 10, 2023

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
Copy link
Member

bennn commented Apr 12, 2023

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

require './table'
require './table_api'

RSpec.describe Basics do
Copy link
Author

@robertDurst robertDurst Apr 15, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These tests are, for the most part, literally testing the ruby core std lib methods themselves... not super practical, more so in the spirit of completeness.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Especially helpful as I re-org the files/classes to more closely adhere to the table api spec; helps with a test driven development approach.

@robertDurst
Copy link
Author

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
Copy link
Author

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants