# Optional static typing possible for Ruby?

**URL:** <https://www.ruby-forum.com/t/optional-static-typing-possible-for-ruby/67952>\
**Category:** Ruby\
**Created:** [September 8, 2006, 4:06am UTC](https://www.ruby-forum.com/t/optional-static-typing-possible-for-ruby/67952 "2006-09-08T04:06:46Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![magpie](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/45deac/32.png) [@magpie](https://www.ruby-forum.com/u/magpie)\
**Post date:** [September 8, 2006, 4:06am UTC](https://www.ruby-forum.com/t/optional-static-typing-possible-for-ruby/67952/1 "2006-09-08T04:06:46Z")

</div>

From [http://weblog.infoworld.com/udell/2006/09/06.html:](http://weblog.infoworld.com/udell/2006/09/06.html:)

“We saw a hint of this in episode 2 of The Screening Room, on Adobe  
Flex, when Christophe Coenraets talked about the value of ActionScript  
3’s optional static typing. “When you already know what your types  
should be, declare them,” he said. “When you don’t, don’t.” One  
language, two styles, complementary benefits.”

This makes a lot of sense to me. eg a function that processes strings  
need not accept anything else, would trap certain errors by declaring  
acceptable type(s) and would be easier for code completion in an IDE.

---

<div class="post-metadata">

**Author:** ![magpie](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/45deac/32.png) [@magpie](https://www.ruby-forum.com/u/magpie)\
**Post date:** [September 8, 2006, 4:18am UTC](https://www.ruby-forum.com/t/optional-static-typing-possible-for-ruby/67952/2 "2006-09-08T04:18:41Z")

</div>

On 9/7/06, Mr Magpie [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> acceptable type(s) and would be easier for code completion in an IDE.  
> There’s megabytes of discussion on this matter that extend far beyond  
> the earliest [ruby-forum.com](http://ruby-forum.com) presence here. Please search the archives  
> before bringing this sort of thing up.

Is a StringIO a String object or an IO object? (Hint: it inherits from  
neither.) Yet if someone were to put class-based typing (which is  
exactly what this is) on a method, they would prevent the use of  
StringIO if they wanted IO objects. Further, it is rare that a method  
needs _exactly_ one type of object unless it’s a custom object – and  
even then, it’s possible to simulate that a lot of the time.

Type in Ruby is not controlled by classes.

Thank Ghu.

-austin

---

<div class="post-metadata">

**Author:** ![magpie](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/45deac/32.png) [@magpie](https://www.ruby-forum.com/u/magpie)\
**Post date:** [September 9, 2006, 2:02pm UTC](https://www.ruby-forum.com/t/optional-static-typing-possible-for-ruby/67952/3 "2006-09-09T14:02:18Z")

</div>

This was pondered as a Ruby 2.0 feature. Haven’t seen wind of any  
concrete ideas yet.

Basically, people can -generally- agree (for given values of every word  
in this sentence) in the longwinded-threads that some form of  
contract-checking wouldn’t hurt, but that static typing wouldn’t work at  
times. And some alternative forms of contract checking were proposed.  
And many, many flames were exchanged.

David V.
