Static Typing in Ruby 3.0

Static Typing in Ruby 3.0

Ruby is a dynamically typed language, which means the interpreter tries to infer the data type of variables and object properties at runtime. This generally leads to programs being more dynamic and easier (faster) to code, and the interpreter/compiler loading code faster.

This week, Ruby’s development team released the first preview build of their long-awaited major update to version 3.0!

Among the countless cool changes and additions — including some fantastic general performance boosts and a powerful new concurrency/parallel processing efficiency model — a new built-in language has emerged for static type definitions: Ruby (Type) Signature language, or RBS.

Static Typing

Ruby is a dynamically typed language, which means the interpreter tries to infer the data type of variables and object properties at runtime. This generally leads to programs being more dynamic and easier (faster) to code, and the interpreter/compiler loading code faster. However, the need for type inference and its associated costs, as well as the difficulty in detecting errors at compile time with dynamically typed code, have caused a modern programming trend to move towards statically typed languages.

Static typing makes the development experience much smoother. Bugs are far easier to detect, especially with modern IDEs and their linting as you write. For most statically typed languages, their more explicit nature leads to faster-compiled code (more efficient resulting machine code.)

Popular dynamically typed languages have begun to follow suit. Python’s typing library for optional static type definitions has gained significant traction since its introduction in Python 3.5. Microsoft’s statically typed JavaScript superset TypeScript has seen a meteoric rise in popularity in recent years and is basically an industry standard at this point.

Types in Ruby

With the upcoming version 3.0, Ruby has plans to integrate optional static typing as well!

The devs have created a “foundational type signature language” gem in the new version preview called RBS. The new .rbs files are analogous to TypeScript’s .d.ts type definition files. These files contain all your various modules’ type definitions. By keeping them in separate files, your actual Ruby code need not be changed and you can quickly and easily add the benefits of static types to your Ruby programs!

In addition to traditional type definition syntax that looks pretty much as you would expect a Ruby version to look, RBS also implements interfaces for safer “guided” Duck Typing, “union types,” and “method overloading” to account for non-uniform Ruby types, as well as a few other cool features.

typing programming software-engineering typescript ruby

Bootstrap 5 Complete Course with Examples

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

Building a simple Applications with Vue 3

Deno Crash Course: Explore Deno and Create a full REST API with Deno

How to Build a Real-time Chat App with Deno and WebSockets

Convert HTML to Markdown Online

HTML entity encoder decoder Online

Software Developer vs Software Engineer — Differences: Bogus or Real?

In this article, see if there are any differences between software developers and software engineers. What you’re about to read mostly revolves around my personal thoughts, deductions, and offbeat imagination. If you have different sentiments, add them in the comment section, and let’s dispute! So, today’s topic…

"Rewrite your Software," says Creator of Ruby on Rails

David Heinemeier Hansson is the creator of Ruby on Rails, co-founder & CTO of Basecamp, best-selling author, Le Mans class-winning race car driver, family man, frequent podcast guest, and inspirational conference speaker.

Functional Programming: Using the Functor Type Class in TypeScript

Functional Programming: Exploring the Functor type class and its use cases

Ruby: Fake Operators

In this post I’d like to discuss one of the more interesting aspects of the Ruby programming language, which is that most of the ‘operators’ in ruby are actually methods. Here is a list of some of the more common fake operators. What does this mean and why does it matter? It means that when you call one of the above ‘operators’, you are actually calling a method. This matters because each class can have its own implementation of a method, meaning the same method may behave differently depending on the class of the object it is called on.

How to Have a Solid Start in Software Engineering

How to Have a Solid Start in Software Engineering. My first ever software development project an A-Z programming experience!