Sorbet - Making Ruby Statically Typed
Sorbet - Making Ruby Statically Typed
Written by Nikos Vaggalis   
Wednesday, 04 July 2018

Stripe's Sorbet type checker aims to achieve what Typescript has done for JavaScript; inject static typing to a dynamical language.

But let's start with the basics; what's so wrong with dynamically typed systems that statically type ones, full or partial, are so desirable.

Back in early 2010, I Programmer ran my in-depth article series, Type System Demystified (Part 1, Part 2, Part 3) on the big face-off between types systems (static vs dynamic, strong vs weak), detailing both their hindrances as well as their merits. While things have moved on, the principles I outlined in the articles remain, and their applicability to JavaScript has even been referred to in a 2013 thesis "Loading match and drawing information using node.js - A Work Performed at the Company Svenska" done at the Swedish KTH Royal Institute Of Technology.

What it mostly comes down to is that declaring types leads to fewer runtime errors, but then again that's trading productivity for safety; try to parse an XML file in Java instead of in Perl. You see where this is going, but the truth is that the trend is moving towards mixed or gradual type systems, such as those endorsed by Perl 6, or statically typed systems with type inference, such as those of Haskell.

Sorbet is actually split into two type checker counterparts, dynamic and static. In taking inspiration from RDL, another lightweight system for adding types, type checking and contracts to Ruby, it adopts a hybrid approach, enforcing type checking at runtime with type annotations being represented as a DSL, and statically checking the code and method signatures.

 

 

Its difference from Typescript is that in Sorbet there is no compilation phase or transpill and, since Stripe's codebase is huge, Sorbet's type system should had been made compatible with existing code and libraries to allow for gradual adaptation.

Other properties outlined by Dmitry Petrashko, the developer at Stripe  who is involved in the core project, are:

  • is ridiculously fast, 100k lines per second per core, scaling up to 64 cores

  • written in modern C++

  • the entire thing is designed with nice error messages in mind

  • local type inference, no need to declare local variables

  • non-nullable types by default

  • smart control-flow dependent typing

  • union and intersection types

At the moment, Sorbet is being used internally at Stripe, with developers optionally joining in, but the long term plans are to open source it. Much is not yet still known, but for the time being the core devs have prepared an online playground to get a feel of what's in stock.

Visit https://sorbet.run/ for more.

stripsq

More Information

RubyKaigi 2018-A practical type system for Ruby at Stripe

Related Articles

Type Systems Demystified part 1

Type Systems Demystified part 2 - Weak typing

Type Systems Demystified part 3 - Strong typing

Exposing The Most Frequent Mistakes In Programming

Pro DLR in .NET 4.0
IronJS - In Conversation with Fredrik Holmström

To be informed about new articles on I Programmer, sign up for our weekly newsletter, subscribe to the RSS feed and follow us on, Twitter, FacebookGoogle+ or Linkedin.

 

Banner


Breaking Enigma Code In Minutes
27/06/2018

Using AI processes across 2,000 DigitalOcean servers, engineers at Enigma Pattern accomplished in 13 minutes and at a cost of just $7 the feat for which Alan Turing and Gordon Welchman, work [ ... ]



Apache Phoenix Now HBase 2.0 Compatible
20/07/2018

Apache Phoenix 5.0 has been released. This is a major version upgrade to bring the compatibility for HBase to 2.0+, and to support Apache Hadoop 3.0.


More News

justjsquare

 



 

Comments




or email your comment to: comments@i-programmer.info

Last Updated ( Wednesday, 04 July 2018 )
 
 

   
Banner
RSS feed of news items only
I Programmer News
Copyright © 2018 i-programmer.info. All Rights Reserved.
Joomla! is Free Software released under the GNU/GPL License.