SlideShare a Scribd company logo
1 of 25
Download to read offline
Rocks
Brian J. Cardiff
bcardiff@manas.tech
19-Sept-19 @NardozBA@CrystalLanguage
Queremos un lenguaje
● Cómodo y seguro para el programador
● Cómodo para la máquina
Crystal
Syntaxis amena
# file: beetle.cr
3.times do
puts "Beetlejuice!"
end
$ crystal beetle.cr
Beetlejuice!
Beetlejuice!
Beetlejuice!
$ crystal build beetle.cr -o beetle
$ ./beetle
Beetlejuice!
Beetlejuice!
Beetlejuice!
$ otool -L ./beetle
./bettle:
/usr/lib/libpcre.0.dylib (compatibility version 1.0.0, current version
1.1.0)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current
version 1252.250.1)
Compilado
$ crystal build --emit llvm-ir --no-debug beetle.cr
$ cat beetle.ll
@"'Beetlejuice!'" = private constant { i32, i32, i32, [13 x i8] } { i32 1, i32 12, i32 12,
[13 x i8] c"Beetlejuice!00" }
define void @__crystal_main(i32 %argc, i8** %argv) {
alloca:
%i = alloca i32
; ...
while:
%68 = load i32, i32* %i
%69 = icmp slt i32 %68, 3
br i1 %69, label %body, label %exit
body:
Compilado (via LLVM)
Compilado (via LLVM)
while:
%68 = load i32, i32* %i
%69 = icmp slt i32 %68, 3
br i1 %69, label %body, label %exit
body:
%70 = load i32, i32* %i
call void @"*puts<String>:Nil"(%String* bitcast ({ i32, i32, i32, [13 x i8] }*
@"'Beetlejuice!'" to %String*))
%71 = load i32, i32* %i
%72 = add i32 %71, 1
store i32 %72, i32* %i
br label %while
exit:
ret void
$ crystal build --emit asm --no-debug beetle.cr
$ cat beetle.s
LBB0_60:
cmpl $3, 52(%rsp)
jge LBB0_62
leaq "l_'Beetlejuice!'"(%rip), %rax
movq %rax, %rdi
callq "_*puts<String>:Nil"
movl 52(%rsp), %ecx
addl $1, %ecx
movl %ecx, 52(%rsp)
jmp LBB0_60
LBB0_62:
Compilado (via LLVM)
Evitar errores en runtime
puts "Hello Beetlejuice !".upper_case
$ crystal build beetle.cr
In beetle.cr:2:27
2 | puts "Hello Beetlejuice !".upper_case
^---------
Error: undefined method 'upper_case' for String
puts "Hello Beetlejuice !".upcase
$ crystal build beetle.cr
$ ./beetle
Hello Beetlejuice !
Evitar errores en runtime
# file: input.cr
name = gets
puts "Hello #{name.upcase} !"
$ crystal build input.cr
Evitar errores en runtime
# file: input.cr
name = gets
puts "Hello #{name.upcase} !"
$ crystal build input.cr
In input.cr:3:20
3 | puts "Hello #{name.upcase} !"
^-----
Error: undefined method 'upcase' for Nil (compile-time type is (String | Nil))
Evitar errores en runtime
Anotaciones de tipos (methods)
def greet(h)
n = h.name
puts "Hey #{n}! How are you #{n}?"
end
humans = [Human.new("Hiccup")]
greet(humans.first)
def greet(h : Human)
n : String
n = h.name
puts "Hey #{n}! How are you #{n}?"
end
humans = [Human.new("Hiccup")] of Human
greet(humans.first)
Anotaciones de tipos (methods)
Anotaciones de tipos (methods)
def greet(h)
...
humans = [] of Human
greet(humans.first) # (Runtime) Index out of bounds (IndexError)
greet(humans.first?) # (Compile) undefined method 'name' for Nil
def greet(h : Human)
...
greet(humans.first) # (Runtime) Index out of bounds (IndexError)
greet(humans.first?) # (Compile) no overload matches 'greet' with type
(Human | Nil)
class Dragon
def meet(h : Human)
puts "Bite"
end
def meet(d : Dragon)
puts "Play"
end
end
class Human
def meet(h : Human)
puts "Hi #{h.name}, I'm #{name}"
end
def meet(d : Dragon)
puts "Watch & train #{d.name}"
end
end
Multi-dispatch & “duck-typing”
creatures = [Human.new("Hiccup"), Human.new("Astrid"),
Dragon.new("Toothless"), Dragon.new("Fireworm")]
a, b = creatures.sample(2) # => a, b : Human | Dragon
print "#{a.name} meeting #{b.name}: "
a.meet(b)
class Human
@name : String
def initialize(name)
@name = name
end
def name
@name
end
end
Anotaciones de tipos (classes)
class Human
def initialize(@name : String)
end
def name
@name
end
end
class Box(T)
def initialize(@object : T)
end
# Returns the original object
def object : T
@object
end
end
Anotaciones de tipos (generics)
● Heap vs Stack
○ class Vec3
○ struct Vec3
● Stream oriented API
○ puts "Hi #{h.name}!"
○ cout << "Hi " << h.name << "!" (c++ vs alloc intermediate string)
○ def to_s(io : IO) : Nil
● Avoid intermediate allocations
○ JSON::Builder
Aprovechar Recursos
channel = Channel(Int32).new
total_lines = 0
files = Dir.glob("*.cr")
files.each do |f|
spawn do
lines = File.read(f).lines.size
channel.send lines
end
end
files.size.times do
total_lines += channel.receive
end
puts total_lines
Concurrencia
● Fibers (coroutines)
● Managed thread(s) worker(s)
● Blocking API (no callbacks)
“Do not communicate by sharing memory;
instead, share memory by communicating.”
Effective Go
https://golang.org/doc/effective_go.html#sharing
class Object
macro property(name)
@{{name.var}} : {{name.type}}
def {{name.var}} : {{name.type}}
@{{name.var}}
end
def {{name.var}}=(@{{name.var}} : {{name.type}})
end
end
end
Metaprogramación
class Human
property name : String
def initialize(@name)
end
end
Integración con C
// C
double cos(double x);
double y = cos(1.5);
# Crystal
lib C
fun cos(x : Float64) : Float64
end
y = C.cos(1.5)
@[Link("pcre")]
lib LibPCRE
type Pcre = Void*
fun compile = pcre_compile(
pattern : UInt8*,
options : Int,
errptr : UInt8**,
erroffset : Int*,
tableptr : Void*) : Pcre
end
Elecciones en Crystal
● Syntaxis amena
● Compilado
● Evitar errores en runtime cuando se pueda
● Multi-dispatch
● Estáticamente tipado pero con inferencia y “duck-typing”
● Promover buenas prácticas de uso de recursos
● Modelo de programación concurrente
● Metaprogramación
● Integración con C
● from a DB to JSON with Crystal
○ https://manas.tech/blog/2017/01/16/from-a-db-to-json-with-crystal.html
○ https://github.com/crystal-lang/crystal-db
● https://kemalcr.com/
● https://amberframework.org/
● https://luckyframework.org
● samples/2048.cr https://github.com/crystal-lang/crystal/tree/master/samples
● sdl raytracer https://github.com/asterite/crystal_sdl2_examples
● nes https://github.com/asterite/nes.cr
Apps & Frameworks
crystal-lang.org
¿Dónde?
Brian J. Cardiff
bcardiff@manas.tech
¡gracias!

More Related Content

What's hot

Introduction to Python
Introduction to PythonIntroduction to Python
Introduction to PythonKHNOG
 
Vim Hacks (OSSF)
Vim Hacks (OSSF)Vim Hacks (OSSF)
Vim Hacks (OSSF)Lin Yo-An
 
Puerto serialarduino
Puerto serialarduinoPuerto serialarduino
Puerto serialarduinozadkiel_123
 
Workshop on command line tools - day 2
Workshop on command line tools - day 2Workshop on command line tools - day 2
Workshop on command line tools - day 2Leandro Lima
 
Workshop on command line tools - day 1
Workshop on command line tools - day 1Workshop on command line tools - day 1
Workshop on command line tools - day 1Leandro Lima
 
Using the Command Line with Magento
Using the Command Line with MagentoUsing the Command Line with Magento
Using the Command Line with MagentoMatthew Haworth
 
Joshua Wehner - Tomorrows Programming Languages Today
Joshua Wehner - Tomorrows Programming Languages TodayJoshua Wehner - Tomorrows Programming Languages Today
Joshua Wehner - Tomorrows Programming Languages TodayRefresh Events
 
Pop3stat sh
Pop3stat shPop3stat sh
Pop3stat shBen Pope
 
Perl: Coro asynchronous
Perl: Coro asynchronous Perl: Coro asynchronous
Perl: Coro asynchronous Shmuel Fomberg
 
Tomáš Čorej - OpenSSH
Tomáš Čorej - OpenSSHTomáš Čorej - OpenSSH
Tomáš Čorej - OpenSSHwebelement
 
Zsh shell-for-humans
Zsh shell-for-humansZsh shell-for-humans
Zsh shell-for-humansJuan De Bravo
 
Simple tricks to speed you up on the command line
Simple tricks to speed you up on the command lineSimple tricks to speed you up on the command line
Simple tricks to speed you up on the command lineJanos Gyerik
 
Le wagon - JavaScript for beginners
Le wagon - JavaScript for beginnersLe wagon - JavaScript for beginners
Le wagon - JavaScript for beginnersEdward_Schults
 
Le Wagon - Javascript for Beginners
Le Wagon - Javascript for BeginnersLe Wagon - Javascript for Beginners
Le Wagon - Javascript for BeginnersSébastien Saunier
 
お題でGroovyプログラミング: Part A
お題でGroovyプログラミング: Part Aお題でGroovyプログラミング: Part A
お題でGroovyプログラミング: Part AKazuchika Sekiya
 
第一回MongoDBソースコードリーディング
第一回MongoDBソースコードリーディング第一回MongoDBソースコードリーディング
第一回MongoDBソースコードリーディングnobu_k
 

What's hot (20)

Introduction to Python
Introduction to PythonIntroduction to Python
Introduction to Python
 
Var and Ops quiz
Var and Ops quizVar and Ops quiz
Var and Ops quiz
 
Vim Hacks (OSSF)
Vim Hacks (OSSF)Vim Hacks (OSSF)
Vim Hacks (OSSF)
 
Puerto serialarduino
Puerto serialarduinoPuerto serialarduino
Puerto serialarduino
 
Workshop on command line tools - day 2
Workshop on command line tools - day 2Workshop on command line tools - day 2
Workshop on command line tools - day 2
 
Workshop on command line tools - day 1
Workshop on command line tools - day 1Workshop on command line tools - day 1
Workshop on command line tools - day 1
 
Unfiltered Unveiled
Unfiltered UnveiledUnfiltered Unveiled
Unfiltered Unveiled
 
Using the Command Line with Magento
Using the Command Line with MagentoUsing the Command Line with Magento
Using the Command Line with Magento
 
Joshua Wehner - Tomorrows Programming Languages Today
Joshua Wehner - Tomorrows Programming Languages TodayJoshua Wehner - Tomorrows Programming Languages Today
Joshua Wehner - Tomorrows Programming Languages Today
 
Pop3stat sh
Pop3stat shPop3stat sh
Pop3stat sh
 
Perl: Coro asynchronous
Perl: Coro asynchronous Perl: Coro asynchronous
Perl: Coro asynchronous
 
Tomáš Čorej - OpenSSH
Tomáš Čorej - OpenSSHTomáš Čorej - OpenSSH
Tomáš Čorej - OpenSSH
 
Zsh shell-for-humans
Zsh shell-for-humansZsh shell-for-humans
Zsh shell-for-humans
 
Comets notes
Comets notesComets notes
Comets notes
 
Simple tricks to speed you up on the command line
Simple tricks to speed you up on the command lineSimple tricks to speed you up on the command line
Simple tricks to speed you up on the command line
 
Le wagon - JavaScript for beginners
Le wagon - JavaScript for beginnersLe wagon - JavaScript for beginners
Le wagon - JavaScript for beginners
 
Le Wagon - Javascript for Beginners
Le Wagon - Javascript for BeginnersLe Wagon - Javascript for Beginners
Le Wagon - Javascript for Beginners
 
お題でGroovyプログラミング: Part A
お題でGroovyプログラミング: Part Aお題でGroovyプログラミング: Part A
お題でGroovyプログラミング: Part A
 
第一回MongoDBソースコードリーディング
第一回MongoDBソースコードリーディング第一回MongoDBソースコードリーディング
第一回MongoDBソースコードリーディング
 
dplyr
dplyrdplyr
dplyr
 

Similar to Crystal Rocks

Crystal presentation in NY
Crystal presentation in NYCrystal presentation in NY
Crystal presentation in NYCrystal Language
 
Clojure Intro
Clojure IntroClojure Intro
Clojure Introthnetos
 
Hypers and Gathers and Takes! Oh my!
Hypers and Gathers and Takes! Oh my!Hypers and Gathers and Takes! Oh my!
Hypers and Gathers and Takes! Oh my!Workhorse Computing
 
Shoulders of giants: Languages Kotlin learned from
Shoulders of giants: Languages Kotlin learned fromShoulders of giants: Languages Kotlin learned from
Shoulders of giants: Languages Kotlin learned fromAndrey Breslav
 
Automatically Tolerating And Correcting Memory Errors
Automatically Tolerating And Correcting Memory ErrorsAutomatically Tolerating And Correcting Memory Errors
Automatically Tolerating And Correcting Memory ErrorsEmery Berger
 
ShellProgramming and Script in operating system
ShellProgramming and Script in operating systemShellProgramming and Script in operating system
ShellProgramming and Script in operating systemvinitasharma749430
 
Unleash your inner console cowboy
Unleash your inner console cowboyUnleash your inner console cowboy
Unleash your inner console cowboyKenneth Geisshirt
 
HTML5 JavaScript Interfaces
HTML5 JavaScript InterfacesHTML5 JavaScript Interfaces
HTML5 JavaScript InterfacesAaron Gustafson
 
Streams of information - Chicago crystal language monthly meetup
Streams of information - Chicago crystal language monthly meetupStreams of information - Chicago crystal language monthly meetup
Streams of information - Chicago crystal language monthly meetupBrian Cardiff
 
LLVM Workshop Osaka Umeda, Japan
LLVM Workshop Osaka Umeda, JapanLLVM Workshop Osaka Umeda, Japan
LLVM Workshop Osaka Umeda, Japanujihisa
 
Ruby 程式語言入門導覽
Ruby 程式語言入門導覽Ruby 程式語言入門導覽
Ruby 程式語言入門導覽Wen-Tien Chang
 
Nosql hands on handout 04
Nosql hands on handout 04Nosql hands on handout 04
Nosql hands on handout 04Krishna Sankar
 
Groovy Fly Through
Groovy Fly ThroughGroovy Fly Through
Groovy Fly Throughniklal
 

Similar to Crystal Rocks (20)

Crystal presentation in NY
Crystal presentation in NYCrystal presentation in NY
Crystal presentation in NY
 
Clojure Intro
Clojure IntroClojure Intro
Clojure Intro
 
Hypers and Gathers and Takes! Oh my!
Hypers and Gathers and Takes! Oh my!Hypers and Gathers and Takes! Oh my!
Hypers and Gathers and Takes! Oh my!
 
2015 555 kharchenko_ppt
2015 555 kharchenko_ppt2015 555 kharchenko_ppt
2015 555 kharchenko_ppt
 
Shoulders of giants: Languages Kotlin learned from
Shoulders of giants: Languages Kotlin learned fromShoulders of giants: Languages Kotlin learned from
Shoulders of giants: Languages Kotlin learned from
 
Automatically Tolerating And Correcting Memory Errors
Automatically Tolerating And Correcting Memory ErrorsAutomatically Tolerating And Correcting Memory Errors
Automatically Tolerating And Correcting Memory Errors
 
ShellProgramming and Script in operating system
ShellProgramming and Script in operating systemShellProgramming and Script in operating system
ShellProgramming and Script in operating system
 
Unleash your inner console cowboy
Unleash your inner console cowboyUnleash your inner console cowboy
Unleash your inner console cowboy
 
An introduction to Ruby
An introduction to RubyAn introduction to Ruby
An introduction to Ruby
 
HTML5 JavaScript Interfaces
HTML5 JavaScript InterfacesHTML5 JavaScript Interfaces
HTML5 JavaScript Interfaces
 
Streams of information - Chicago crystal language monthly meetup
Streams of information - Chicago crystal language monthly meetupStreams of information - Chicago crystal language monthly meetup
Streams of information - Chicago crystal language monthly meetup
 
Smalltalk on rubinius
Smalltalk on rubiniusSmalltalk on rubinius
Smalltalk on rubinius
 
Effective Object Oriented Design in Cpp
Effective Object Oriented Design in CppEffective Object Oriented Design in Cpp
Effective Object Oriented Design in Cpp
 
LLVM Workshop Osaka Umeda, Japan
LLVM Workshop Osaka Umeda, JapanLLVM Workshop Osaka Umeda, Japan
LLVM Workshop Osaka Umeda, Japan
 
Ruby 程式語言入門導覽
Ruby 程式語言入門導覽Ruby 程式語言入門導覽
Ruby 程式語言入門導覽
 
First steps in C-Shell
First steps in C-ShellFirst steps in C-Shell
First steps in C-Shell
 
Shell programming
Shell programmingShell programming
Shell programming
 
Nosql hands on handout 04
Nosql hands on handout 04Nosql hands on handout 04
Nosql hands on handout 04
 
Ruby
RubyRuby
Ruby
 
Groovy Fly Through
Groovy Fly ThroughGroovy Fly Through
Groovy Fly Through
 

Recently uploaded

Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptxLBM Solutions
 
How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?XfilesPro
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...HostedbyConfluent
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 

Recently uploaded (20)

Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptx
 
How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food Manufacturing
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 

Crystal Rocks

  • 2. Queremos un lenguaje ● Cómodo y seguro para el programador ● Cómodo para la máquina Crystal
  • 3. Syntaxis amena # file: beetle.cr 3.times do puts "Beetlejuice!" end $ crystal beetle.cr Beetlejuice! Beetlejuice! Beetlejuice!
  • 4. $ crystal build beetle.cr -o beetle $ ./beetle Beetlejuice! Beetlejuice! Beetlejuice! $ otool -L ./beetle ./bettle: /usr/lib/libpcre.0.dylib (compatibility version 1.0.0, current version 1.1.0) /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1252.250.1) Compilado
  • 5. $ crystal build --emit llvm-ir --no-debug beetle.cr $ cat beetle.ll @"'Beetlejuice!'" = private constant { i32, i32, i32, [13 x i8] } { i32 1, i32 12, i32 12, [13 x i8] c"Beetlejuice!00" } define void @__crystal_main(i32 %argc, i8** %argv) { alloca: %i = alloca i32 ; ... while: %68 = load i32, i32* %i %69 = icmp slt i32 %68, 3 br i1 %69, label %body, label %exit body: Compilado (via LLVM)
  • 6. Compilado (via LLVM) while: %68 = load i32, i32* %i %69 = icmp slt i32 %68, 3 br i1 %69, label %body, label %exit body: %70 = load i32, i32* %i call void @"*puts<String>:Nil"(%String* bitcast ({ i32, i32, i32, [13 x i8] }* @"'Beetlejuice!'" to %String*)) %71 = load i32, i32* %i %72 = add i32 %71, 1 store i32 %72, i32* %i br label %while exit: ret void
  • 7. $ crystal build --emit asm --no-debug beetle.cr $ cat beetle.s LBB0_60: cmpl $3, 52(%rsp) jge LBB0_62 leaq "l_'Beetlejuice!'"(%rip), %rax movq %rax, %rdi callq "_*puts<String>:Nil" movl 52(%rsp), %ecx addl $1, %ecx movl %ecx, 52(%rsp) jmp LBB0_60 LBB0_62: Compilado (via LLVM)
  • 8. Evitar errores en runtime puts "Hello Beetlejuice !".upper_case $ crystal build beetle.cr In beetle.cr:2:27 2 | puts "Hello Beetlejuice !".upper_case ^--------- Error: undefined method 'upper_case' for String
  • 9. puts "Hello Beetlejuice !".upcase $ crystal build beetle.cr $ ./beetle Hello Beetlejuice ! Evitar errores en runtime
  • 10. # file: input.cr name = gets puts "Hello #{name.upcase} !" $ crystal build input.cr Evitar errores en runtime
  • 11. # file: input.cr name = gets puts "Hello #{name.upcase} !" $ crystal build input.cr In input.cr:3:20 3 | puts "Hello #{name.upcase} !" ^----- Error: undefined method 'upcase' for Nil (compile-time type is (String | Nil)) Evitar errores en runtime
  • 12. Anotaciones de tipos (methods) def greet(h) n = h.name puts "Hey #{n}! How are you #{n}?" end humans = [Human.new("Hiccup")] greet(humans.first)
  • 13. def greet(h : Human) n : String n = h.name puts "Hey #{n}! How are you #{n}?" end humans = [Human.new("Hiccup")] of Human greet(humans.first) Anotaciones de tipos (methods)
  • 14. Anotaciones de tipos (methods) def greet(h) ... humans = [] of Human greet(humans.first) # (Runtime) Index out of bounds (IndexError) greet(humans.first?) # (Compile) undefined method 'name' for Nil def greet(h : Human) ... greet(humans.first) # (Runtime) Index out of bounds (IndexError) greet(humans.first?) # (Compile) no overload matches 'greet' with type (Human | Nil)
  • 15. class Dragon def meet(h : Human) puts "Bite" end def meet(d : Dragon) puts "Play" end end class Human def meet(h : Human) puts "Hi #{h.name}, I'm #{name}" end def meet(d : Dragon) puts "Watch & train #{d.name}" end end Multi-dispatch & “duck-typing” creatures = [Human.new("Hiccup"), Human.new("Astrid"), Dragon.new("Toothless"), Dragon.new("Fireworm")] a, b = creatures.sample(2) # => a, b : Human | Dragon print "#{a.name} meeting #{b.name}: " a.meet(b)
  • 16. class Human @name : String def initialize(name) @name = name end def name @name end end Anotaciones de tipos (classes) class Human def initialize(@name : String) end def name @name end end
  • 17. class Box(T) def initialize(@object : T) end # Returns the original object def object : T @object end end Anotaciones de tipos (generics)
  • 18. ● Heap vs Stack ○ class Vec3 ○ struct Vec3 ● Stream oriented API ○ puts "Hi #{h.name}!" ○ cout << "Hi " << h.name << "!" (c++ vs alloc intermediate string) ○ def to_s(io : IO) : Nil ● Avoid intermediate allocations ○ JSON::Builder Aprovechar Recursos
  • 19. channel = Channel(Int32).new total_lines = 0 files = Dir.glob("*.cr") files.each do |f| spawn do lines = File.read(f).lines.size channel.send lines end end files.size.times do total_lines += channel.receive end puts total_lines Concurrencia ● Fibers (coroutines) ● Managed thread(s) worker(s) ● Blocking API (no callbacks) “Do not communicate by sharing memory; instead, share memory by communicating.” Effective Go https://golang.org/doc/effective_go.html#sharing
  • 20. class Object macro property(name) @{{name.var}} : {{name.type}} def {{name.var}} : {{name.type}} @{{name.var}} end def {{name.var}}=(@{{name.var}} : {{name.type}}) end end end Metaprogramación class Human property name : String def initialize(@name) end end
  • 21. Integración con C // C double cos(double x); double y = cos(1.5); # Crystal lib C fun cos(x : Float64) : Float64 end y = C.cos(1.5) @[Link("pcre")] lib LibPCRE type Pcre = Void* fun compile = pcre_compile( pattern : UInt8*, options : Int, errptr : UInt8**, erroffset : Int*, tableptr : Void*) : Pcre end
  • 22. Elecciones en Crystal ● Syntaxis amena ● Compilado ● Evitar errores en runtime cuando se pueda ● Multi-dispatch ● Estáticamente tipado pero con inferencia y “duck-typing” ● Promover buenas prácticas de uso de recursos ● Modelo de programación concurrente ● Metaprogramación ● Integración con C
  • 23. ● from a DB to JSON with Crystal ○ https://manas.tech/blog/2017/01/16/from-a-db-to-json-with-crystal.html ○ https://github.com/crystal-lang/crystal-db ● https://kemalcr.com/ ● https://amberframework.org/ ● https://luckyframework.org ● samples/2048.cr https://github.com/crystal-lang/crystal/tree/master/samples ● sdl raytracer https://github.com/asterite/crystal_sdl2_examples ● nes https://github.com/asterite/nes.cr Apps & Frameworks