Writing a learning mode for crystal, searching for feedback

Learning mode for crystal on exercism

I am currently planning to build a learning mode for the crystal. A learning mode means that the language has a syllabus tree covering various language-centric concepts. I have set up a base “tree”, and over time more could be added. Here is my current draft:

Here is what every concept will cover:

Basics

  • Create variabels and constants
  • How to define a method and how to call a method
  • Default parameters

Numbers

  • Cover basic “math” methods (+, -, *, **, /, %)
  • How to round a number
  • Floats, Uint, int and all the forms of them e.g int16 etc
  • How to convert between different number types
  • Prioritization in math methods

Binary & octal & hexadecimal

  • How to create Binary & octal & hexadecimal
  • TBD

Bools

  • True/False
  • &&, ||
  • !

classes

  • General oop
  • Initialize
  • Instance variables
  • Class variables

Getters/setters

  • Getter
  • Property

Strings

  • What a string is and how to create them
  • Interpolation
  • Empty?
  • Size
  • Indexing
  • Convert a string to a number and the other way around

String methods

  • Escaping
  • gsub
  • TBD

Conditionals

  • If/elsif/else
  • Comparisons operators(==, <= etc)
  • Unless

Case (switch)

  • How to create a case
  • When to use a case

Modules

  • How to create a module
  • Difference between a class and a module
  • Extend & include

Ternary operator

  • How to create a ternary operator

Char

  • Basics of what a char is and how to use them
  • TBD

While & Until

  • How to create a while loop
  • Next
  • Break
  • Until
  • Difference between until and while

Range

  • Range with numbers, chars, and strings
  • Range with .. and ...
  • How to slice a String

Nil

  • Introduction to nil
  • Explain that [x]? returns the item if it exists otherwise nil.

Union types

  • Explain how to create a union type
  • Explain that assigning for example Int32? means (Int32 | Nil)
  • Explain typeof vs .class

Rasing errors

  • Explain how to raise errors
  • Explain errors in crystal

Array

  • How to create an array
  • Declaring an empty array
  • Declaring a nested array
  • Indexing and slicing arrays
  • Join and split
  • Explain that arrays are mutable
  • Explain append(<<)
  • Delete/pop

Array methods

  • Sort
  • uniq
  • shift
  • fil
  • concat
  • Compact
  • First
  • Last
  • Flatten
  • Reverse
  • Rotate
  • Shuffle
  • Index
  • TBD

Enumeration

  • each
  • all?
  • any?
  • count
  • each_with_index
  • find
  • none?
  • map
  • map_with_index
  • one?
  • products
  • reduce
  • sum
  • Sort_by

More enumeration

Comment: Some of this will there not be any deep dive on, just a mention

  • chunks
  • cycles
  • each cons
  • each cons pair
  • each slice
  • group_by
  • in_groups_of
  • max_by
  • max_of
  • min_by
  • min_of
  • reject
  • Select
  • skip_while
  • skip
  • take_while

Symbols

  • What a symbol is
  • Comparison between symbols and strings
  • Convert a symbol to a string

Tuples

  • How to create a tuple
  • Difference between array and tuple
  • When to use a tuple and when to use an array
  • Explain that tuples are immutable

Hashes

  • Explain how to create a hash
  • Explain how to create a hash with symbols
  • Explain how to create an empty hash
  • Explain hash methods TBD

Named tuple

  • How to create a named tuple and the difference between a hash.

Decompositon & multiple assignment

  • How to do multiple assignments
  • How to use the splat operator

Now when the very WIP explanation is over.
The reason I want to bring this up with the crystal community is that once the tree is implemented it is quite hard to do major changes to the root of the tree. With that said after the base is implemented it is possible to make new branches, for example, say we want a concept about a math module. We can just branch that of numbers and there will be no pain points. Although say we decide to change so we first learn strings and then bools. Such a change will require a lot of work and should be avoided.
Thereby I want feedback on everything, on the order, is a concept missing from the root (for example there should be a concept about regex before arrays (not about new branches, just changes that affect current branches). Is there something in the explanation of the concept that should be added/explained at an earlier/later concept.

Here is an example of how the tree looks for C# syllabus tree on exercism and Elxir syllabus on Exercism.
Feedback on more “branches”(not the root which is shown in the tree) to be added is welcome but there are already 23 concepts and as I am the only one working on this, so could take a while until those gets added.

4 Likes

What about “Spec and Automated Tests”, “Using the Compiler”, “Shards and Libraries”, “Debugging in Crystal”?

1 Like

How exercism works is that there is a test runner running within a docker container. You can solve exercises locally but when sending the exercise to the website does it go through the test-runner. Which could limit some stuff.

Spec could be interesting to add, although, that does likely require modifications to the test-runner and is not on my prioritization list. But I think it is a cool idea and when I get the time I will see if it is possible.

Using the compiler could be a bit complicated because of the docker stuff I mentioned earlier. Thereby am I a bit unsure in which way you mean using the compiler.

Shards and libraries, I am planning to at a later point cover require. But since the test-runner runs in docker so can’t the user just download a shard, instead the shard has to be given before run time. Thereby if there is some cool library for data processing or something else so could I include that library and let the user use that. But the library should preferably be quite used in the crystal community and std library in crystal is already pretty solid.

Debugging in crystal will probably be a document instead of a concept since debugging will probably be needed from the first concept to the last.

Awesome! Giving a quick look at it, I’d say there’s missing a chapter on Blocks (and Procs?). I imagine you will need that to most of the stuff in the more advanced topics.

Yes, blocks and procs, do you have any inputs about where that should be put? Otherwise, I am thinking perhaps before enumeration.

I don’t know, it will depend on how you cover the previous material. For instance, if you’ll use Range#each, then you’ll need it quite in advance. But maybe you can get along introducing Range without #each.

Also, there are several subtleties in method creation and calling (see e.g., the tutorial). I don’t know when/if you plan to cover those.

(Just quick thoughts, not doing a thorough analysis!)

I am thinking of introducing ranges in a bit step by step. So first introduce ranges, how to create a range and then use a range to slice a string, using includes and sum. Then in the array or array method concept there will be a brief introduction to converting a range to an array. Then in enumeration will there be each so I guess it makes sense to introduce procs right before that.

A lot of the “basic” methods things will be in basics, methods, arguments, default arguments, and returning a value. Then I will see but return type and Type Restrictions may be a part of classes or may be in basics, I have not really decided. Method overloading may be its own concept in around the middle of the tree or may be a part of modules, I dunno. I will have to see.

1 Like

Okay I updated the tree a bit.

Changes:

  • classes go of bools & numbers instead of basics
  • String comes of classes
  • Nil goes from Conditionals instead of string methods
  • Added missing link from char to range
  • Add block(proc)