small medium large xlarge

Programming Crystal: Create High-Performance, Safe, Concurrent Apps

by

Cover image for Programming Crystal

Programming Crystal

Create High-Performance, Safe, Concurrent Apps

by

Crystal is for Ruby programmers who want more performance or for developers who enjoy working in a high-level scripting environment. Crystal combines native execution speed and concurrency with Ruby-like syntax, so you will feel right at home. This book, the first available on Crystal, shows you how to write applications that have the beauty and elegance of a modern language, combined with the power of types and modern concurrency tooling. Now you can write beautiful code that runs faster, scales better, and is a breeze to deploy.

Choose Your Format(s)

  • $19.95 In Stock
    • Beta: What do I get?

  • Ebooks are DRM free.

  • Ebook delivery options.

  • The Paper Book will ship on 2019-01-10 (roughly).

About this Title

Skill-meter-3-6
Pages: 230 (est)
Published: 2019-01-10
Release: B3.0 (2018-11-02)
ISBN: 978-1-68050-286-2

Crystal is elegant to read and easy to program like Ruby, allowing full object-oriented development. Its compiler is powerful enough to nearly always infer the type of your variables. So you get the benefits of a statically typed language: more robust code, safety, and execution speed while still reaching high productivity in development. Null pointer exceptions as in JavaScript, Java, or C#, are a thing of the past: Crystal annihilates them, just like Rust.

Explore the building blocks and design of the language and how you can use the Crystal tool-chain to build and manage powerful applications. Harness the power of the macro system, as well as how to work with fibers and channels, making concurrency as easy as possible. Learn how to use the Kemal web framework and access databases and how to tap the potential of existing Crystal libraries. Find the spot that Crystal fills in today’s software world with real-world examples.

With Crystal, you can combine the best of both worlds: the high-level coding of dynamic languages and the safety and blazing performance of a natively compiled language.

What You Need

To develop in Crystal, you only need Crystal v 0.26, the latest version, a common text editor and a browser.

Contents & Extracts

This book is currently in beta, so the contents and extracts will change as the book is developed.

  • Preface
  • Getting Started
    • Diving Into Crystal
      • A Programming Language For Humans and Computers
      • Slick As Ruby, But Way Faster
      • Almost as Fast as C
      • Speeding Up the Web
      • Talking To Databases
      • More Safety Through Types
      • No To the Billion Dollar Mistake
      • Batteries Included
      • Putting Crystal To Good Use
      • A Company’s Story Crystallized: Red Panthers
      • Wrapping Up
    • Crystal Foundations excerpt
      • Using Basic Variables and Types
      • Variable Operations
      • Structuring Data With Container Types
      • Controlling the Flow
      • Using Methods
      • Organizing Code In Classes and Modules
      • Executing Code Concurrently Through Fibers
      • A Company’s Story Crystallized: Dev Demand
      • Wrapping Up
  • Building Blocks
    • Typing Variables and Controlling the Flow
      • Converting Data Between Types
      • Getting Input
      • Putting It Together—Converting Currencies 1
      • Exception Handling For Faulty Input
      • Chaining Methods
      • Getting Input From Command-line Arguments
      • Using String Methods
      • Using Symbols as Identifiers
      • Using Enums
      • Using Regular Expressions
      • Putting It Together—Converting Currencies 2
      • Beyond Hashes and Arrays: More Composite Types
      • Nilable types
      • Controlling the Flow And Types
      • A Company’s Story Crystallized: Linkfeed
      • Wrapping Up
    • Organizing Code In Methods and Procs
      • Passing Arguments
      • Returning Values
      • Working With Yield, Procs, and Blocks
      • Overloading and Multiple Dispatch
      • Using a Shorter Syntax for Exception Handling
      • Using Recursive Methods
      • A Company’s Story Crystallized: Duo Design
      • Wrapping Up
    • Using Classes and Structs excerpt
      • Converting a Ruby Class to Crystal
      • Structuring a Class
      • Applying Inheritance
      • Controlling Visibility
      • Working With Structs
      • Viewing the Type Hierarchy
      • Some Nice Tricks
      • A Company’s Story Crystallized: LI-COR Biosciences
      • Wrapping Up
    • Working With Modules
      • Combining Files With Require
      • Using Modules as Namespaces
      • A Module Extending Itself
      • Mixing In Modules
      • How the Compiler Finds Methods
      • Applying Built-In Modules
      • A Company’s Story Crystallized: Diploid
      • Wrapping Up
    • Managing Projects
      • Creating a Shard
      • Formatting Code
      • Documenting a Project
      • Writing Tests With Spec
      • Using External Libraries
      • Benchmarking Your Code
      • Deploying a Crystal App
      • A Company’s Story Crystallized: Diploid – part 2
      • Wrapping Up
  • Advanced Crystal
    • Advanced Features
      • DRY Your Code With Macros
      • Low-level Programming and C Bindings
      • Concurrency
      • Database Access
      • A Company’s Story Crystallized: NeuraLegion
      • Wrapping Up
    • Web Frameworks and the Shard Ecosystem
      • Web Frameworks – Kemal and Amber
      • A Brief Tour Of The Shard Ecosystem
      • A Company’s Story Crystallized: Kemal in production
      • Wrapping Up and Afterword
  • Appendices
    • Setting Up a Crystal Environment
      • Working With Crystal Online
      • Installing Crystal on Your Machine
      • Compiling Code
      • Using Editors and IDEs
      • Working With Crystal Playground
      • Using Crystal Documentation
      • Wrapping Up
    • Porting Ruby Code To Crystal
      • Ruby extensions in Crystal
    • Answers To Exercises
      • Chapter 1 – Why Crystal ?
      • Chapter 2 – Setting Up a Crystal Environment
      • Chapter 3 – Exploring Crystal.new
      • Chapter 4 – Typing Variables and Controlling The Flow
      • Chapter 5 – Organizing Code In Methods and Procs
      • Chapter 6 – Using Classes and Structs
      • Chapter 7 – Working With Modules
      • Chapter 8 – Managing Projects
      • Chapter 9 – Advanced Features
      • Chapter 10 – Web Frameworks and The Shard Ecosystem

Author

Ivo Balbaert is a programming teacher and Crystal enthusiast. He has a Ph.D. in Applied Physics and has worked for 25 years in the software industry as a developer and project manager in several companies. Now he combines teaching and consultancy with technical writing. He is particularly interested in elegant emerging languages for concurrency and distributed processing.

Simon St. Laurent is a content manager at LinkedIn Learning, focusing primarily on front-end web projects. He has been co-chair of the Fluent conference and of OSCON. He has authored or co-authored books including Introducing Elixir, Introducing Erlang, Learning Rails 3, XML: A Primer, and Cookies. You can find more of his writing on technology, Quakerism, and the Town of Dryden at simonstl.com.