Book Image

Crystal Programming

By : George Dietrich, Guilherme Bernal
Book Image

Crystal Programming

By: George Dietrich, Guilherme Bernal

Overview of this book

Crystal is a programming language with a concise and user-friendly syntax, along with a seamless system and a performant core, reaching C-like speed. This book will help you gain a deep understanding of the fundamental concepts of Crystal and show you how to apply them to create various types of applications. This book comes packed with step-by-step explanations of essential concepts and practical examples. You'll learn how to use Crystal’s features to create complex and organized projects relying on OOP and its most common design patterns. As you progress, you'll gain a solid understanding of both the basic and advanced features of Crystal. This will enable you to build any application, including command-line interface (CLI) programs and web applications using IOs, concurrency and C bindings, HTTP servers, and the JSON API. By the end of this programming book, you’ll be equipped with the skills you need to use Crystal programming for building and understanding any application you come across.
Table of Contents (26 chapters)
1
Part 1: Getting Started
5
Part 2: Learning by Doing – CLI
10
Part 3: Learn by Doing – Web Application
13
Part 4: Metaprogramming
18
Part 5: Supporting Tools

What this book covers

Chapter 1, An Introduction to Crystal, provides a brief introduction to Crystal, including its history, key concepts, and goals. This chapter will also include information about setting up Crystal as well as information on the conventions that'll be used throughout the book.

Chapter 2, Basics Semantics and Features of Crystal, introduces you to writing Crystal code, starting from the very basics and advancing to the most common techniques. It also explores common types and operations from the standard library.

Chapter 3, Object-Oriented Programming, goes deeper into using the object-oriented features of the language by teaching you about creating new types with custom functionality, the basic tool of every non-trivial program.

Chapter 4, Exploring Crystal via Writing a Command-Line Interface, explores setting up a CLI project and walking through the initial implementation.

Chapter 5, Input/Output Operations, builds on the previous chapter by introducing I/O operations as a means of handling input and output instead of hard-coded strings.

Chapter 6, Concurrency, starts off by going over Crystal's concurrency features and later uses what was learned earlier to make the CLI program concurrent.

Chapter 7, C Interoperability, demonstrates how C libraries can be leveraged within a Crystal program by binding libnotify to make the CLI program notification aware.

Chapter 8, Using External Libraries, introduces the shards command and how to find it.

Chapter 9, Creating a Web Application with Athena, walks through creating a simple blog web application using Athena Framework, making use of many of its features.

Chapter 10, Working with Macros, provides an introduction to the world of metaprogramming by exploring Crystal macros.

Chapter 11, Introducing Annotations, talks about how to define, include data within, and read annotations.

Chapter 12, Leveraging Compile-Time Type Introspection, demonstrates how to iterate instance variables, types, and methods at compile time.

Chapter 13, Advanced Macro Usages, shows off some of the powerful things that can be created using macros and annotations, along with a little bit of creativity.

Chapter 14, Testing, introduces the Spec module and walks you through unit and integration testing in the context of CLI and web applications.

Chapter 15, Documenting Code, shows off how best to document, generate, host, and version Crystal code documentation.

Chapter 16, Deploying Code, talks about how to release new versions of a shard as well as how best to build and distribute the production version of an application.

Chapter 17, Automation, provides example workflows and commentary on enabling continuous integration for Crystal projects.

Appendix A, Tooling Setup, provides a hands-on explanation of how to set up Visual Studio Code for Crystal programming using the official plugin.

Appendix B, The Future of Crystal, gives a short overview of the work currently being done behind the scenes for the future of the language and shows you how to participate and contribute.