When static types make your code shorter

@EvanHahn was porting some Ruby code to Crystal and found that due to static typing, the Crystal code cam out 15% shorter.

My main takeaway was this: static typing gets a bad reputation for being verbose. That’s sometimes true! But sometimes, a static type system wins because it can prevent a hydra of impossible states.

There is quite an active comment thread on lobste.rs:

5 Likes

Indeed, there is a very active comment thread…twice as many comments as upvotes! :sweat_smile:

For a little more on my porting efforts, I wrote a short blog post introducing the project which might be interesting to Crystal programmers.

2 Likes

Ruby intentionally tries to avoid putting types in its code. The ruby core team’s answer is rbs and typeprof. The basic idea is to separate the type definition from the code, leaving the option of not writing types. Although rbs is not widely used, it is used by some companies. (Larger companies tend to prefer sorbet.) I mention these tools because some of you may not be aware of recent attempts in Ruby.