Need advice about which tool to choose?Ask the StackShare community!

Crystal

339
350
+ 1
286
Ruby

41.7K
21.5K
+ 1
4K
Add tool

Crystal vs Ruby: What are the differences?

Introduction

Crystal and Ruby are both popular programming languages that share similarities given their heritage from the Ruby programming language. However, there are several key differences that set them apart from each other. This article will delve into the major differences between Crystal and Ruby, highlighting their distinctions and providing a comprehensive understanding of each language.

1. Compilation vs Interpretation:

Crystal is a compiled language, which means that it goes through a separate compilation step before being executed. This allows for better performance and optimization since the code can be transformed into machine-level instructions. In contrast, Ruby is an interpreted language, where the code is executed directly without a prior compilation step. This difference in the execution model leads to varying performance characteristics between the two languages.

2. Static Typing vs Dynamic Typing:

One of the fundamental differences between Crystal and Ruby lies in their typing systems. Crystal is statically typed, meaning that variables are required to have a specific type assigned at compile-time. This enables compile-time type checking and enhances code reliability and performance optimizations. On the other hand, Ruby is dynamically typed, allowing variables to hold values of any type at runtime. While dynamic typing offers flexibility and ease of use, it can introduce potential runtime errors due to type mismatches.

3. Memory Management:

Crystal adopts manual memory management using an automatic reference counting (ARC) system. This means that developers have to explicitly manage memory by allocating and releasing resources. In contrast, Ruby utilizes a garbage collector that automatically manages memory allocation and object deallocation. The garbage collector tracks objects that are no longer in use and frees up the associated memory. This distinction affects memory usage, performance, and the developer experience in terms of memory management.

4. Concurrency and Parallelism:

Another significant difference between Crystal and Ruby is their approaches to concurrency and parallelism. Crystal provides built-in support for lightweight fibers, which can be viewed as cooperative threads, allowing developers to write concurrent code with ease. Additionally, Crystal has a built-in concurrent programming construct called Channel, which facilitates communication between fibers. Conversely, while Ruby offers concurrency mechanisms like threads and processes, it lacks native support for lightweight fibers and requires using external libraries for achieving concurrent programming.

5. Performance:

Due to its compilation process and static typing, Crystal generally offers superior performance compared to Ruby. The pre-compiled nature of Crystal's code allows the compiler to perform various optimizations, resulting in faster execution. Additionally, Crystal's static typing eliminates the runtime type checks present in Ruby, further enhancing performance. These performance advantages make Crystal a compelling choice for high-performance applications or areas where speed is crucial.

6. Interoperability:

Although Crystal and Ruby share a common syntax, they are not completely compatible with each other. While it is possible to call Crystal code from Ruby and vice versa, there are certain limitations and considerations. Crystal can directly use Ruby libraries through its C binding compatibility. However, due to the differences in their respective type systems and execution models, interoperability between the two languages can be challenging and may require additional work to bridge the gap effectively.

In Summary, Crystal and Ruby differ in terms of their compilation models, typing systems, memory management, concurrency mechanisms, performance, and interoperability. These distinctions make each language suitable for different use cases and development scenarios.

Decisions about Crystal and Ruby
Ing. Alvaro Rodríguez Scelza
Software Systems Engineer at Ripio · | 12 upvotes · 375.7K views

I was considering focusing on learning RoR and looking for a work that uses those techs.

After some investigation, I decided to stay with C# .NET:

  • It is more requested on job positions (7 to 1 in my personal searches average).

  • It's been around for longer.

  • it has better documentation and community.

  • One of Ruby advantages (its amazing community gems, that allows to quickly build parts of your systems by merely putting together third party components) gets quite complicated to use and maintain in huge applications, where building and reusing your own components may become a better approach.

  • Rail's front end support is starting to waver.

  • C# .NET code is far easier to understand, debug and maintain. Although certainly not easier to learn from scratch.

  • Though Rails has an excellent programming speed, C# tends to get the upper hand in long term projects.

I would avise to stick to rails when building small projects, and switching to C# for more long term ones.

Opinions are welcome!

See more
Timm Stelzer
VP Of Engineering at Flexperto GmbH · | 18 upvotes · 637.8K views

We have a lot of experience in JavaScript, writing our services in NodeJS allows developers to transition to the back end without any friction, without having to learn a new language. There is also the option to write services in TypeScript, which adds an expressive type layer. The semi-shared ecosystem between front and back end is nice as well, though specifically NodeJS libraries sometimes suffer in quality, compared to other major languages.

As for why we didn't pick the other languages, most of it comes down to "personal preference" and historically grown code bases, but let's do some post-hoc deduction:

Go is a practical choice, reasonably easy to learn, but until we find performance issues with our NodeJS stack, there is simply no reason to switch. The benefits of using NodeJS so far outweigh those of picking Go. This might change in the future.

PHP is a language we're still using in big parts of our system, and are still sometimes writing new code in. Modern PHP has fixed some of its issues, and probably has the fastest development cycle time, but it suffers around modelling complex asynchronous tasks, and (on a personal note) lack of support for writing in a functional style.

We don't use Python, Elixir or Ruby, mostly because of personal preference and for historic reasons.

Rust, though I personally love and use it in my projects, would require us to specifically hire for that, as the learning curve is quite steep. Its web ecosystem is OK by now (see https://www.arewewebyet.org/), but in my opinion, it is still no where near that of the other web languages. In other words, we are not willing to pay the price for playing this innovation card.

Haskell, as with Rust, I personally adore, but is simply too esoteric for us. There are problem domains where it shines, ours is not one of them.

See more
Andrew Carpenter
Chief Software Architect at Xelex Digital, LLC · | 16 upvotes · 421.1K views

In 2015 as Xelex Digital was paving a new technology path, moving from ASP.NET web services and web applications, we knew that we wanted to move to a more modular decoupled base of applications centered around REST APIs.

To that end we spent several months studying API design patterns and decided to use our own adaptation of CRUD, specifically a SCRUD pattern that elevates query params to a more central role via the Search action.

Once we nailed down the API design pattern it was time to decide what language(s) our new APIs would be built upon. Our team has always been driven by the right tool for the job rather than what we know best. That said, in balancing practicality we chose to focus on 3 options that our team had deep experience with and knew the pros and cons of.

For us it came down to C#, JavaScript, and Ruby. At the time we owned our infrastructure, racks in cages, that were all loaded with Windows. We were also at a point that we were using that infrastructure to it's fullest and could not afford additional servers running Linux. That's a long way of saying we decided against Ruby as it doesn't play nice on Windows.

That left us with two options. We went a very unconventional route for deciding between the two. We built MVP APIs on both. The interfaces were identical and interchangeable. What we found was easily quantifiable differences.

We were able to iterate on our Node based APIs much more rapidly than we were our C# APIs. For us this was owed to the community coupled with the extremely dynamic nature of JS. There were tradeoffs we considered, latency was (acceptably) higher on requests to our Node APIs. No strong types to protect us from ourselves, but we've rarely found that to be an issue.

As such we decided to commit resources to our Node APIs and push it out as the core brain of our new system. We haven't looked back since. It has consistently met our needs, scaling with us, getting better with time as continually pour into and expand our capabilities.

See more
Thomas Miller
Talent Co-Ordinator at Tessian · | 16 upvotes · 243K views

In December we successfully flipped around half a billion monthly API requests from our Ruby on Rails application to some new Python 3 applications. Our Head of Engineering has written a great article as to why we decided to transition from Ruby on Rails to Python 3! Read more about it in the link below.

See more
Mike Fiedler
Enterprise Architect at Warby Parker · | 3 upvotes · 236K views

When I was evaluating languages to write this app in, I considered either Python or JavaScript at the time. I find Ruby very pleasant to read and write, and the Ruby community has built out a wide variety of test tools and approaches, helping e deliver better software faster. Along with Rails, and the Ruby-first Heroku support, this was an easy decision.

See more
Manage your open source components, licenses, and vulnerabilities
Learn More
Pros of Crystal
Pros of Ruby
  • 38
    Compiles to efficient native code
  • 36
    Ruby inspired syntax
  • 32
    Performance oriented - C-like speeds
  • 23
    Gem-like packages, called Shards
  • 20
    Can call C code using Crystal bindings
  • 18
    Super Fast
  • 18
    Typed Ruby <3
  • 17
    Open Source
  • 14
    Minimal Runtime
  • 11
    Cute
  • 9
    Clean code
  • 9
    Concurrent
  • 9
    Productive
  • 4
    Great community
  • 2
    Powerful
  • 2
    Program compiled into a single binary
  • 2
    Simplicity
  • 2
    Meta-Programming (via Macros)
  • 2
    Feels like duck types, safe like static types
  • 2
    Null Safety
  • 2
    Type inference
  • 1
    Has builtin LLVM support library
  • 1
    Statically linked binaries that are simple to deploy
  • 1
    Fun to write
  • 1
    High-performance
  • 1
    Simple, minimal syntax
  • 1
    Compile time statically safe macros
  • 1
    Concise
  • 1
    Statically Safe Monkey Patching
  • 1
    Fibers
  • 1
    Spawn
  • 1
    Meta-programming
  • 1
    Productivity
  • 1
    Elegant
  • 1
    Cross-platform
  • 605
    Programme friendly
  • 536
    Quick to develop
  • 490
    Great community
  • 468
    Productivity
  • 432
    Simplicity
  • 273
    Open source
  • 234
    Meta-programming
  • 207
    Powerful
  • 156
    Blocks
  • 139
    Powerful one-liners
  • 69
    Flexible
  • 58
    Easy to learn
  • 51
    Easy to start
  • 42
    Maintainability
  • 37
    Lambdas
  • 30
    Procs
  • 21
    Fun to write
  • 19
    Diverse web frameworks
  • 13
    Reads like English
  • 10
    Makes me smarter and happier
  • 9
    Rails
  • 8
    Very Dynamic
  • 8
    Elegant syntax
  • 6
    Matz
  • 5
    Object Oriented
  • 5
    Programmer happiness
  • 4
    Elegant code
  • 4
    Generally fun but makes you wanna cry sometimes
  • 4
    Friendly
  • 4
    Fun and useful
  • 3
    Easy packaging and modules
  • 3
    There are so many ways to make it do what you want
  • 2
    Primitive types can be tampered with

Sign up to add or upvote prosMake informed product decisions

Cons of Crystal
Cons of Ruby
  • 13
    Small community
  • 3
    No windows support
  • 1
    No Oracle lib
  • 7
    Memory hog
  • 7
    Really slow if you're not really careful
  • 3
    Nested Blocks can make code unreadable
  • 2
    Encouraging imperative programming
  • 1
    No type safety, so it requires copious testing
  • 1
    Ambiguous Syntax, such as function parentheses

Sign up to add or upvote consMake informed product decisions

What is Crystal?

Crystal is a programming language that resembles Ruby but compiles to native code and tries to be much more efficient, at the cost of disallowing certain dynamic aspects of Ruby.

What is Ruby?

Ruby is a language of careful balance. Its creator, Yukihiro “Matz” Matsumoto, blended parts of his favorite languages (Perl, Smalltalk, Eiffel, Ada, and Lisp) to form a new language that balanced functional programming with imperative programming.

Need advice about which tool to choose?Ask the StackShare community!

What companies use Crystal?
What companies use Ruby?
Manage your open source components, licenses, and vulnerabilities
Learn More

Sign up to get full access to all the companiesMake informed product decisions

What tools integrate with Crystal?
What tools integrate with Ruby?

Sign up to get full access to all the tool integrationsMake informed product decisions

Blog Posts

Nov 20 2019 at 3:38AM

OneSignal

PostgreSQLRedisRuby+8
9
4698
Oct 24 2019 at 7:43PM

AppSignal

JavaScriptNode.jsJava+8
5
981
Jun 6 2019 at 5:11PM

AppSignal

RedisRubyKafka+9
15
1687
GitHubDockerReact+17
41
37057
What are some alternatives to Crystal and Ruby?
JavaScript
JavaScript is most known as the scripting language for Web pages, but used in many non-browser environments as well such as node.js or Apache CouchDB. It is a prototype-based, multi-paradigm scripting language that is dynamic,and supports object-oriented, imperative, and functional programming styles.
Git
Git is a free and open source distributed version control system designed to handle everything from small to very large projects with speed and efficiency.
GitHub
GitHub is the best place to share code with friends, co-workers, classmates, and complete strangers. Over three million people use GitHub to build amazing things together.
Python
Python is a general purpose programming language created by Guido Van Rossum. Python is most praised for its elegant syntax and readable code, if you are just beginning your programming career python suits you best.
jQuery
jQuery is a cross-platform JavaScript library designed to simplify the client-side scripting of HTML.
See all alternatives