What’s in This Book

This book teaches the basics of Crystal with an emphasis on how its developers structured its design to make it perform so well.

As Crystal is a recent addition to the programming world, convincing companies and individuals to use it is trickier than promoting familiar tools. To help deal with those challenges, you’ll find discussions about real-world use cases, entitled “A Company’s Story Crystallized,” at the end of each chapter.

The book is organized into three parts:

Part I — Getting Started

We’ll begin by going over all the good reasons you should use Crystal. Then you’ll set up a working Crystal environment and work through a mini-tutorial.

Chapter 1: Diving into Crystal

First, you’ll learn the main reasons for Crystal’s success: it combines human-readable syntax with native code execution performance. You’ll get a first impression of Crystal code, and you’ll see why Crystal focuses on types, potentially saving you from lots of runtime errors.

Chapter 2: Crystal Foundations

This chapter teaches the core of the Crystal programming language through examples you can try in the Crystal playground. You’ll get an overview of variables and types, and how to structure data. You’ll explore logical structures and build simple methods, classes, and modules.

Part II — Building Blocks

This part examines the building blocks of Crystal in much greater depth: variable types, basic and compound data types, control structures, methods, classes, modules, generating docs, testing frameworks, and code formatting.

Chapter 3: Typing Variables and Controlling the Flow

Simple and compound types are the heart of Crystal. Control flow will probably be familiar, but using union types offers some new possibilities here, for example in exception handling.

Chapter 4: Organizing Code in Methods and Procs

Crystal adds type-based method overloading and the multiple dispatch technique, which is one of the keys to Crystal’s speed. We’ll also explore how procs, pointers to blocks of code, can be used in very flexible ways, and how Crystal adds some nice syntax sugar.

Chapter 5: Using Classes and Structs

Crystal’s type hierarchy is laid out here, together with information about when to prefer structs over classes. You’ll see in the type hierarchy how carefully the types were designed to deliver performance. Also, we’ll go over visibility of methods, inheritance, and abstract types.

Chapter 6: Working with Modules

Modules structure code by defining namespaces, but also, as in Ruby and Dart, enable you to mix in code and methods of other types. We’ll discuss the appropriate use of require, include, and extend.

Chapter 7: Managing Projects

Here you’ll analyze a typical generated project structure, and we’ll examine how to write tests using the built-in spec framework. You’ll learn how to include external libraries, how to generate documentation, and how to benchmark your code.

Part III — Advanced Features

Once you’ve learned the heart of the language, you can explore Crystal’s features for maximizing code reuse, as well as sharing code and data.

Chapter 8: Advanced Features

Here you’ll dive into macros—Crystal’s mechanism to generate code at compile-time. Then we’ll discuss binding to C libraries and how Crystal implements concurrency through lightweight fibers communicating data over channels. A unified API called crystal-db gives you an easy way to access databases and SQL, as well as NoSQL.

Chapter 9: Web Frameworks and the Shard Ecosystem

Here you’ll explore Kemal and other web frameworks that aim to provide Rails-like functionality. We’ll also discuss some important packages, shards in Crystal parlance, in various application areas.

In the appendices, you’ll find installation instructions, tips for porting Ruby code to Crystal, and answers to the exercises and questions presented throughout the book.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.223.210.71