9

Programming with Crystal: "A language for humans and computers"

 1 year ago
source link: https://devm.io/ruby/crystal-ruby-programming
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Interview with Beta Ziliani, Team Lead and Product Manager at Manas.Tech

Programming with Crystal: "A language for humans and computers"

03. Jul 2023


We spoke with Beta Ziliani, Team Lead and Product Manager at Manas.Tech, leading the development of the Crystal language to learn all about this Ruby-inspired programming language. Billed as a "language for humans and computers", Crystal is easy to read and write, and compiled efficiently. Let's learn all about it, its future plans, and how you can start programming in Crystal.

devmio: Could you tell our readers a little bit about yourself and what you do?

Beta Ziliani: I’m Beta Ziliani, Team Lead and Product Manager at Manas.Tech, leading the development of the Crystal language for the past two years. I have a PhD in the area of programming languages, so I count myself into the nerdy geeky type. I can even strengthen this stereotype by revealing I’ve been listening to synthwave these past weeks.

devmio: Where does the name Crystal come from?

Beta Ziliani: The origin is rooted in Ruby, the main language Crystal drew inspiration from. Both names refer to precious shiny things.

devmio: How would you describe Crystal, in a few sentences?

Beta Ziliani: Our motto is “A language for humans and computers”: It’s pleasant to read and write (what we humans do), and it compiles to a very efficient program (what computers like).

In many aspects, programming in Crystal feels like programming in an object oriented dynamic language like Ruby or Python, although it’s safe and efficient like statically-typed languages like Java or C#.

Our motto is “A language for humans and computers”: It’s pleasant to read and write (what we humans do), and it compiles to a very efficient program (what computers like).

devmio: What was the motivation for creating the language?

Beta Ziliani: Back in 2010 we were programming in Ruby, and we really enjoyed it: the flexibility of the language, and its lack of bureaucracy required to get things working. At the same time, at Manas.Tech we also coded in Java and C# and, while we weren’t thrilled with the overhead brought by types, we did like to have a typechecker looking after our code, and an efficient program being produced in the end.

So it came kind of natural: can we mix the two; as they say, to have the cake and eat it too? Luckily, Ary, Brian and Juan, the original founders of the language, found how to answer this question positively.

devmio: What are the most significant language features that you think Crystal adds?

Beta Ziliani: In general, Crystal strikes the right balance between the dynamically-typed languages and the statically-typed ones. In particular, it adds duck typing and monkey patching to a statically typed, compiled language. That is rather unique and superb!

Duck typing lets us call a method of an object without having to declare the method in the object’s interface. This is particularly useful when dealing with objects that might have different types according to the path of execution, as it doesn’t require us to specify the method in the types involved. Here is a simple example, where we can call duck.quack even when duck can be a Duck or a Parrot:

class Duck
  def quack
    " quacks!"
  end
end

class Parrot
  def quack
    " quacks!"
  end
end

if rand(2) >= 1    # 
  duck = Duck.new
else
  duck = Parrot.new
end

puts duck.quack

Monkey patching is the possibility to alter an existing class to change its behavior. For instance, it’s possible to add serialization support to existing classes without a fuzz, or add convenience methods to operate a class from a third-party library. For instance, we can make the Duck place an egg even if the class is defined elsewhere:

class Duck  # We’re reopening the class here
  def place_egg
    " drops !"
  end
end

For both features, since Crystal is typed, the typechecker will catch any type error we might unwillingly introduce. And since it has a powerful type inference mechanism, types are rarely seen in a typical Crystal program.

In general, Crystal strikes the right balance between the dynamically-typed languages and the statically-typed ones. In particular, it adds duck typing and monkey patching to a statically typed, compiled language.

devmio: What operating systems does Crystal currently support? Are there plans to add more in the future?

Beta Ziliani: Crystal is fully upported in a large variety of OSes, including macOS, Linux, and various BSDs. Windows support is almost complete and just missing a final polish. In the current minor release (1.8) it’s already usable, and we hope to have it fully supported in the coming months. In terms of chipsets, it’s also fully supported for Intel and ARM-based chips (macOS and Linux). There’s also partial support on Android and WebAssembly.

devmio: Why should one choose Crystal over other programming languages?

Beta Ziliani: One should use the language that best matches one’s own development process and project constraints. For instance, I like to try things quickly, as doing is also discovering. At the same time, I make typos and introduce silly bugs. Once things are working, I reflect back at what I just did and refactor the code to improve its quality.

Crystal is a natural fit in this scenario: you can code quickly and dirty first, with silly bugs being catched by the typechecker, and then you can add all the nice abstractions that modern languages allow, with the typechecker still holding your back. And once the work is done, you get an efficient, easily distributable binary.

devmio: What type of applications is Crystal best suited for?

Beta Ziliani: This is a tough one: the community managed to build all sorts of interesting applications with Crystal. From programming languages to a performant video game music player, and even the kernel of an operating system! But to me the best applications are the amazing web frameworks written in Crystal. CLI tools are a natural fit too.

devmio: How does Crystal compare to Ruby? What commonalities do they have, and will Ruby devs be able to jump right into Crystal?

Beta Ziliani: A large fraction of the syntax and the standard library was conceived standing on the shoulders of Ruby. It gets to the point that simple classes might be ported without a change. And typically Rubyists feel comfortable switching to Crystal. This week, for instance, we saw a nice comment from a gem author that ported it to Crystal.

But Crystal doesn’t aim at being compatible with Ruby (we just happen to like it a lot!), and there are subtle differences that could be confusing. For instance, Crystal has method overloading, and our library makes use of it. Luckily we have resources on the web page to help Rubyists to easily jump into Crystal.

A large fraction of the syntax and the standard library was conceived standing on the shoulders of Ruby. It gets to the point that simple classes might be ported without a change. And typically Rubyists feel comfortable switching to Crystal.

devmio: How big is the community right now?

Beta Ziliani: I’m not sure how to answer this properly, to be honest. I can give you some numbers: 18.5k stars in GitHub, which is quite an achievement when compared to other languages hosted there, 2k daily pageviews in the forum by actual people (that is, without crawlers), more than 400 contributors to the main repository… In short, we’re currently a mid-size, growing and glowing community.

devmio: Are there any notable companies or organizations that are currently using Crystal?

Beta Ziliani: Our two main sponsors are 84codes, a devops company with clients such as Hewlett-Packard, KLM, and Docker; and Nikola, one of the most advanced companies building electric trucks.

devmio: What are the current goals for Crystal?

Beta Ziliani: From the technical side, the most immediate goal is to finish polishing Windows support. Then, we need to strengthen the support for multi-threading and make it more convenient to use. In parallel (no pun intended!), with the help of Mekhla, the new Community Manager of Crystal, we are making efforts to grow and strengthen the community.

In this line of work it is worth mentioning the Crystal Ambassador program we launched this year, incorporating members from the community to help spread the word about Crystal; and a conference that is being lined up this year.

devmio: How may our readers get in touch if they have any interesting suggestions for Crystal's development?

Beta Ziliani: The simplest way is to reach out to the forum, or the other channels listed on the community page. We note this is a 10 year old project, with lots of ideas already poured into the forum and the issue tracker.

Great suggestions might have been made already: searching is caring!

If you come from Ruby and you approach Crystal as if it were a compiler for it, you’ll likely hit a wall. And if you are approaching it from another language, note that each strange thing you note might have a sensible explanation.

devmio: What advice would you give programmers looking to start coding in Crystal?

Beta Ziliani: As with any other language: keep an open mind. If you come from Ruby and you approach Crystal as if it were a compiler for it, you’ll likely hit a wall. And if you are approaching it from another language, note that each strange thing you note might have a sensible explanation.

For instance, many complain about the notions of falsey and truthy values inherited from Ruby. To us, they allow us to code very succinctly!

devmio: What resources are available for learning Crystal, such as books, tutorials, and online courses?

Beta Ziliani: The documentation of the language contains a lot of material, from tutorials to reference manuals and books. I want to bring into attention a recent book by one of the core team members of the language, which offers a great technical introduction of the language and its ecosystem.

Thank you for answering our questions!

Beta Ziliani
Beta Ziliani

Beta Ziliani got into informatics at the age of 10, wanting to program his own computer games. He caught the bug from his dad, who was also a programmer. He went on into electronics with his heart set on robotics. He arrived at Manas in 2005 after 6 years in the industry and stayed until 2009, when the company gave him a scholarship so he could finish his thesis. After graduating, he and his wife toured Europe and soon after he moved there to get a doctorate degree in Germany. Having returned to Argentina, and settling in Cordoba with a research position, he returned to Manas to take on the role of Team Lead & Project Manager for Crystal. Having his heart set on playing drums from a young age, he took a detour into guitar first and eventually reunited with his drumming passion.


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK