SlideShare una empresa de Scribd logo
1 de 70
The Origamist’s Ruby
折り紙作家のルビー
@halogenandtoast
Matthew "Goose" Mongeau
https://github.com/halogenandtoast
@halogenandtoast
Matthew "Goose" Mongeau
https://github.com/halogenandtoast
グース
@halogenandtoast
Matthew "Goose" Mongeau
https://github.com/halogenandtoast
What is this talk
about?
"Not all code needs to
be a factory, some of it
can just be origami."
- _why
"A programmer who subconsciously
views himself as an artist will enjoy
what he does and will do it better."
- Donald Knuth
What is Origami?
The art of
folding paper.
Demonstration
O o
Imagination Required
ガオー
Origami is Art
Origami is Art
It’s beautiful.
Origami is Art
It’s beautiful.
It’s creative.
It’s beautiful.
It’s creative.
It’s expressive.
Origami is Art
What is
Programming?
The art of
writing code.
Code is Art
Code is Art
It’s beautiful.
Code is Art
It’s beautiful.
It’s creative.
Code is Art
It’s beautiful.
It’s creative.
It’s expressive.
How do you write
beautiful code?
Simplicity
単純
Code should be simple
to understand.
def play
puts "Welcome to the guessing game."
3.times do
guess = get_guess
if won? guess
@won = true
puts "You win!"
break
else
puts "Wrong!"
end
end
if !@won
puts "You lost.The actual number is #{@actual_number}."
end
end
def play
puts "Welcome to the guessing game."
3.times do
guess = get_guess
if won? guess
@won = true
puts "You win!"
break
else
puts "Wrong!"
end
end
if !@won
puts "You lost.The actual number is #{@actual_number}."
end
end
def play
print_header
play_rounds
print_results
end
def play
puts "Welcome to the guessing game."
play_rounds
print_results
end
def play
print_header
play_rounds
print_results
end
Complexity
複雑
How do you balance
simplicity and complexity?
def play_rounds
round_count.times do
if correct_guess? get_guess
@won = true
break
else
puts "Wrong!"
end
end
end
def play_rounds
@won = round_count.times.detect { play_round }
end
def play_round
if correct_guess? get_guess
true
else
puts "Wrong!"
end
end
Constraints
規制
Origami’s Constraints
Origami’s Constraints
Must use a single sheet of paper.
Origami’s Constraints
Must use a single sheet of paper.
Must be in the shape of a square.
Must use a single sheet of paper.
Must be in the shape of a square.
Must not cut the square.
Origami’s Constraints
Code Constraints
Code Constraints*
*Borrowed from Sandi Metz
Code Constraints*
*Borrowed from Sandi Metz
Methods can be no longer than 5 lines.
Code Constraints*
*Borrowed from Sandi Metz
Methods can be no longer than 5 lines.
Classes can be no longer than 100 lines.
Code Constraints*
*Borrowed from Sandi Metz
Methods can be no longer than 5 lines.
Classes can be no longer than 100 lines.
Methods cannot take more than 4 arguments.
def play
puts "Welcome to the guessing game."
3.times do
guess = get_guess
if won? guess
@won = true
puts "You win!"
break
else
puts "Wrong!"
end
end
if !@won
puts "You lost.The actual number is #{@actual_number}."
end
end
def play
print_header
play_rounds
print_results
end
def play_rounds
round_count.times do
if correct_guess? get_guess
@won = true
break
else
puts "Wrong!"
end
end
end
def play_rounds
@won = round_count.times.detect { play_round }
end
def play_round
if correct_guess? get_guess
true
else
puts "Wrong!"
end
end
http://www.flickr.com/photos/ardonik/3954691105/sizes/l/in/photostream/
Breaking the Rules
違反
"Learn the rules like a
pro, so you can break
them like an artist."
- Pablo Picasso
def play_round
if correct_guess? get_guess
true
else
puts "Wrong!"
end
end
def play_round
if correct_guess? get_guess
puts "Correct"
true
else
puts "Wrong!"
false
end
end
def play_round
if correct_guess? get_guess
correct_guess
else
incorrect_guess
end
end
def incorrect_guess
puts "Wrong!"
false
end
def correct_guess
puts "Correct"
false
end
class Guess
def initialize actual_number
@actual_number = actual_number
@guess = get_guess
end
def status
if correct?
"Correct"
else
"Incorrect"
end
end
def correct?
guess == actual_number
end
private
attr_reader :guess, :actual_number
def get_guess
print "What is your guess: "
gets.to_i
end
end
class Guess
def initialize actual_number
@actual_number = actual_number
@guess = get_guess
end
def status
if correct?
"Correct"
else
"Incorrect"
end
end
def correct?
guess == actual_number
end
private
attr_reader :guess, :actual_number
def get_guess
print "What is your guess: "
gets.to_i
end
end
def play_round
guess = Guess.new(actual_number)
puts guess.display_status
guess.correct?
end
How to be an artist
Be inspired by others
Surround yourself with
talented artists
Surround yourself with
talented artists
Use well known
techniques
Use well known
techniques
Measure improvement
Have feelings
Know when to break
the rules
Have fun.
RUBYKAIGI
$20 off first month
Prime
learn.thoughtbot.com/prime
Questions?

Más contenido relacionado

Destacado (8)

Network simulator 2 a simulation tool for linux
Network simulator 2 a simulation tool for linuxNetwork simulator 2 a simulation tool for linux
Network simulator 2 a simulation tool for linux
 
First One
First OneFirst One
First One
 
Ns doc
Ns docNs doc
Ns doc
 
3 Pillars of Universal Design
3 Pillars of Universal Design3 Pillars of Universal Design
3 Pillars of Universal Design
 
Performance comparision 1307.4129
Performance comparision 1307.4129Performance comparision 1307.4129
Performance comparision 1307.4129
 
POWER INTERACTIVO DE MATEMATICA
POWER INTERACTIVO DE MATEMATICAPOWER INTERACTIVO DE MATEMATICA
POWER INTERACTIVO DE MATEMATICA
 
Cs757 ns2-tutorial-exercise
Cs757 ns2-tutorial-exerciseCs757 ns2-tutorial-exercise
Cs757 ns2-tutorial-exercise
 
Cygwin ug-net
Cygwin ug-netCygwin ug-net
Cygwin ug-net
 

Último

CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
giselly40
 

Último (20)

The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Evaluating the top large language models.pdf
Evaluating the top large language models.pdfEvaluating the top large language models.pdf
Evaluating the top large language models.pdf
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 

Origamist's ruby