Crystal: A Better Ruby?

Serdar Doğruyol

@sdogruyol

  • Open Source Wizard
  • Rubyist
  • Crystal contributor / evangelist
  • Kemal author
  • Polyglot

Serdar Doğruyol

  • Dynamically typed
  • Metaprogramming
  • GIL
  • No async
  • Legacy / Weird Stuff

Ruby

Dynamically Typed

def full_name(first_name, last_name)
  first_name + last_name
end

NoMethodError: undefined method `+' for nil:NilClass

 

Metaprogramming

  • #send
  • #eval
  • #define_method
  • ....

BUT

RUNTIME IS SLOOO..........W

GIL

a.k.a

I WONT INTERPRET YOUR CODE IN PARALLEL

No Async

Just use concurrent-ruby

Guilds?

ko1's proposal for Ruby 3.0 

Legacy / Weird Stuff

Double Quotes

VS

Single Quotes

ENGRISH

include? anyone

require

load

autoload

Bazillions of aliases

#size

#length

Ruby is awesome!

  • Statically typed
  • Macros
  • LLVM
  • CSP
  • NO Legacy / Weird Stuff

Crystal

Statically Typed

def full_name(first_name, last_name)
  first_name + last_name
end

crystal build full_name.cr

./full_name

Error in line 5: instantiating 'full_name(Nil, String)' in line 2: undefined method '+' for Nil

Macros

  • NO #send
  • NO #eval
  • NO RUN-TIME

COMPILE-TIME

LLVM

--release

free optimizations!

CSP

a.k.a

Communicating Sequential Processes

require "socket"

channel = Channel(String).new

spawn do
  server = TCPServer.new("0.0.0.0", 8080)
  socket = server.accept
  while line = socket.gets
    channel.send(line)
  end
end

spawn do
  while line = gets
    channel.send("Echo: #{line}")
  end
end

loop do
  puts channel.receive
end

No Legacy / Weird Stuff

ENGLISH

includes?

contains?

require

No Aliases

class Human
  
  def initialize(@first_name, @last_name, @skills)
  end

end

Human.new "Serdar", "Dogruyol", ["ruby", "crystal"]

crystal tool format

crystal play

Union Types

Int32 | String

Crystal is awesome!

Thanks

@sdogruyol

https://slides.com/sdogruyol/crystal-a-better-ruby

Made with Slides.com