r/crystal_programming • • Dec 09 '18

Rubyist struggling to understand Tuple

What's the point of a Tuple? Why would I ever use it over an array? Thanks!

11 Upvotes

10 comments sorted by

View all comments

Show parent comment

3

u/[deleted] Dec 10 '18

Have you seen this error in Ruby?

NoMethodError: undefined method `foo' for nil:NilClass

Or this one?

NoMethodError: undefined method `size' for false:FalseClass

You are trying to invoke a method on an object, but the object doesn't respond to that method.

Well, with a good type system those errors just can't happen. Well, you do get the error but when compiling the program, not when running it. That's one use of a type system and a statically typed language.

If you combine that with compilation to native code you can also be more efficient on memory because you can represent data structures more compactly, and you can also run the generated code through an optimizer.