Más contenido relacionado Similar a Por qué Crystal? Why Crystal Language? (20) Por qué Crystal? Why Crystal Language?1. Buenos Aires - Crystal Meetup #1
¿Por qué Crystal? Ary Borenszweig
aborenszweig@manas.com.ar
3. Poca ceremonia
# Crystal
puts “Hello world”
~~~
// Java
public class Main {
public static void main(String[] args) {
System.out.println(“Hola mundo!”);
}
}
5. Fácil de leer y escribir
def say_hello()
puts(“Hola mundo!”);
end
say_hello();
6. Fácil de leer y escribir
def say_hello()
puts(“Hola mundo!”)
end
say_hello()
7. Fácil de leer y escribir
def say_hello()
puts “Hola mundo!”
end
say_hello()
8. Fácil de leer y escribir
def say_hello
puts “Hola mundo!”
end
say_hello
9. Apariencia de un lenguaje dinámico
def 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)
13. 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
Threadring
https://github.com/kostya/crystal-benchmarks-game
16. Chequeo de tipos
def 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)
17. Chequeo de tipos
def 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”)
18. Chequeo de tipos
def 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
19. Chequeo de tipos
def 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
20. Chequeo de tipos
def 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
21. Chequeo de tipos
def 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)
22. Chequeo de tipos
def 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)
23. Chequeo de tipos
def 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”)
24. Chequeo de tipos
def 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
25. Alto nivel
numbers = [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”
26. Bajo nivel
ptr = 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]
28. ¿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!
30. 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