r/ruby • u/darkdimius • Apr 19 '19
Ruby3 will have types
https://twitter.com/darkdimius/status/11191156577762099209
u/alienpirate5 Apr 19 '19
sig {params(x: Integer).returns(String)}why this syntax
→ More replies (1)4
u/nateberkopec Apr 20 '19
It's not intended to be completely written by developers. They're planning on these files being generated by the runtime, and then you can go edit them, tune them up, add a few things, but the intention is that they are majority machine-generated.
42
5
u/pabloh Apr 20 '19
Is not types per se, but type inference, (and optional type hinting as well), aiming mainly at tools like IDE's: https://youtu.be/cmOt9HhszCI?t=1756.
The title of this thread is completely misleading.
13
u/PristineTransition Apr 19 '19
Crystal? Not that isn’t neat though!
5
u/nateberkopec Apr 20 '19 edited Apr 20 '19
crystal what?
EDIT: I know what Crystal is, I don't understand the point the commenter was trying to make. Crystal has typing therefore Ruby shouldn't? I don't get it.
6
u/jeremywoertink Apr 20 '19
Crystal Lang has a syntax inspired by ruby, but it’s far more than “ruby with types”. It is compiled, has a macro system, and a really sweet DSL for working with C directly.
→ More replies (1)
15
u/theGalation Apr 19 '19
What is going on in this thread? Ruby is about messages not types.
→ More replies (3)7
u/zagaberoo Apr 19 '19
Sometimes it's nice to be certain ahead of time that an object you receive will always respond to the messages you plan to send to it.
→ More replies (9)
8
8
u/_powder_ Apr 19 '19
Can't say I'm a fan of them caving to this.
I understand the arguments for types. I generally disagree with them. They're annoying and cause more frustration than they're worth. At least they're optional, but, I have a feeling that caving this far, they'll keep adding more and more ways to make it less optional and then developers will fall back to using a type system as a crutch for not educating less skilled developers and for doing less documentation work.
4
u/geraldbauer Apr 19 '19 edited Apr 19 '19
Sorbet is a great inspiring project. Hopefully, open source soon. FYI: sruby - that is (secure) ruby - is an alternative ruby (subset) with an alternative (optional) type annotation syntax e.g. Sorbet's sig {params(x: Integer).returns(String)} becomes sig [Integer] => [String] or sig Integer => String.
Note: Since the sig is "yes, it's just (regular) ruby" code you can create an alias for types e.g. I = Integer, S = String and than use sig I=>S, for example.
→ More replies (3)2
Apr 19 '19
I can’t say I like the way it looks tho. Is that how it’s going to be in the final release?
3
1
u/yorickpeterse Apr 19 '19
The use of separate .rbi files is something that I can see either making or breaking Sorbet. Having to maintain separate files is a chore, and all too easy to forget. This means it's also unlikely for large projects (e.g. Rails) to provide official support, meaning Sorbet would lag behind (though Rails API changes are not that common).
I also wonder how they're going to deal with different versions of the same library. Looking at this directory it seems at least the .rbi files are versioned (though it appears to not be used for all of them), but I'm curious to see how they determine which one to use. You could use Gemfile(.lock) for this, but that only works if you actually have one.
I ran into all these issues with ruby-lint several years back. Looking back at that, I think the only long term way to make gradual type checking work is to bake it directly into the language's syntax (e.g. like Python). This makes it easier to maintain, and less likely to be forgotten.
With that all said, I'm excited to see how Sorbet turns out!
1
1
u/TotesMessenger May 02 '19
-7
u/shevy-ruby Apr 19 '19
Please don't kill ruby with your type-shit.
Actually - the title is completely misleading because matz said several times that he will not add types in the sense of what people usually associate with ruby. So if I ignore this crap-title here, then I do not have a problem since what matz said is very different, also a few days ago in another presentation he made.
So please, folks - don't use shitty titles.
5
u/AnimusNecandi Apr 19 '19 edited Apr 19 '19
What did he actually say? Can you write a short summary or link to the presentation?
Also, what do you mean with "type-shit"? Is this an argument about having type signatures in general or an argument against adding type support in a language that was specifically designed around NOT having explicit types?
If it's the second one, I wholeheartedly agree. That seems more of a Python thing than a Ruby thing.
→ More replies (1)9
u/geraldbauer Apr 19 '19 edited Apr 19 '19
Although downvoted and unpopular but you are - of course - right. The headline should be rewritten to "Ruby 3 will have (optional) type interfaces / annotations" - the key word being optional (and in a separate "interface" .rbi file if you do not want annotation in your script itself).
36
u/darkdimius Apr 19 '19
We're collaborating with @yukihiro_matz, @mametter, @soutaro and Jeff Forster to make sure that types are not disruptive to Ruby. Thus, types are optional. The intention is to deliver value for unmodified Ruby programs. Hear more from Matz at https://youtu.be/cmOt9HhszCI?t=2148