Live data from Hacker News

Consider Static Typing in Ruby

codon.com

1–10 of 37 posts

Re: Consider Static Typing in Ruby

#2
Another very interesting (and well-thought) article on the topic is Tony Arcieri's latest blog post: http://tonyarcieri.com/an-open-letter-to-matz-on-ruby-type-s....

I can't wait to see how this develops, the simple fact that people inside the Ruby community are willing to put all this on the table is a good sign about the dynamism of all involved.

Re: Consider Static Typing in Ruby

#4
So much of what makes Ruby Ruby is based on dynamic types. Is this going to be optional? I've been moving away from Ruby a bit over the years specifically because I want static typing, but I can't imagine that the majority of Ruby devs feel this way.

Also isn't Crystal basically a compiled, statically typed version of Ruby?

Re: Consider Static Typing in Ruby

#6
As a 10 years Rubyist I'm conflicted about this.

First, if I wanted to use a static typed language I have plenty of them to chose from, when I started using Ruby and more right now. One of the reasons I'm using Ruby is that it works well enough without having to tell types to the interpreter (which is already pretty strict about them because - example - it doesn't automatically cast strings and numbers into each other like JS and Perl do).

However, in some very rare cases an object without method M gets passed as argument where an object with method M is expected and the code fails at runtime. It would be nice to catch this in advance, but if the price to pay is to start declaring types like I did in C and Java, no thanks. The problems I had because of dynamic typing have not been big enough to go through all that pain again (and code pollution.)

We'll see what Matz ends up proposing to us, then we'll discuss it. I hope to be able to keep my code free from type declarations and optionally throw in some constraint when I really want to be sure that an object belongs to some class or has some methods. Nothing more.

Re: Consider Static Typing in Ruby

#7
OP missed some more development on recent gradual typing efforts in dynamic languages. I collected those links below when implementing gradual typing for perl5. perl5 is more lucky than ruby, since perl5 supports syntax for types in lexical variable declarations for decades already, and more via attributes.

http://www.typescriptlang.org/Content/TypeScript%20Language%... (microsoft's javascript with types)

https://code.facebook.com/posts/1505962329687926/flow-a-new-... (facebook's javascript with types)

https://github.com/rwaldron/tc39-notes/blob/master/es6/2015-... Soundscript, google's javascript with types

https://www.python.org/dev/peps/pep-0484/ (planned python with types)

http://www.mypy-lang.org/ (existing python with types)

https://news.ycombinator.com/item?id=8620129 (ruby 3.0 planned with types)

http://crystal-lang.org/ (a good existing ruby with types)

http://hacklang.org/ (facebook's php with types)

http://blog.pascal-martin.fr/post/in-favor-of-rfc-scalar-typ... (php 7 types overview)

https://wiki.php.net/rfc/scalar_type_hints (php 7)

https://wiki.php.net/rfc/return_types (php 7)

https://github.com/rurban/perl/blob/master/pod/perltypes.pod (perl5 inofficial)

Re: Consider Static Typing in Ruby

#8
post #4

So much of what makes Ruby Ruby is based on dynamic types. Is this going to be optional? I've been moving away from Ruby a bit over the years specifically because I want static typing, but I can't imagine that the majority of Ruby devs feel this way. Also isn't Crystal basically a compiled, statically typed version of Ruby?

Not really -- with strong typing you can still use duck typing.

Swift has a cool approach to this.

Re: Consider Static Typing in Ruby

#9
post #6

As a 10 years Rubyist I'm conflicted about this. First, if I wanted to use a static typed language I have plenty of them to chose from, when I started using Ruby and more right now. One of the reasons I'm using Ruby is that it works well enough without having to tell types to the interpreter (which is already pretty strict about them because - example - it doesn't automatically cast strings and numbers into each othe…

The bad things about Ruby are mostly Ruby cultural norms, like willy nilly metaprogramming often done by unskilled people, published as a gem, and used by many others, some of whom create useful gems.

Static typing would be a benefit. I think Matz realizes that with the rise of Javascript transpilers Ruby is going to have to fight hard to remain relevant. Give Swift a few more months and there is already a pretty solid language with ruby-like simplicity and a well designed type system.

Re: Consider Static Typing in Ruby

#10
post #8
post #4

So much of what makes Ruby Ruby is based on dynamic types. Is this going to be optional? I've been moving away from Ruby a bit over the years specifically because I want static typing, but I can't imagine that the majority of Ruby devs feel this way. Also isn't Crystal basically a compiled, statically typed version of Ruby?

Not really -- with strong typing you can still use duck typing. Swift has a cool approach to this.

Unless I read something wrong, the proposal was to add static typing not strong. Dynamic vs static, and strong vs weak are two different things, although the exact meaning of strong vs weak isn't really settled.

Many people already consider ruby to be pretty strongly typed. It's definitely already more strongly typed than javascript.

Post reply on HN