 good start okay cool hi today I will talk to you about crystal language but first because before we get to this topic a little bit of introduction so all the languages that we're using be it the spoken languages like English or being programming languages are inspired by others every single language that you know has some words some grammar structure some influence from from the other languages so in English even though it might be difficult to believe we have some words from Japanese from Chinese and even from East Frischan which is language from I don't know probably Middle East the same the same with programming languages so when Ruby was created Mats had a few inspirations he really liked Pearl but he wanted to create better Pearl so Robi is a scripting language Mats really loved Emacs and the the Lisp that you can use to program Emacs so Robi has closures and then everything in Ruby is an object which is an idea taken from small talk so as languages are inspired by other languages then when they are major they also provide some information they are copied to other languages so words from English are used in various different languages like Polish Spanish or even Japanese and how about Ruby there are different languages that use beat syntax or methods names or some grammar constructs from Ruby so there is Groovy which is a language working on Java virtual machine there is Elixir which was created by Jose Valim who is a core team member of of Ruby on Rails and now created his own language and there is Crystal which is the topic of my today's talk so in this talk I will try to tell you about the language and I will try to answer the question if Crystal the language heavily influenced by Ruby can be the next Ruby or is it totally misguided idea just a brief information the project started in 2012 but it's still unstable the current version is 0.7.4 so it's just three years old and it hasn't gained a lot of popularity yet Crystal is totally written in Crystal so you can go to GitHub you can read in source code and you can see that the whole language is written in itself it started being written by in Ruby but when the language reached some level of maturity they switch the compiler they switch the whole source code to Crystal language it still has unstable API which has some consequences about which I will I will talk later and one important point is that syntax is inspired by Ruby and probably the word inspired is a bit of underestimation so why should we why should we think about other languages if we have something like Ruby with amazing beautiful syntax with lots of great features be it for example metaprogramming with fantastic community full of very active developers and plenty of libraries some of the libraries that are now available in lots of different languages actually started in Ruby for example there is a library called VCR which records HTTP responses and later caches them this started as a project created in Ruby and later was ported to Python PHP and various other languages so Ruby community is very active very creative and creates lots of fantastic projects but Ruby except for its strengths has problems speed is very well-known problem in Ruby and even though with every new version we hear that Ruby is becoming faster and faster you can meet a lot of people who started to rewriting their code base to languages like Rust or Go just because they are so much faster and other issues concurrency we all know that Ruby doesn't handle well threats and there are different opinions there are different plans how to solve it in the next version but for now it is a big problem in the language then reopening classes which is considered a great feature of the language and fantastic idea but it can cause lots of unexpected problems if you require a module that overwrites core class you may unexpectedly have have some errors or some problems with your code and the code in Ruby even though it is really beautiful it becomes hard to maintain for various reasons that I will mention later in my talk crystals approach these problems our first compiler so we achieve speed by executing byte code we do not have an interpreter that that interprets the code on the fly when it's executed so first you have to compile crystals code and it uses LLVM which is a set of compiler tools so how it works is that crystal code is compiled to intermediate language which then is compiled to native byte code for your machine it's it makes it much faster than any interpreted language then instead of working with threats and processes you are working with abstractions like routines and channels which I will mention later another interesting idea is that you have optional types which prevents you from for example providing Neil and having a crush that every one of us has seen thousands of times and then macros which are kind of replacement for meta metaprogramming so when I mentioned that crystal syntax is influenced by Ruby or inspired by Ruby what I really meant is that it is a valid Ruby syntax so this is valid crystal code and except for one small exception here if you code if you copy this code and paste and run as a Ruby file it would it would run so we define methods with the keyword dev we use instance variables use at in in front of them and class variables use double at in front of them we have keywords like if and unless we have blocks blocks to which we provide variables exactly the same way and we have lambdas and prox which we call by putting dot call the only difference here is this one question mark so this actually is to the whole phrase so if you square brackets with question mark in the end it is valid crystal syntax while in Ruby this is beginning of trinary operators so we need to have some expression and then colon and another expression to be the valid code but this is just a just a small difference there are a few more differences which is as I mentioned optional types so you can write a few methods with the same name and specify what types does this method accept it can be either a single type it can be a list of types like in the second example or it can be no type which means that method will accept any any argument another interesting alternative the difference between Ruby and crystal is something called struct so it is basically the same as a class so for user there is there for developer there is really no difference the only the only thing that differentiates structs from class is that it is allocated on a stack instead of on a heap which makes it much faster so when you provide when you pass an object as an argument to a function in Ruby it is always passed by reference while in crystal if it's a if it's a class it's passed by reference but if it's a struct it's passed by value this is just an optimization so if you want to have some small objects that you need to pass around very fast you just use structs instead of a reader writer and accessor we've got getter setter and property and instead of providing a simple as an argument you provide the name of the getter or setter we have a class called tuple which is basically an array but it has a limited size so when you create a tuple with three elements it will always have three elements it cannot grow bigger and this is something that I really love in Ruby community there are constant arguments about whether to use single or double quotes and there are each side has its has their advantages but in crystal it is solved different way if you use double quotes is a string if you single quote is just a single character so the problem is solved on the level of the language syntax as I mentioned before crystal is compiled language it doesn't have an interpreter what does it mean probably most of you have used some compiled language like C Java or or C++ in your life but but maybe not everyone has used it so in Ruby I can write code like this I have a method called add to array and this method adds new element then adds all the elements together and divides them by two if I provide the number be integer or float it will of course work but if I provide a string as an argument here it will crash and the moment that it will crash will be when I run the program so I have no idea if my program is correct or not until I execute it or unless I write tests having compiler crystal will first throw an error here if you create an empty array you have to specify a type but you don't have to do it if you provide some elements in the beginning so if I put an integer or a string here the array will have type integer or string but if it's an empty array I need to provide types then the second error will appear because it appears that there is no some method for an array that contains strings so to fix it I need to remove string from my list of arguments and then if I provide a string as an argument to my function there is another compiler error because my because my array contains only of integers so it cannot hold any string and only after I fix all these errors my program will compile so then it is the moment when I can run it it has its advantages and disadvantages one of the main points of using compiler is that it prevents program for crashing during runtime and because of that you don't have to write so many unit tests as in as in interpreted languages the third big issue with Ruby is concurrency and currently we have threats and processes so when you write Ruby code you operate directly on this very low level abstraction that's very close to the operating system unfortunately you cannot execute multiple threats at the same time because Ruby has global virtual machine lock which makes it that one threat locks the whole code and prevents other threats from executing it this is because when Matt created Ruby he had an idea of making programmers happy and he said that threads don't make programmers happy they make programming very difficult and he wanted to solve this problem so so it is solved this way but over the years programmers realized that our machines are not getting faster anymore instead we are getting more processors more cores so we need to have we need to be able to handle concurrency and parallelism in a much better way so there are lots of different ideas on how it will be solved in Ruby free but there is still at least a few years until this version of language will be released and it is still not known how this problem exactly will be solved so when I want to when I want to run concurrent code in Ruby I operate directly on this on this very low level abstractions while in crystal we are using channel and routines that are inspired by go language however it is still on a very very early stage so even though channels and routines work underneath the virtual machine the runtime doesn't create new threads automatically so basically at this point it is not better than Ruby at all except that probably by the 1.0 version it will already have this problem solved so right now I can do something like this in crystal so I spawn some some routines I create a channel and I send variables to the channel and this channel in a in this loop receives the information and then then then put some text but as I said this will this will run synchronously this will not spawn multiple threads and it will not be spread across multiple cores automatically Ruby is very well known for metaprogramming because it's an interpreted language you can actually accept a string from from user and you can evaluate it as a source code whether it is a good idea or not I leave it up to you but Ruby is very well known and there are even books talking only about metaprogramming in Ruby so I can do something like this I can have a bunch of strings and for each of them I can define a method and then I just define whatever whatever I want in this method Ruby has also some lower level metaprogramming like just the infamous eval function so I can I can call eval I can provide any string as a parameter and it will be executed as Ruby code because crystal is compiled language it cannot create it cannot interpret the code on the fly the idea to solve it is to use macros so this is not as beautiful as Ruby it is quite limited to be honest and probably lots of people who really like metaprogramming will not be able to fully enjoy the idea of macros in crystal but it will solve most of the cases where you need to dynamically create methods or when you have a method missing some of the macros are already predefined like define method or or method missing but this is a syntax that allows you to create your own macros and then you can define your own methods using strings one limitation here is that you cannot provide a variable instead of this string it has to be hard-coded in your code it cannot be variable because then you have to because crystal doesn't know what does variable might be it might be a string it might be nil it might be something else and because it's type language it cannot handle it there are many more things about crystal that are already available but I don't really have much time to talk about them in this presentation and to be honest I don't really I don't really feel confident enough to talk about them so you can write C functions directly using crystal so you can just use any available library and bind it to your program there is a there are pointers that are con consider very unsafe but if you're good low-level programmers maybe maybe you can have some advantage of using them you have type reflection which means that variables can can ask answer your question if they respond to some method there is metal called finalize which will be run on an object just before it is garbage collected there are some generics and their attributes which to be honest I haven't I haven't dug into yet but there are some interesting ideas that definitely will make the language more powerful in the future so is crystal wolf worth trying I'm not authority I'm not very proficient many programming languages but there is a guy who says that it is worth trying so Matt himself supports development of crystal right now there is there is the fundraising it has just started like two or three days ago and Matt's actively supports crystal so I'm not sure why if there he sees it as a as a great development of ideas that started in Ruby or maybe he doesn't think that the language is a competitor I don't know anyway if Matt supports it then probably it's a good idea so why did I check out crystal why do I think that it's interested interesting languages so if you need to make your Ruby code a bit faster you can just save it as a crystal file and and run run in a compiler and you've got executable file that in like some 80 90 percent will be a correct correct crystal code the source code is very easy to understand it is something that for me it's very difficult in Ruby because if I read Ruby code I feel like stupid because I barely no see so if I want to understand some Ruby code usually I go to Rubinius but Rubinius is not always up to date with the newest Ruby version so crystal is written entirely in crystal which means that if you understand Ruby you can go to the github and and very easily reads its source code then the concurrency abstraction when finally version 1.0 is released they it should be able to handle the concurrency the parallel is much better than Ruby has at this point and if you go to the Google mailing group of crystal lang you can see many interesting discussions about how to introduce new syntax whether the old syntax should change how to how to tackle certain problems so Ruby is very major language it is over 20 years old and crystal is very young so it's interesting to observe and to read how the how the language is created you can do the same with some other languages that are very early like elixir or Rust but these are written in low-level languages which makes it much more difficult to read their source code I wouldn't recommend to use crystal in production right now because it is still very early stage and maybe when the new version is released your code will not run anymore there is also lack of documentation so of course you can read source code and it's very easy but it takes much more time than just reading well-written documentation there are few libraries the most popular library except for the language itself has like 150 stars on github so you see the community is still very small but there is already web framework and there is already library that connects crystal with PostgreSQL so you can write some small web application and the last reason why I do not recommend it is that if you want to learn something new you should go as far from Ruby as possible you should learn something like Rust or Erlang or maybe something totally different like Julia so crystal is too similar to Ruby to really broaden your horizons but anyway I think this is language that has some future and I'm really looking forward to see to see the next versions so you can go to the website crystal-lang.org you can check the documentation if you find some bug you can fix the documentation and you can join the very small but the community of very early stage of a language so there are lots of chances lots of opportunities to shape how the language looks like and to help it grow thank you for listening questions