Hacker Newsnew | past | comments | ask | show | jobs | submitlogin



So many JS projects are switching to TS, but AFAIK the same isn't happening within Ruby, which reduces some of the type-checking benefit.

Also, this is subjective but I don't like the syntax.

> Sorbet is 100% compatible with Ruby. It type checks normal method definitions, and introduces backwards-compatible syntax for method signatures.

I would have preferred if they had introduced a compile step the way typescript does, and provided a TS-like syntax. I find the current version hard to read.


> So many JS projects are switching to TS, but AFAIK the same isn't happening within Ruby

The sheer propagation of JS might have something to do with the big push to have some kind of typing. From my own experience, if I see ruby I know I can either re-write it or find an alternative in TS/JS.

The ubiquity of JS makes it more accessible, but I'm still trying to find reasons why one would choose Ruby.. I'm always a 'right tool for the job' but I don't know what the niche is.

Edit : My pedant in me :

> compile step the way typescript doe

Typescript transpiles to JS. I don't 'believe' there is a compilation step.


> > compile step the way typescript [does]

> Typescript transpiles to JS. I don't 'believe' there is a compilation step.

This is a common misconception. Transpiling is not something distinct from compiling. "Transpiler" is just a trendy name for a certain subset of compilers. Just because it compiles to another "high level" language doesn't mean it's not a compiler.

Every "transpiler" is a compiler.

Sources:

On BIX in the 1980s, when the only implementation of C++ was Cfront, which translated to C, I asked Bjarne Stroustrup if it was a preprocessor. He told me quite emphatically, "No, Cfront is a compiler." (I don't think the term "transpiler" was in common use at that time.)

The Wikipedia article on Cfront agrees:

> Cfront was the original compiler for C++ (then known as "C with Classes") from around 1983, which converted C++ to C

https://en.wikipedia.org/wiki/Cfront

More recently, and relevant to this discussion, the TypeScript team specifically calls tsc a compiler:

> Let’s get acquainted with our new friend tsc, the TypeScript compiler.

https://www.typescriptlang.org/docs/handbook/2/basic-types.h...

In fact, if you search that page for "pil", you will find nine references to "compile" and none for "transpile".


This is probably the best comment I've ever received here.

I've always seen them as different, but as you lay out, they're all doing the same thing in the end.. Thanks for making me a little more aware!


TS has a way to attach type annotations (.d.ts files) on top of existing JS code base, thus allowing for gradual migration and relatively peaceful coexistence. Same with Python: you can add type definitions on top of existing untyped code, as a separate package. In either case, types can be provided by a third party, e.g. yourself if you want to use a particular library and it still lacks typing support.

Does Sorbet offer something comparable? That would make adoption easier.


> Does Sorbet offer something comparable?

Yes, RBI files.


The problem (as TFA points out) is that most of the available options (including "a TS-like syntax") are already valid Ruby code.

I do agree with your first point that the lack of adoption of Sorbet among library maintainers negates some of the benefit of the type system (compared to TS). Seeing all those `T.untyped`'s in generated RBI files is a little scary :D.


> So many JS projects are switching to TS, but AFAIK the same isn’t happening within Ruby

TS has been around a lot longer than Sorbet and even moreso a lot longer than RBS.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: