←back to thread

511 points mootrichard | 1 comments | | HN request time: 0.264s | source
Show context
swagonomixxx ◴[] No.23991156[source]
I haven't used Ruby in ages but this seems like a really odd way to incorporate type hints in the language.

I much prefer the Python 3+ approach of type annotations in source code.

I can't imagine having to look at a separate file just to figure out what the type of something is. You may say "tooling will fix this" but it's just far less overhead for everyone at the end of the day to just make annotations in source.

My more existential question is, is there really an advantage to doing static type checking in Ruby?

When I was doing Ruby, the way you can change objects on the fly, add methods on the fly, the vast amounts of metaprogramming, are types at "compile" (I know, not really) time really the same as types at runtime?

Like, it might be nice to get some autocomplete, but AFAIK tools already do that (RubyMine, others).

replies(5): >>23991225 #>>23991242 #>>23991244 #>>23991252 #>>23991292 #
1. nicoburns ◴[] No.23991292[source]
> I can't imagine having to look at a separate file just to figure out what the type of something is. You may say "tooling will fix this" but it's just far less overhead for everyone at the end of the day to just make annotations in source.

TypeScript has this functionality (in addition to being able to write actually TypeScript files with inline annotations. The big advantage is being able to provide 3rd party type definitions for libraries that don't provide them and aren't interested in using them. This allowed TypeScript to bootstrap decent library support well before it was popular enough that the mainstream was considering adopting it, and this in turn enabled widespread adoption.

> My more existential question is, is there really an advantage to doing static type checking in Ruby? When I was doing Ruby, the way you can change objects on the fly, add methods on the fly, the vast amounts of metaprogramming, are types at "compile" (I know, not really) time really the same as types at runtime?

Again, I think TypeScript shows that there is. Sure, there are times when you want to do super-dyanamic stuff. And you can opt out of type checking using the "any" type in those cases. But a lot of the time you're not doing anything complicated, and you just want a compile-type check that ensures you're passing the correct type to the function you're calling.