top | item 43938994

(no title)

kodablah | 9 months ago

> I hate this idea that Ruby needs to be more like Python or Typescript

It's not be more like those, it's be more like helpful, author-friendly programming which is very much Ruby's ethos.

Every time I think about ripping out all of the RBS sig files in my project because I'm tired of maintaining them (I can't use Sorbet for a few reasons), Steep catches a `nil` error ahead of time. Sure we can all say "why didn't you have test coverage?" but ideally you want all help you can get.

discuss

order

PaulHoule|9 months ago

As a Pythoner the most direct value I get out of types is the IDE being smart about autocompletion, so if I'm writing

   with db.session() as session:
      ... use the session ...
I can type session. and the IDE knows what kind of object it is and offers me valid choices. If there's a trouble with it, it's that many Pythonic idioms are too subtle, so I can't fully specify an API like

   collection = db["some_collection"]
   collection.filter(lambda doc: doc["amount"].as_integer() > 500)
   collection.filter({"name": "whatever"})
   collection.filter({"field": lambda f: f["subfield"] = jsonb({"a":1, "b":"2})})
not to mention I'd like to be able to vary what gets returned using the same API as SQLAlchemy so I could write

   collection.filter(..., yield_per=100)
and have the type system know it is returning an iterator that yields iterators that yields rows as opposed to an iterator that yields rows. It is simple, cheap and reusable code to forward a few fetch-control arguments to SQLAlchemy and add some unmarshalling of rows into documents but if I want types to work right I need an API that looks more like Java.

maleldil|9 months ago

If I understand correctly, you can do this with overloads. They don't change the function implementation, but you can type different combinations of parameters and return types.

jimbokun|9 months ago

> Sure we can all say "why didn't you have test coverage?"

Well types are a form of test performed by the compiler.

jaredsohn|9 months ago

LLMs can probably help maintain them so that probably could be solved if you start using LLMs more.

This maybe already exists, but it would be nice if RBS or Sorbet had a command you could run that checks that all methods have types and tries to 'fix' anything missing via help from an LLM. You'd still be able to review the changes before committing it, just like with lint autofixing. Also you'd need to set up an LLM API key and be comfortable sharing your code with it.