Exploring & Learning Crystal Language with code examples and augment the documentation.

NOTE:
  • The code is just good enough to demonstrate an idea.

  • This code does not focus on best practices, security nor being production ready.

1. Installation

On MacOS - use:

$ brew install crystal

For all other systems see: https://crystal-lang.org/install/

2. Crystal CLI

  • Useful commands when using crystal

  • My most useful command while developing is:

crystal run src/file_name.cr

2.1. Structs & Records

2.2. Structs

  • Structs (& Records) are immutable data structures - these are safe when used in a concurrent/parallel context.

2.3. Records

  • Structs (& Records) are immutable data structures - these are safe when used in a concurrent/parallel context.

3. WebSockets

Making long-lived client-server connections over a TCP.

4. Concurrency & Parallelism

An intro into the basics of how things like websockets work

TODO

Augment and adapt content using inspiration from: https://blog.golang.org/pipelines

4.1. Concurrency Basics

  • Basics on starting processes concurrently

4.2. Concurrent Objects

  • Examples of using concurrency with objects

4.3. Channels (Async Messaging)

  • Channels allow us to safely communicate between concurrent processes.

  • To safely share data/state send immutable data only (Structs are a good option).

4.4. Channel Buffers

  • What to do when messages come faster than collected

4.5. Channel Callbacks

  • Safely share state information when its available

4.6. Crystal Promises

4.7. Parallelism

  • Compiling to use multiple CPUs (add -Dpreview_mt) to the compile command

4.8. Actor Model (not done)

  • Using macros to build async message sending, callbacks and state sharing.

5. TO-DOs

  • Add Macros

  • Write Channel Buffering

  • Reseach Promises in Crystal

  • Finish Callbacks & (Notification)

  • Research/Add Crystal Value Objects

  • Build a Macro to make a simple Actor Class

  • Add Parallelism (Ideally with WebSockets example — to extend chat)

  • Add, review, augment and adapt content using: https://blog.golang.org/pipelines

6. Resources

Note
Crystal Lang Gitter is a great group of people willing to help. (special mention to: @stnluu_twitter, @watzon, @repomaa, @randiaz95, @straight-shoota & @paulcsmith)

7. Webpage & Code Repo

Webpage and associated code can be found at: https://github.com/btihen/crystal_explorations

8. Generating these Docs

$ asciidoctor -D docs adoc/*

9. Corrections & Improvements

Thanks!