SlideShare uma empresa 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?

Mais conteúdo relacionado

Destaque

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 linuxPratik Joshi
 
3 Pillars of Universal Design
3 Pillars of Universal Design3 Pillars of Universal Design
3 Pillars of Universal Designcentralmath
 
Performance comparision 1307.4129
Performance comparision 1307.4129Performance comparision 1307.4129
Performance comparision 1307.4129Pratik Joshi
 
POWER INTERACTIVO DE MATEMATICA
POWER INTERACTIVO DE MATEMATICAPOWER INTERACTIVO DE MATEMATICA
POWER INTERACTIVO DE MATEMATICAmarita1277
 
Cs757 ns2-tutorial-exercise
Cs757 ns2-tutorial-exerciseCs757 ns2-tutorial-exercise
Cs757 ns2-tutorial-exercisePratik Joshi
 

Destaque (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

Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostZilliz
 
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
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024The Digital Insurer
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfRankYa
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
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
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 

Último (20)

Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
 
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
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdf
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
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
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 

Origamist's ruby