Crystal for non Rubyist?

Hello!

I’m really interested in Crystal and how just amazingly simple (and fast!) it is! Now I understand that a lot of people who once learned Ruby or used it would have a very easy time learning Crystal… But sadly I have never touched Ruby before and neither Crystal. I come from the world of Lua and little bit of Kotlin/Swift so Crystal is certainly different piece of bread to chew on.

Are there any good resources that someone could share with me to get hang of Crystal? I know someone posted a book and I’m planning to buy it soon, but the more resources the better!

Thank you!

1 Like

I wouldn’t worry about the “missing” ruby background.

I would agree that many if not most initial interest in crystal comes via the ruby route, but speaking from my own experience, I think I would feel far more attracted to crystal if I didn’t know ruby beforehand and “fell” for the “it’s do much like ruby” claims.

Don’t get me wrong, please: Crystal is great! It’s just that if one comes with “ruby expectations” one gets quickly sad and disappointed in so many ways (except for speed! The performance is really impressive!)
I just somehow wished I would have started directly with crystal without having been spoiled by ruby earlier.

What I try to say: while some syntax looks similar it’s imo not as close to ruby as it’s often claimed in blogs etc. If I were you I really wouldn’t worry about it.

About learning ressources: as you mentioned yourself, there has been a recent book release; the book is supposed to be good (I haven’t read it myself). There is also some older book (which I’ve read) which isn’t fully up to date, but should be still good enough to get you started.
For the most part: check the API documentation and the spec on the homepage (they should contain enough example code for all relevant things you need to know).

Another way which might help: look for crystal projects on GitHub and have a look at actual code. The code should be quite well understandably even without prior crystal knowledge.

And don’t hesitate to ask in the forum if you have any questions. I did so a lot myself, and people were really supportive and friendly.

2 Likes

Thank you for the response!

That is a very interesting take on Crystal as a Rubyist! How comes?
Yeah, in that case I might order that book next week and see where it gets me. I just hope it won’t have too many Ruby mentions otherwise it might get a little bit complicated…

I’m trying my best looking around right now, might take sometime to get used to Crystal as it really feels like one type of language I have never touched before, a whole uncharted territory (and thank God it uses toml for build system!!) The only thing I have to get used to now is the blasted snake_case…

A good book is Ruby Programming Language, published by O'Reilly, write by the author of the ruby programming language.

image

If you believe me, almost all knowledge you learn there will help you Crystal a lot, if you not learn ruby first, you probably very hard to understood the point of the document of offcial reference, it really write by some guys use Ruby quite well, and write for Rubyist because it assume you know many knowledge of ruby i have to admit.

All right, the key point is, you have to give yourself some ruby background, to make you use Crystal really happy.

Sure, some experiences of others languages will help, (e.g. lisp, smalltalk, perl, haskell), but i still consider the most easy way is, just study Ruby.

Maybe someday (or maybe now), you can learn Crystal with a book about Crystal, but, AFAIK, there is no book can teach you Crystal as detailed as teach you Ruby, that is, we still missing a book, named: Crystal programming language, it should be published by O'Reilly typically.

That makes it slightly … Time consuming because at that point one would learn two languages who are yet so similar but have differences. Don’t know if it matters from an outsiders point of view, but the documentation perhaps should look at a broader audience, not only to those with Ruby background.

But thank you, I guess I might need to check it out.

I didn’t have any Ruby experience before I learned Crystal. Only after learning Crystal did I start using Ruby for some light scripting tasks. Before that, I mostly used Common Lisp, Go, and some Pascal. Long before that, C#. TBH, I’m glad Crystal isn’t more like Ruby, not because I dislike Ruby (I certainly do like it), but because it would take away from Crystal what I like the most.

Anyway, whenever I start learning a new language, I usually want to know the basics of the syntax and tools and general feel of the language. I also prefer to jump in and start tinkering right away. With Crystal, the initial introduction on the main website and the associated guides both did this quite well. Reading through the specification was also really helpful because, unlike other language specifications, the one for Crystal isn’t dry.

I also have a small toy program that I rewrite in almost every language that I learn (list the data inside of a Doom WAD file). Doing this lets me focus on learning the actual language and its standard library rather than both learning a language and solving a problem. Revisiting some common problems on Rosetta Code to see how things would be done in Crystal was also helpful.

Hopefully that helps? You definitely aren’t the only one coming to Crystal without a Ruby background ^_^

6 Likes

That slightly reassures me that perhaps I don’t need to spend hours going through a Ruby book to learn Crystal with what we’re given then.

You definitely helped out here with the links and gave me a little suggestion on what I can try doing to get hands on Crystal a little bit more.

Much appreciated!

1 Like

There is also a Crystal lang book: Programming Crystal: Create High-Performance, Safe, Concurrent Apps by Ivo Balbaert and Simon St. Laurent

Considering the book was released in 2019, has a lot of things changed in Crystal since then?

not significantly, but I actually meant to link this book

a little newer. Thanks for pointing out the date.
The 2019 book is pretty close to version 1 of crystal too

2 Likes

Ah yes, this one I’m aware of and planning to buy it soon!

1 Like

Yeah you shouldn’t need to read a Ruby book. Just take the Crystal one ;)

We’re also collecting learning resources at External resources - The Crystal Programming Language (currently it’s not very populated, the page is rather new; contributions are welcome).

1 Like

IMHO, Programming Crystal is a little elementary, Notice, This book is full of errors, most of those is because the target version of this book is too old, but, the key is no different, i guess you can figure it out. anyway, it is a good start book.

You don’t need read Ruby Programming Language entirety, but, almost all the concepts in this book are very useful, whether it’s for learning a dynamic language like Ruby/Python or learn Crystal.

But if your purpose is to learn Crystal, you can use this book as a more detailed references, or for understand the key concept(suitable for both Ruby and Crystal), instead of google, get answer from this book is more easy, though, you probably can get some awesome answer from blog or SO.

Regarding Programming Crystal: Create High-Performance, Safe, Concurrent Apps by Ivo Balbaert and Simon St. Laurent, IIRC the most notable outdated part will be how overflow is handled in arithmetic operators and how it can be skipped when wanted. The book was authored before those were introduced. Maybe some examples would error due to some enforcement the compiler does for abstract method. But other than that the content of the book is very good, and if you want to read about some use cases in the industry the stories and interview are a good source for that. I would still recommend that book with these caveats in mind.

My 2 cents on learning: Do something with whatever you want to learn.
This might be really obvious, in which case, please just ignore it :)

  • Pick a task/problem/thing
  • break it down to a minimum viable project (don’t start with a whole warhammer army, start with one Orc. Don’t program a twitter smartphone app, do a console app that fetches some tweets)
  • pick a starting point. (get a can of Primer, learn how to use it. Find out how you do a HTTP request and do that)
  • start building on that. (buy color, apply base color. print the results of your request in a pretty way on the console)
    continue on like this. Pick one next task, see what you need to know/acquire for that task, and do it.

What I mean is: Don’t have a big plan of learning. Learning something is almost pointless if you don’t plan to use the knowledge.
Find out what you want to use it for, and start learning with that specific target in mind.

I find it easier that way, as opposed to following someone elses tutorial, because I’m more invested in it.
After all, I’m doing something I want to do.

4 Likes

Just leaving a quick comment to mention that I also had no ruby experience before learning Crystal, and I’ve never found that to be an issue. In fact, learning Crystal is what taught me Ruby, not the other way around haha

When I was learning, I did find it very useful to google Ruby’s documentation, though. Crystal is still niche, and a lot of beginner Crystal questions don’t have an easily accessible answer on google. Most of the time, though, I found that I could just google “how to do X in ruby,” and the answer would either directly translate or at least get me started towards a Crystal answer.

Then again, there’s also the Forum, Discord, and StackOverflow to let you ask questions if you need to :)

2 Likes

You can also get some learning and practice on Exercism: Crystal on Exercism

1 Like

I don’t think it’s necessary to read Ruby’s book. It looks like you have experience with both dynamic and static languages, maybe the Crystal’s documentation(It is clear enough and easy to read) and @stakach’s recommended book are sufficient for you. The community is friendly and it’s easy to solve confusion here.

1 Like

If you really start coding use Crystal(instead of just playing as a toy), you will find there is FAR FAR less document/example than Ruby, this is really a serious problem, although, many times I can find the answer in the Ruby standard library document or blog, but that not always true.