Learn Crystal - 10 Code Examples & CST Typing Practice Test
Crystal is a modern, statically typed, compiled programming language with syntax heavily inspired by Ruby. It aims to combine the efficiency and speed of compiled languages with the readability and productivity of Ruby, supporting type inference, concurrency, and high-performance applications.
Learn CRYSTAL with Real Code Examples
Updated Nov 20, 2025
Explain
Crystal compiles directly to native code for high performance.
It features static type checking with powerful type inference, reducing boilerplate.
Used for web development, CLI tools, system utilities, and high-performance applications.
Core Features
Classes, modules, structs, and enums
Generics and type inference
Error handling with exceptions
Compile-time macros
Standard library for networking, HTTP, JSON, and more
Basic Concepts Overview
Crystal syntax and expressions
Variables, types, and constants
Classes, structs, and modules
Methods, blocks, and lambdas
Error handling with `raise` and `rescue`
Project Structure
src/ (source code)
lib/ (dependencies via Shards)
spec/ (unit tests)
shard.yml (dependency config)
bin/ (compiled binaries)
Building Workflow
Write `.cr` source files
Manage dependencies with Shards
Compile using `crystal build file.cr`
Run compiled binary
Debug with compiler warnings and logging
Difficulty Use Cases
Beginner: CLI utilities and small scripts
Intermediate: web apps with Kemal or Amber
Advanced: concurrent microservices
Expert: system-level high-performance tools
Comparisons
Syntax similar to Ruby, but compiled and statically typed
Faster than interpreted languages like Ruby or Python
Less mature ecosystem than mainstream languages
Macro system allows metaprogramming unlike Go
Concurrency model simpler than full OS threads
Versioning Timeline
2011 - Crystal first introduced
2014 - Shards dependency manager released
2016 - Kemal web framework launched
2018 - Amber web framework stabilization
2020-2025 - Compiler improvements and ecosystem growth
Glossary
Shards: Crystal’s package manager
Fiber: lightweight concurrency primitive
Macro: compile-time code generator
Spec: built-in testing module
Type inference: compiler deduces variable types
Frequently Asked Questions about Crystal
What is Crystal?
Crystal is a modern, statically typed, compiled programming language with syntax heavily inspired by Ruby. It aims to combine the efficiency and speed of compiled languages with the readability and productivity of Ruby, supporting type inference, concurrency, and high-performance applications.
What are the primary use cases for Crystal?
Web applications (via Kemal, Amber frameworks). Command-line tools. Microservices and APIs. High-performance backend services. System utilities and scripting. Prototyping with production-ready performance
What are the strengths of Crystal?
High performance due to compilation to native code. Readable Ruby-like syntax. Strong static typing with minimal verbosity. Macros for metaprogramming and code reuse. Good concurrency model with lightweight fibers
What are the limitations of Crystal?
Smaller ecosystem than Ruby or Python. Slower compiler for large projects. Limited libraries for certain domains. Less community support compared to mainstream languages. Still maturing in tooling and IDE support
How can I practice Crystal typing speed?
CodeSpeedTest offers 10+ real Crystal code examples for typing practice. You can measure your WPM, track accuracy, and improve your coding speed with guided exercises.