rbs icon indicating copy to clipboard operation
rbs copied to clipboard

[Proposal] Make`-> void` return type annotation on `initialize` methods to be implicit

Open deepak-shopify opened this issue 5 months ago • 1 comments

I propose simplifying the RBS syntax for initialize methods by removing the required -> void return type annotation.

Current Syntax:

#: (a: String) -> void
def initialize(a:)
  @a = a
end

Proposed Syntax:

#: (a: String?)
def initialize(a:)
  @a = a
end

Why?

  1. Redundant - I was moving from Sorbet sigs to RBS style sigs and noticed that I was adding the -> void to every initialize method. Even though it makes sense from a completeness perspective, it seemed redundant to me and does not add any new information.

  2. Initialize is special - The initialize method is already special in Ruby - it's the only method that is called indirectly through new, cannot meaningfully return a value to its caller, has a fixed, unchangeable return behavior. Making its type signature special in RBS would accurately reflect its special status in the language.

  3. Comparison with other languages:

    Language Example Requires Return Type?
    Python (with types) def __init__(self, a: str): Optional
    TypeScript constructor(a: string) { } No
    Java public MyClass(String a) { } No
    C# public MyClass(string a) { } No
    Go N/A - uses factory functions instead N/A
    Ruby (current RBS) #: (a: String) -> void Yes

deepak-shopify avatar Aug 06 '25 15:08 deepak-shopify

👌 won’t hurt since RBS isn’t currently taking advantage of these round parentheses for a dedicated structure.

Edit: such as https://github.com/ruby/rbs/discussions/1639#discussioncomment-10153229? 🤔 Nah, they are compatible.

ParadoxV5 avatar Aug 06 '25 18:08 ParadoxV5