From: shevegen@... Date: 2014-09-30T13:10:25+00:00 Subject: [ruby-core:65329] [ruby-trunk - Feature #9999] Type Annotations Issue #9999 has been updated by Robert A. Heiler. I like the principal idea behind it. For instance, today I wrote ruby code like this (yes, hate me for using set_ methods but I like it visually because my brain works that way): def set_be_verbose(i) @be_verbose = i end @be_verbose can only be true or false, and must never be any value. It can also only be modified through that accessor method above. I thought it would be nice if I could somehow tell ruby to check automatically. Of course I could check the input for FalseClass or TrueClass or something but I wondered if it would not be better to also provide an additional OPTIONAL way. At any rate, I like the idea behind this - my main concern is only the syntax. The syntax proposal: def connect(r -> Stream, c -> Client) -> Fiber I am sorry, that is awful. It would conflict with my ruby code (I do not use ->) and the intent is not clear at all to me. def connect(Stream r, Client c) -> Fiber This is a bit better but it also uses -> and thus it really is not good at all. If we would not have to be backwards compatible we could use @@ hehe :) At any rate, please consider the syntax! I picked ruby because it is by far the most elegant language out there (actually, that is not completely true, I picked ruby over python because of its philosophy from matz' old interview from back then at: http://www.artima.com/intv/ruby.html it really still is my favourite interview from matz hehe) ---------------------------------------- Feature #9999: Type Annotations https://bugs.ruby-lang.org/issues/9999#change-49144 * Author: Davide D'Agostino * Status: Assigned * Priority: Normal * Assignee: Yukihiro Matsumoto * Category: * Target version: ---------------------------------------- Hi all, I know @matz is interested in introducing **type annotations** in ruby. More here: https://bugs.ruby-lang.org/issues/5583 I think it's time for ruby to get this. Before working on a patch I would like to know: 1. Syntax of methods signatures 2. Syntax of variables guards (?) 3. Implementation For point **1** I was thinking in some like: ~~~ruby def connect(r -> Stream, c -> Client) -> Fiber def connect(Stream r, Client c) -> Fiber # quite sure this will make some reduce problems in the grammar ~~~ Before making a proposal consider: keyword arguments and default value collisions. Then for point **2** I'm not sure if we want also check assignments but as before a syntax could be: ~~~ruby r: Client = something # will throw an exception if something is not kind of Client ~~~ Finally, **implementation**. Do we want some in python style and then leave the programmer/library for the implementation **or** (and I'm for this) we want MRI do that, if so how? Cheers! DD p.s. Sorry if this issue was already discussed but I didn't find anything except the link posted. -- https://bugs.ruby-lang.org/