36
Buenos Aires - Crystal Meetup #1 ¿Por qué Crystal? Ary Borenszweig [email protected]

Por qué Crystal? Why Crystal Language?

Embed Size (px)

Citation preview

Page 1: Por qué Crystal? Why Crystal Language?

Buenos Aires - Crystal Meetup #1

¿Por qué Crystal? Ary [email protected]

Page 2: Por qué Crystal? Why Crystal Language?

¿Por qué un lenguaje nuevo?

Page 3: Por qué Crystal? Why Crystal Language?

Poca ceremonia# Crystal

puts “Hello world”

~~~

// Java

public class Main {

public static void main(String[] args) {

System.out.println(“Hola mundo!”);

}

}

Page 4: Por qué Crystal? Why Crystal Language?

Fácil de leer y escribir

Page 5: Por qué Crystal? Why Crystal Language?

Fácil de leer y escribir

def say_hello()

puts(“Hola mundo!”);

end

say_hello();

Page 6: Por qué Crystal? Why Crystal Language?

Fácil de leer y escribir

def say_hello()

puts(“Hola mundo!”)

end

say_hello()

Page 7: Por qué Crystal? Why Crystal Language?

Fácil de leer y escribir

def say_hello()

puts “Hola mundo!”

end

say_hello()

Page 8: Por qué Crystal? Why Crystal Language?

Fácil de leer y escribir

def say_hello

puts “Hola mundo!”

end

say_hello

Page 9: Por qué Crystal? Why Crystal Language?

Apariencia de un lenguaje dinámicodef prime?(n)

(2..n).all? { |i| n % i != 0 }

end

def sexy_primes(n)

(9..n).map { |i| {i - 6, i} }

.select { |i| i.all? { prime?(i) } }

end

puts sexy_primes(100_000)

Page 10: Por qué Crystal? Why Crystal Language?

Eficiente

Page 11: Por qué Crystal? Why Crystal Language?

Eficiente

Tiempo (s) Memoria (MB)

C++ 5.08 1.1

Crystal 6.97 1.3

Ruby 226.86 8.0

Brainfuckhttps://github.com/kostya/benchmarks

Page 12: Por qué Crystal? Why Crystal Language?

Eficiente

Tiempo (s) Memoria (MB)

Crystal 15.87 398.1

C++ 17.72 174.5

Python 396.54 724.0

Havlakhttps://github.com/kostya/benchmarks

Page 13: Por qué Crystal? Why Crystal Language?

Eficiente

Tiempo (s) Memoria (MB)

Crystal 0.59 3.3

Go 1.43 2.3

Erlang 1.89 17.1

Ruby 41.73 30.0

Threadringhttps://github.com/kostya/crystal-benchmarks-game

Page 14: Por qué Crystal? Why Crystal Language?

Eficiente

Tiempo (relativo)

Java 1.8.0_66 1.00

Crystal 1.58

Ruby MRI 2.3 47.59

Are we fast yet?http://stefan-marr.de/downloads/crystal.html

Page 15: Por qué Crystal? Why Crystal Language?

Chequeo de tipos

Page 16: Por qué Crystal? Why Crystal Language?

Chequeo de tiposdef prime?(n)

(2..n).all? { |i| n % i != 0 }

end

def sexy_primes(n)

(9..n).map { |i| {i - 6, i} }

.select { |i| i.all? { prime?(i) } }

end

puts sexy_primes(100_000)

Page 17: Por qué Crystal? Why Crystal Language?

Chequeo de tiposdef prime?(n)

(2..n).all? { |i| n % i != 0 }

end

def sexy_primes(n)

(9..n).map { |i| {i - 6, i} }

.select { |i| i.all? { prime?(i) } }

end

puts sexy_primes(“Ups”)

Page 18: Por qué Crystal? Why Crystal Language?

Chequeo de tiposdef prime?(n)

(2..n).all? { |i| n % i != 0 }

end

def sexy_primes(n)

(9..n).map { |i| {i - 6, i} }

.select { |i| i.all? { prime?(i) } }

end

puts sexy_primes(“Ups”) # Error: no overload matches

# `Int32#<` with type String

Page 19: Por qué Crystal? Why Crystal Language?

Chequeo de tiposdef prime?(n)

(2..n).all? { |i| n % i != 0 }

end

def sexy_primes(n)

(9..n).map { |i| {i - 6, i} }

.select { |i| i.all? { prime?(i) } }

end

puts sexy_primes(“Ups”) # Error: no overload matches

# `Int32#<` with type String

Page 20: Por qué Crystal? Why Crystal Language?

Chequeo de tiposdef prime?(n)

(2..n).all? { |i| n % i != 0 }

end

def sexy_primes(n)

(9..n).map { |i| {i - 6, i} }

.select { |i| i.all? { prime?(i) } }

end

puts sexy_primes(“Ups”) # Error: no overload matches

# `Int32#<` with type String

Page 21: Por qué Crystal? Why Crystal Language?

Chequeo de tiposdef prime?(n)

(2..n).all? { |i| n % i != 0 }

end

def sexy_primes(n)

(9..n).map { |i| {i - 6, i} }

.select { |i| i.all? { prime?(i) } }

end

puts sexy_primes(100_000)

Page 22: Por qué Crystal? Why Crystal Language?

Chequeo de tiposdef prime?(n)

(2..n).all? { |i| n % i != 0 }

end

def sexy_primes(n : Int)

(9..n).map { |i| {i - 6, i} }

.select { |i| i.all? { prime?(i) } }

end

puts sexy_primes(100_000)

Page 23: Por qué Crystal? Why Crystal Language?

Chequeo de tiposdef prime?(n)

(2..n).all? { |i| n % i != 0 }

end

def sexy_primes(n : Int)

(9..n).map { |i| {i - 6, i} }

.select { |i| i.all? { prime?(i) } }

end

puts sexy_primes(“Ups”)

Page 24: Por qué Crystal? Why Crystal Language?

Chequeo de tiposdef prime?(n)

(2..n).all? { |i| n % i != 0 }

end

def sexy_primes(n : Int)

(9..n).map { |i| {i - 6, i} }

.select { |i| i.all? { prime?(i) } }

end

puts sexy_primes(“Ups”) # Error: no overload matches

# `sexy_primes` with type String

Page 25: Por qué Crystal? Why Crystal Language?

Alto nivelnumbers = [1, 2, 3, 4]

puts numbers.map { |x| x + 10 } # => [11, 12, 13, 14]

puts numbers[0] + numbers[-1] # => 5

phones = {

“Ary” => “15512312312”,

“Brian” => “1545645645”,

“Juan” => “1578978978”,

}

puts phones[“Brian”] # => “1545645645”

Page 26: Por qué Crystal? Why Crystal Language?

Bajo nivelptr = Pointer(UInt8).malloc(20)

ptr.value = 10_u8

puts ptr # => Pointer(UInt8)@0x109303e00

a = 1

ptr = pointerof(a)

ptr.value = 2

puts a # => 2

buffer = uninitialized UInt8[1024]

Page 27: Por qué Crystal? Why Crystal Language?

Bajo nivel

lib LibC

fun rand : LibC::Int

end

puts LibC.rand # => 16807

Page 28: Por qué Crystal? Why Crystal Language?

¿Por qué un lenguaje nuevo?❖ Poca ceremonia

❖ Fácil de leer y escribir

❖ Apariencia de un lenguaje dinámico

❖ Eficiente

❖ Chequeo de tipos

❖ Alto y bajo nivel

❖ => Felicidad!

Page 29: Por qué Crystal? Why Crystal Language?

¿Para qué sirve?

Page 30: Por qué Crystal? Why Crystal Language?

Aplicaciones de consola❖ tlcr: https://github.com/porras/tlcr

❖ crul: https://github.com/porras/crul

❖ vicr: https://github.com/veelenga/vicr

❖ shards: https://github.com/ysbaddaden/shards

Page 31: Por qué Crystal? Why Crystal Language?

Emuladores❖ nes.cr: https://github.com/romeroadrian/nes.cr

❖ rcpu: https://github.com/ddfreyne/rcpu

Page 32: Por qué Crystal? Why Crystal Language?

Juegos❖ crsfml: https://github.com/BlaXpirit/crsfml

❖ crystal-gl: https://github.com/ggiraldez/crystal-gl

Page 33: Por qué Crystal? Why Crystal Language?

Páginas web❖ crystalshards: https://github.com/zamith/

crystalshards

❖ play.crystal-lang.org: https://github.com/jhass/carc.in

Page 34: Por qué Crystal? Why Crystal Language?

Bots IRC❖ DeBot: https://github.com/jhass/DeBot

Page 35: Por qué Crystal? Why Crystal Language?

Compiladores❖ Crystal: https://github.com/manastech/crystal

Page 36: Por qué Crystal? Why Crystal Language?

¡Gracias!

Ary Borenszweig

email: [email protected]

@asteritetwitter: