Crystal Programming: A project-based introduction to building efficient, safe, and readable web and CLI applications

This document was uploaded by one of our users. The uploader already confirmed that they had the permission to publish it. If you are author/publisher or own the copyright of this documents, please report to us by using this DMCA report form.

Simply click on the Download Book button.

Yes, Book downloads on Ebookily are 100% Free.

Sometimes the book is free on Amazon As well, so go ahead and hit "Search on Amazon"

The juxtaposition of "machine learning" and "pure mathematics and theoretical physics" may first appear as contradictory in terms. The rigours of proofs and derivations in the latter seem to reside in a different world from the randomness of data and statistics in the former. Yet, an often under-appreciated component of mathematical discovery, typically not presented in a final draft, is experimentation: both with ideas and with mathematical data. Think of the teenage Gauss, who conjectured the Prime Number Theorem by plotting the prime-counting function, many decades before complex analysis was formalized to offer a proof. Can modern technology in part mimic Gauss's intuition? The past five years saw an explosion of activity in using AI to assist the human mind in uncovering new mathematics: finding patterns, accelerating computations, and raising conjectures via the machine learning of pure, noiseless data. The aim of this book, a first of its kind, is to collect research and survey articles from experts in this emerging dialogue between theoretical mathematics and machine learning. It does not dwell on the well-known multitude of mathematical techniques in deep learning, but focuses on the reverse relationship: how machine learning helps with mathematics. Taking a panoramic approach, the topics range from combinatorics to number theory, and from geometry to quantum field theory and string theory. Aimed at PhD students as well as seasoned researchers, each self-contained chapter offers a glimpse of an exciting future of this symbiosis.

Author(s): George Dietrich, Guilherme Bernal
Publisher: Packt Publishing
Year: 2023

Language: English
Pages: 356

Cover
Title Page
Copyright and Credits
Contributors
Table of Contents
Preface
Part 1: Getting Started
Chapter 1: An Introduction to Crystal
Technical requirements
A bit of history
Exploring Crystal's expressiveness
Crystal programs are also FAST
A web server comparison
Setting up the environment
Creating our first program
Creating an executable
Summary
Chapter 2: Basic Semantics and Features of Crystal
Technical requirements
Values and expressions
Numbers
The primitive constants – true, false, and nil
String and Char
Ranges
Enums and symbols
Controlling the execution flow with conditionals
if and unless
case
while and until loops
Exploring the type system
Experimenting with the crystal play command
Organizing your code in methods
Adding type restrictions
Default values
Named parameters
External and internal names for parameters
Passing blocks to methods
Data containers
Arrays and tuples
Hash
Iterating collections with blocks
Short block syntax
Splat parameters
Organizing your code in files
require "./filename"
require "filename"
Summary
Further reading
Chapter 3: Object-Oriented Programming
Technical requirements
The concept of objects and classes
Creating your own classes
Manipulating data using instance variables and methods
Creating getters and setters
Inheritance
Polymorphism
Abstract classes
Class variables and class methods
Working with modules
Values and references – using structs
Generic classes
Exceptions
Custom exceptions
Summary
Part 2: Learning by Doing – CLI
Chapter 4: Exploring Crystal via Writing a Command-Line Interface
Technical requirements
Project introduction
Scaffolding the project
Writing the basic implementation
Transforming the data
Improving reusability
Summary
Chapter 5: Input/Output Operations
Technical requirements
Supporting terminal input/output
Supporting other IO
Performance testing
Explaining IO behavior
Summary
Chapter 6: Concurrency
Technical requirements
Using fibers to complete work concurrently
Using channels to communicate data safely
Transforming multiple files concurrently
Summary
Chapter 7: C Interoperability
Technical requirements
Introducing C bindings
Binding libnotify
Testing the bindings
Abstracting the bindings
Integrating the bindings
Summary
Part 3: Learn by Doing – Web Application
Chapter 8: Using External Libraries
Technical requirements
Using Crystal Shards
Shard dependencies on C code
Updating Shards
Checking dependencies
Finding Shards
Example scenario
Summary
Chapter 9: Creating a Web Application with Athena
Technical requirements
Understanding Athena's architecture
Getting started with Athena
The Article entity
Returning an article
Handling the request body
Validation
Implementing database interactions
Setting up the database
Persisting articles
Fetching articles
Updating an article
Deleting an article
Leveraging content negotiation
Summary
Further reading
Part 4: Metaprogramming
Chapter 10: Working with Macros
Technical requirements
Defining macros
Fresh variables
Non-macro definition macros
Understanding the macro API
Recreating the property macro
Exploring macro hooks
Summary
Chapter 11: Introducing Annotations
Technical requirements
What are annotations?
Storing data within annotations
Reading annotations
Summary
Chapter 12: Leveraging Compile-Time Type Introspection
Technical requirements
Iterating type variables
Iterating types
Iterating a type's subclasses
Iterating types with a specific annotation
Iterating types that include a specific module
Iterating methods
Summary
Further reading
Chapter 13: Advanced Macro Usages
Technical requirements
Using annotations to influence runtime logic
Exposing compile-time data at runtime
Accessing the value
Modeling an entire class
Determining a constant's value at compile time
Creating custom compile-time errors
Restricting generic types
Summary
Part 5: Supporting Tools
Chapter 14: Testing
Technical requirements
Why test?
Unit testing
Tagging tests
Mocking
Hooks
Integration testing
Summary
Chapter 15: Documenting Code
Technical requirements
Documenting Crystal code
Linking an API feature
Formatting
Documentation directives
Ditto
Nodoc
Inherit
Generating the documentation
Hosting the documentation
Documentation versioning
Summary
Chapter 16: Deploying Code
Technical requirements
Versioning your shard
Creating production binaries
Distributing your binary
Via Docker
Via package manager(s)
Summary
Further reading
Chapter 17: Automation
Technical requirements
Formatting code
Linting code
Continuous integration with GitHub Actions
Formatting, coding standards, and tests
Deploying documentation
Summary
Appendix A: Tooling Setup
Installing the Crystal compiler
Installing the compiler on Windows
Installing Visual Studio Code
Appendix B: The Future of Crystal
Windows
WebAssembly
Multithreading
Structured concurrency
Incremental compilation and better tooling
How to get in touch with the community
Index
Other Books You May Enjoy