-
Notifications
You must be signed in to change notification settings - Fork 516
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
Attempting to sorbetize Diff::LCS #3252
Comments
Ack, thank you.
You should be able to unblock yourself by using
The decision that we have made when developing Sorbet is that passing arguments to methods that aren't used is a smell. It leads to confusion of "what does this method need" and thus "what does it do/what does it guarantee". I understand that with a smaller and well understood codebase that doesn't change much, these may not sound like an issue, but with dozens millions of lines of code that evolves quickly these are important concerns to address.
We believe this is valid error because
Indeed, it might be too strict and the backdoor is
We went back & forward on this one in early days of Sorbet. At this point, it's very unlikely we'll add structural types. We have found that for existing libraries using
TBH, we aren't a good place to ask: Stripe does not use gems(we are a monorepo place). AFAIK Shoppify was working on sharing how they use gems in their systems(that, if I'm not mistaking, can be summarized by |
Thank you for the feedback! Feel free to open bugs if they are worth tracking separately. |
I’m exploring Sorbet by attempting to apply it to Diff::LCS at halostatue/diff-lcs#67. Even if I get it working, it won’t be merged in the current release version because Diff::LCS has a wide support range (1.8.7 to current Ruby). I should have been committing each set of successful changes as different commits, but I didn’t.
I have turned on
typed: true
in a few files, but the latest file that I added it to (lib/diff/lcs.rb
) appears to have some likely unfixable issues with how I understand Sorbet.Here’s some general feedback:
Tuple specifications are useful, especially for type aliases and what would have been
*args
. https://github.com/halostatue/diff-lcs/blob/sorbet/lib/diff/lcs/change.rb#L10-L16I originally had these constructors as
def initialize(*args)
, then I shifted to my current form withdef initialize(action, position, element, *)
. Sorbet didn’t like the last argument without a specification (even though that’s Ruby for “I really don’t care”), so I had to give this throwaway arg a name (_
). It would be nice to be able to recognize bare*
and**
as the throwaway values they are.Dynamic splats. I had to change these from dynamic splats to explicit parameter splits because Sorbet didn’t like dynamic splats (the code here was previously
*(arr[0...3])
). https://github.com/halostatue/diff-lcs/blob/sorbet/lib/diff/lcs/change.rb#L74-L85Unsupported method
undef
(quick bug report: typo here,Unsuppored method
). I could this by creating aDiff::LCS::AbstractChange
class that doesn’t containposition
orelement
, but this is code that I started in ~2004 or so. https://github.com/halostatue/diff-lcs/blob/sorbet/lib/diff/lcs/change.rb#L139-L144This seems fairly reasonable to me, but I will acknowledge that this may be a code smell.
Diff::LCS.diff
, etc.) it can also be mixed into random access sequences (e.g., Array or String). So the following errors don’t really make sense to me, because the Diff::LCS module itself should notinclude Kernel
.SequenceT = T.type_alias { T.any(Diff::LCS, Enumerable, String) }
, but it’s not a correct alias, and it’s not correct. The code mentioned in the error below is suboptimal because it uses.count
(it had been using.size
, which is the correct type). What I need to say here is something that amounts to:#size
and#[]
(and probably#[]=
, but I’m not 100% sure; it also needs to support#[]/#[]=
in the same way that Array does, for replacement or insertion). Really what I’m looking for is something trait-ish, but more duck typing than the name typing/resolution here. I’m really not sure how to indicate this. I could do some runtime checking ofincluded
on Diff::LCS to make sure that#size
,#[]
, and#[]=
are defined on the class, but that doesn’t help with Sorbet.This is also currently blocking me because I’ve gone from 2 errors (and tests pass) to 89 errors and the tests don’t look like they’re going to pass.
require 'sorbet-runtime'
in our tests? Should we somehow create .rbi files and leave our code unannotated otherwise?There are other errors, but this is by and large the stuff that’s currently blocking me with no clear way forward.
The text was updated successfully, but these errors were encountered: