Maybe write a #community:journals for that as well Mafinar? I am sure many people will find it interesting
Yes of course I will. This is not the first time I attempted to learn an ML. I tried with OCaml, F# and even ReasonML numerous times and then backed out for some reason. Especially I went far with F# then all the .NET specific terms came up and I backed out. I love the language though.
I hope with a #community:journals it would work for me. I know I learned Crystal and completed a book from it.
There you go: My OCaml Journal
Had to switch to OCaml at the last minute, I did not like ReasonML documentation and the fact it took my a long time to get VSCode to work.
It has a lot of features, but itâs not pluggable. You can add backends to go through sure but if you are wanting âmoreâ capabilities then you canât really do that in the existing framework. This is why I like how Rustâs works, it just supplies some basic âpointsâ that a logger can plug in to, then it can do whatever it wants, itâs significantly lower level though, but much more powerful.
For example, not only can you log text messages with warn!("blah")
or whatever, which does also give a huge variety of information about its calling context (which, of course, the logger can do more to) but you can also add more information like warn!("blah", user_id=user.id, some_more=metadata)
but you can even âspanâ logs across more than just a single point, so you could do, for example, let _ = warn_span!("blah", ...)
and it will be held in that entire scope, giving wrapping other logs that happen during it (like deeper in the callstack), can give timing details if the logger so wants it (or no cost if it doesnât), etc⊠It is pluggable even with profilers, which makes timing code easy as well, you can do that in Elixir for example but it requires using the tracing infrastructure, not part of the log system and itâs part of the beam internals and doesnât always correspond to elixir code due to its code generation.
I very much prefer OCaml straight over ReasonML. ReasonML just transpiles straight to OCaml anyway (and it can convert OCaml to ReasonML, itâs a lossless conversion, other than formatting just going bonkers, lol). But the OCaml syntax is so excessively more pleasant for me than ReasonML (which was designed to be a javascriptây syntax for OCaml, so itâs a lot more noisy).
I am back in this thread with a small review.
I have mentioned in the past that I will only skip the chapter involved with Web Frameworks in the book because neither of the frameworks (Amber and Kemal) really clicked, not to say they are bad frameworks, quite the opposite (I actually motivated a friend of mine to use Amber in his start-up for a small service and he loved it)- itâs just that I feel like it wouldnât give me anything new. Unlike a programming language, investing in a specialized library or framework is a more time consuming one as it involves you to think up a non-trivial end product and go after it. Kemal is just Sinatra (or any of itâs brethren i.e. Express or Flask) crystallized.
But what I missed mentioning about is are the appendices. These are often not reviewed or talked about but in some cases, could give you a boost to get on with the rest of the book, In this case, itâs the latter.
There are three appendices here- 1. Setting up the environment, 2. Ruby to Crystal conversion and 3. Answers to the exercises. So the third one is your typical appendice that you only use as needed and may never care beyond that. But the setting up the environment one was pretty good. Except for the one where they claim about ânice IDE experienceâ in relation to VS Code. I donât think thatâs anywhere near nice. I canât speak for other editors. But, I had forgotten about âSublime Editorâ when talking about Onivim to a former colleague of mine yesterday, I kept refering to as â⊠that fast editor that kept asking for money which I never used and promised not to ever useâŠâ, she happened to forget the name too. So this appendix at least gave me that aha moment.
The next appendix, porting Ruby to Crystal, is just a table with syntaxes of the languages side by side. I am not a Ruby programmer but I can feel the convenience of having it. If one is a Ruby developer, Iâd suggest skimming through that little table before any else. Itâs weird, Java and Clojure belong to the same VM, but a table converting one syntax unit to other in entirety would not be useful at all (I am talking as a whole, not just the interoperability part, thatâs useful). Same goes for Scala and Clojure. But Ruby and Crystal makes sense, theyâre both the same paradigm-wise and philosophy-wise, has an overlap in the community and libraries with similar pattern. This makes total sense. Probably, Erlang and Elixir would be in this group too, but I think Ruby knowledge gets you close to Crystal knowledge faster than Erlang would to to Elixir, initially (eventually the role is reversed, knowing Erlang well helps with in your Elixir journey better as you tackle advanced things, Ruby/Crystal, may not be as much).
So, this is my penultimate thought regarding this book. Should have been the last one but I kept the advanced chapter, which I would tomorrow. After this, I will just note down any Crystal things I do.
One nice side-effect of this book though, I feel like I know more Ruby now!
If you want to learn an interesting web framework that is âdifferentâ Iâd recommend Rocket in Rust, itâs method of handling âhowâ a route is acquired and the variety of ways it can be skipped and so forth is fascinating!
Something more Phoenix-like in Rust in Warp, itâs concept of filters is essentially identical to Plugs in Elixir. ^.^
(Honestly Rocketâs style is like plugs/filters but baked in to the very types that the route function accepts, which makes it amazingly succinct and clear compared to the filter style!)
I do want to learn a web framework that is different. Only problem for me with Rocket is, I have 0 Rust knowledge. I do have it in my to learn list.
After OCaml, Iâll start a thread on Rust.
Chapter 8 - Advanced Features
Finally, my final chapter! This is an interesting one, I learned quite a bit from here, though I think each of the major features deserved its own chapter instead of a section.
So, advanced crystal here is comprised of-
- Macros
- Concurrency
- C-binding and
- Database Access
First, letâs check out Marco. I remember teaching Macro to a Django Developer colleague through Django templating language. It was very effectively communicated I believe. I was happy to see Crystal being much closed to the Django Template syntax than Clojure (my only macro example back then). It has {{}}
and {% for <loop> %}...{% end %}
. I think the chapter does great in explaning macros both in terms of what they are and how they are implemented in Crystal. method_missing
, inherited
, extended
and included
are hook-ish Macro-s that you can define to metaprogram on specific events (i.e. what happens when a method is missing? A subclass is defined? etc). I only tried out method_missing
on playground, rest will follow. But it does seem straight forward.
Next comes C binding. This too looks quite simple in Crystal (compared to any other language I used). I got introduced to âannotationsâ, âlibâ and âfunâ syntaxes! I donât recall having seen them described earlier. Anyways, upon visual inspection- lib
is grouping of C libraries and fun
inside a lib is a signature by signature mapping of same named C functions (More new syntaxes: *
at the end for pointers that were introduced in this chapter). Annotations would map the C library with the following lib
block. After this setup is made, weâre pretty much back to Crystal-land calling the FUNctions.
However, upon inspecting the Crystal Docs, there seems to be a lot more in binding Crystal with C than it was mentioned in the book (though it is suggested to reach out to that link to know more). Examples include, unsafe, enums, threadlocals, callbacks and many more. I think C <> Crystal is a big selling point for Crystal and from whatever I have skimmed through (have not executed anything) I do seem to be impressed at the simplicity of it. I would have been a lot happier if there were an example that does more than just a C void greet(const* char)
function being called from Crystal, but something a little more. Perhaps the temperature converter mentioned in the first chapter? Or the Mineral system in the subsequent ones converted into struct
?
One other thing, this chapter mentions once- âC is a strongly typed languageâ where it should have been C is a statically typed language. âStrongâ and âWeakâ typing is rather relative in my opinion and also in my opinion, âStrongly Typedâ is not really a strong suit of C-s, itâs rather on the âweakerâ end when it comes to âstrengthâ of typing. Again, very nit. Also, I got to learn of system
in Crystal which lets you execute an OS command (as does backticks, though not mentioned in the book).
Anyways, this book is not a reference and it DID do a great job of pointing me to the right direction after motivating me enough. Also, this chapter, particularly this section, had inspired me to continue playing with Crystal, so that too is a good thing.
After C-binding came concurrency. Crystal concurrency is like Go concurrency where go
is spawn
. You have channels, channels can be buffered, selected, yielded etc. The unit of concurrency is called Fiber. I think anyone understanding the conveyor belt metaphor and Goâs way of concurrency will find it easier to understand Crystalâs point of view. And in my opinion, Crystal does it with a much more beautiful syntax:
def generator(n : T) forall T
chan = Channel(T).new
spawn do
loop do
sleep n
chan.send n
end
end
chan
end
ch1 = generator(1)
ch2 = generator(1.5)
ch3 = generator(5)
loop do
select
when n1 = ch1.receive
puts "Int: #{n1}"
when f1 = ch2.receive
puts "Float: #{f1}"
when ch3.receive
break
end
end
^ Another example from the book.
Final section for this chapter was DB integration. The pattern is simple:
DB.open do |db|
db.query sql do |r|
<do your thing with `r`>
end
end
And that db
also has exec
, query_one
, query_all
etc. It only briefly mentioned Transactions at the end but looking at the design pattern, itâs simple to guess: db.transaction do |tx| ... end
, I verified my guessing from Crystal docs.
So this was the final chapter highlights from my side. I left one out (the one with web frameworks) but I will revisit it from a âmetaâ viewpoint if I look into a Crystal framework, but that will be my highlights on the framework, not the chapter, and it may happen much later. As far as chapter-by-chapter exploration is concerned, I am finished here
I could go on and on about how this book club journey has been for me (It was obviously good, I learned a language in ~40 posts!), but I will keep that for my upcoming post where I will summarize my experience, as for conclusion of this chapter/post, I will summarize my overall feelings of this chapter.
It was a âheavyâ chapter, a lot of concepts to swallow in one unit. I wish this chapter was a PART
with at least three chapters- Advanced Syntax (Macro + Generics maybe?), C-Binding, and Concurrency. The chapter on Database couldâve been merged with the Web Frameworks chapters. However, it is my opinion based on my worldview of things and this really is not a bad thing of this book. This chapter did a great job by having me see all these things and occasionally try them out in one weekend evening. I understand those things are out there in the docs, but the book prepared and outlined all the things and placed it in the right sequence of the ToC and got me there, if I am ever to deal with a problem in Crystal that does any of these, I am prepared, the remainder of the execution is the reference docs and my effortâs job. Despite my nitpicks and complaints, I will give it 4/5, based on the benefits I received from reading it!
Yes, I will continue with Crystal, and possible this yearâs Advent of Code will be divided between Crystal and OCaml for me
One pain point of my using Crystal! The crystal play
borne playground is painful! When I copy the code from the book and paste it there, clicking on Run Formatter
does nothing. The error labels often do not go away, and it crashed on my multiple times. Not sure it should be supplied with a Version 1.0
system.
Maybe Elixir spoiled me, but having a good interactive system (along with good IDE integration) receive strong points from me and Crystal receives low points in them both.
Entirely correct. C is a statically weakly typed language. OCaml or Rust would be statically strongly typed languages. Python would be a dynamically strongly typed language. Javascript would be dynamically weakly typed. ^.^
I have a blog about these definitions somewhere⊠>.>
How very windows of that term. Generally greenthread or microthread is the term, but windows had an API for stackframe swapping that people (poorly) implemented greenthreads/microthreads on called the Fiber API. ^.^;
Oooo that gives me an idea for a rust async descriptionâŠ
OT but there are a couple libraries for C called libdill/libmill that add similar concurrency, one of them is a go-style system and the other is more traditionally C style, but same backend for both. ^.^
Iâm curious about hearing of your comparisons. OCaml I really love as a language, though you can definitely feel a lot of the cruft in its age, it still ranks as one of my favs. I still say look at Rust, Rust was originally built on OCaml after all.
You know what, I think I really should. I never fought back with the compiler so my Rust progress never happened beyond a day or an hour. I should leverage this social learning spree of mine and see if I can get any Rust.
Do you suggest any learning resources? Any books? Working by doing didnât seem to help much with it.
The official âRust Bookâ on the main website is fantastic learning material, but Iâm of the opinion that 1-on-1 help is often the easiest and best way to learn (Iâm a fan of socratic style teaching). I have some time at work today (yay Fridays) that if you want to then we can. Iâm on IRC and Discord if you have a preference. I mainly use Clion and it has awesome pair coding functionality (though sadly I canât use the mic/audio while at work) though I think vscode has similar features as well, I can use either if you want pair coding.
Thank you very much! I will start Rust from tomorrow, opening a section on it like this one to ask questions. It would be super good if youâd help me out. And judging from your responses in this thread, I am confident those would be more helpful than the books
I think to start with, I will mostly initially have asynchronously reviewable questions and Github PR-s⊠I already have a few projects in mind. To be able to be pair programming, Iâd need some familiarity with Rust first (I am at Hello World level right now), and it would be great if youâre up for it at that time
I do have Clion. Is the IDE experience of Rust any good? I also checked my Manning and PragProg accounts, looks like I have all Manning Rust books/videos bought (Not sure why and how I did that), none of PragProgâs (Not sure why and how I didnât do that). But I think youâre right, the official âRust Bookâ might be enough, itâs written keeping âeveryoneâ in mind, I felt like.
I canât thank you and @AstonJ enough for motivating me through the journals. I have learned more Crystal and OCaml than I would have if done solo. I am hoping the have better experience with Rust since I have more than just âAdvent of Codeâ and Syntax-level interest in this one
I wish I was as fast a reader as you Mafinar! We definitely have to do some Rust book clubs (I already bought #book-hands-on-rust) but just gotta finish Programming Erlang Book Club first. I hope to get back into it all soon tho - Iâve nearly finished porting our portal system over to one site, then itâs just one more after that and Iâll have more time for books
Youâre welcome and thank YOU for doing them! Iâve enjoyed following all of yours (and everyone elseâs) journals and book clubs
My need for sleep is 3/4 hours a day (any more than that on a non-sick day and I get migraine). So time is on my side; the true enemy is procrastination. Which is why I found this forum to be so useful, I can just jump right in and people join, help and motivate.
On weekends Iâm mostly watching a baby so I wonât have any real computer time, but feel free to ask me questions on Discord or so and I can answer in mostly real time.
Clion and RustAnalyzer (an LSP server, mostly designed to work with VSCode) are the big Rust IDEâs out, they are pretty much on par overall but I still like Clion better as itâs an actual IDE with other useful IDE features, both are very good though.
I can also help with OCaml questions, feel free to ask. ^.^
Yes, spent decent amount of time reading the Rust book and coding some Advent of Code. Feels like this time I wonât give up.
I am starting a thread on it soon. The amount of lessons I learned from just doing 2 day 1 level Advent of Code in Rust is crazy!
My apologies in advance to @OvermindDL1 for all the silly questions Iâll be asking.
Lol! Remember, if you have a question then other people do too, so itâs good to publicly document it! ^.^
Hi folks !
Sorry for the radio silence but I was quit busy later. Iâve get another job and thus, I documented all the stuff etc, it took me a lot of time and energy.
I can start reading and giving you my feedback on the chapters in a couple of weeks.
But unfortunately I would not be able to compare Go and Crystal since Iâll not work with Go.
Hope youâre all well !