Ruby Contracts: Best of Both Worlds

github logo ・1 min read

Among the many flame-wars in the developer community is the one about typing: static vs. dynamic.

In Ruby, we can have the best of both worlds, via gem contracts.

I was going to write about this powerful and flexible gem here, but on second thought will just link to this excellent page by the gem's author.

twitter logo DISCUSS (2)
markdown guide
 

I'd be interested to hear your experiences with the gem. Have you found it makes it easier to write applications? Do you write fewer tests? Do you use it everywhere in a codebase or only in particular places?

 

Thanks, Phil.

Using contracts makes it easier to catch bugs earlier: type error is caught immediately rather than further downstream where it's harder to debug.

For my large-scale in-house test frameworks, I've used it throughout.

For code that will become a gem, though, I don't use it, because it creates a dependency that the potential user might find unacceptable.

Classic DEV Post from Nov 2 '18

From homelessness to making six figures: On learning how to code.

A reflection of my life post High School.

Burdette Lamar profile image
Started out teaching English at Embry-Riddle. Graded 10,000 essays. Lesson learned. Became a mathematics teacher. Discovered computing. Never looked back.