SlideShare a Scribd company logo
1 of 36
Programming Production Code
 as if writing Natural Language




      Kazuya NUMATA
         @kaznum
Self-introduction
                        (Kazuya NUMATA)
  •
  •                          �


  •
  •
  •
      ���������������


  •
My favorite


•
    •
    •
Agile
Communication with team members
     including stakeholder
                &
        Iterative Testing
Behavior Driven Development
             BDD
Tools
to make BDD effective
•   RSpec (Ruby)

•   NSpec (.NET)

•   CppSpec (C++)

•   JBehave (Java)

•   instinct (Java)

•   PHPSpec (PHP)

•   and more....
Question
Question




   Have you ever experienced *Spec?


*Spec                                 ?
RSpec example:



describe "A new chess board" do

   before(:each) do
     @board = Chess::Board.new
   end

   it "should have 32 pieces" do
     @board.should have(32).pieces
   end

end
                               D. Chelimsky. The RSpec Book
                          Section 13.7 Generated Descriptions
RSpec example:



describe "A new chess board" do

   before(:each) do
     @board = Chess::Board.new
   end

   it "should have 32 pieces" do
     @board.should have(32).pieces
   end

end
                               D. Chelimsky. The RSpec Book
                          Section 13.7 Generated Descriptions
RSpec example:



$ rspec -fd board_spec.rb

(Output is...)

A new chess board
  should have 32 pieces

                       D. Chelimsky. The RSpec Book
                  Section 13.7 Generated Descriptions
It is just Natural Language!
�
The reality is that it’s hard for the Japanese.
Cucumber

(              )
Cucumber Example:


         :

         :


         "           "    "                 "
         "       "   "        Cucumber"
         "       "
             "           Cucumber"

                                                                   ( ∀ )o   sasata299's blog
                                     http://blog.livedoor.jp/sasata299/archives/51278697.html
/Spec




Before
 BDD


After    Spec    Spec
BDD
Before
 BDD


After
BDD
?
Uncle Bob

   Complex fulcrumPoint = Complex.FromRealNumber(23.0);

is generally better than

   Complex fulcrumPoint = new Complex(23.0);

Consider enforcing their use by making the corresponding constructors private.



                           (   )
by Masayoshi Son
Person
         name
                        true
                false
Ruby Example:   name   1

ex1


class Person
  attr_accessor :name
  def initialize(name = nil)
    @name = name
  end
end

shimada = Person.new(“Shimada”)
if shimada.name.split(//)[0] == “S”
  puts “Match”
end
Ruby Example: name   1

ex2


class Person
  attr_accessor :name
  def initialize(name = nil)
    @name = name
  end

  def has_a_name_that_begins_with?(expected)
    @name.split(//)[0] == expected
  end
end

shimada = Person.new(“Shimada”)
if shimada.has_a_name_that_begins_with?(“S”)
  puts “Match”
end
Ruby Example: name    1

ex3

class Person
  attr_accessor :name
  def initialize(name = nil)
    @name = name
  end

  def has_a_name_that_begins_with?(expected)
    @name.split(//)[0] == expected
  end

  def method_missing(m, *args, &block)
    if m.to_s =~ /has_(a|the)_name_(that|which)_begins_with?/
      has_a_name_that_begins_with?(args)
    else
      super
    end
  end
end

shimada = Person.new(“Shimada”)
puts “Match” if shimada.has_a_name_that_begins_with?(“S”)
puts “Match” if shimada.has_the_name_that_begins_with?(“S”)
puts “Match” if shimada.has_a_name_which_begins_with?(“S”)
puts “Match” if shimada.has_the_name_which_begins_with?(“S”)
Ruby Example: name                           1
ex4      name                                                                                     String
                                                                   has_(a|the)_(.+)_(which|that)_begins_with?
Dynamic                    setter
             undef                         Singleton Method
class Person
  def initialize(args)
    args.each do |key, value|
      self.class.send(:attr_accessor, :"#{key}") unless instance_variables.include?(:"@#{key}")
      instance_variable_set(:"@#{key}", value)
    end
  end

  def self.undef_has_a_var_which_begins_with(var)
    method_name = "has_a_#{var}_which_begins_with?"
    send("undef_method", method_name) if method_defined? method_name
  end

  def self.define_has_a_var_which_begins_with(var)
    method_name = "has_a_#{var}_which_begins_with?"
    define_method(method_name) do |expectation|
      value = instance_variable_get(:"@#{var}")
      if value.is_a?(String)
        value.split(//)[0].downcase == expectation.downcase
      else
        self.class.undef_has_a_var_which_begins_with(var)
        method_missing(method_name.to_sym)
      end
    end
  end

  def method_missing(m, *args, &block)
    if m.to_s =~ /has_(a|the)_(.+)_(which|that)_begins_with?/ &&
         instance_variables.include?(:"@#{Regexp.last_match[2]}") &&
         instance_variable_get(:"@#{Regexp.last_match[2]}").is_a?(String)
      var_name = Regexp.last_match[2]
      self.class.define_has_a_var_which_begins_with(var_name)
      send("has_a_#{var_name}_which_begins_with?".to_sym, *args, &block)
    else
      super(m, *args, &block)
    end
  end
end

#### sample #####
shimada = Person.new(:name => "Shimada", :age => 18, :sex => :half, :fuga => "bababa")
p shimada.has_a_name_which_begins_with?("S") ? "Good" : "Suck"
p shimada.has_the_name_which_begins_with?("S") ? "Good" : "Suck"
shimada.name = 5
p shimada.has_the_name_which_begins_with?("5") ? "Good" : "Suck" #=> undefined method
if air_plane.is_created_by? :bowing
    if he.is_eligible_to_get? reward
    if selected_value.is_valid?


→
    can_..., is_,
is does was did
module Kernel
  def is(expected)
    expected
  end

 alias_method :does, :is
 alias_method :was, :is
 alias_method :were, :is
 alias_method :did, :is
 # alias_method :do, :is       × do
end

is air_plane.created_by?(bowing)
does [1,2,3].include?
is he.eligible_to_get?(bonus)
does [1,2,3].include?
is "h".included_in?("hello")
is she, nancy   # ?
Conclusion & Impression

•   Spec



•

•
      •                                                                          Receiver
                                                                            Array#sort


      •            Ruby Standard Library         if obj.instance_of?(exp)   be
                                           (Is                  Object#is   Is#method_missing
           self   return...)


      •
      •
      •
thank you :)

More Related Content

What's hot

Ruby - Uma Introdução
Ruby - Uma IntroduçãoRuby - Uma Introdução
Ruby - Uma IntroduçãoÍgor Bonadio
 
CodeFest 2010. Иноземцев И. — Fantom. Cross-VM Language
CodeFest 2010. Иноземцев И. — Fantom. Cross-VM LanguageCodeFest 2010. Иноземцев И. — Fantom. Cross-VM Language
CodeFest 2010. Иноземцев И. — Fantom. Cross-VM LanguageCodeFest
 
Exhibition of Atrocity
Exhibition of AtrocityExhibition of Atrocity
Exhibition of AtrocityMichael Pirnat
 
Exploring Ceylon with Gavin King - JUG BB Talk - Belrin 2014
Exploring Ceylon with Gavin King - JUG BB Talk - Belrin 2014Exploring Ceylon with Gavin King - JUG BB Talk - Belrin 2014
Exploring Ceylon with Gavin King - JUG BB Talk - Belrin 2014hwilming
 
Rapid Development with Ruby/JRuby and Rails
Rapid Development with Ruby/JRuby and RailsRapid Development with Ruby/JRuby and Rails
Rapid Development with Ruby/JRuby and Railselliando dias
 
Slides chapter3part1 ruby-forjavaprogrammers
Slides chapter3part1 ruby-forjavaprogrammersSlides chapter3part1 ruby-forjavaprogrammers
Slides chapter3part1 ruby-forjavaprogrammersGiovanni924
 
Ruby 入門 第一次就上手
Ruby 入門 第一次就上手Ruby 入門 第一次就上手
Ruby 入門 第一次就上手Wen-Tien Chang
 
Real world gobbledygook
Real world gobbledygookReal world gobbledygook
Real world gobbledygookPawel Szulc
 
Coffeescript: No really, it's just Javascript
Coffeescript: No really, it's just JavascriptCoffeescript: No really, it's just Javascript
Coffeescript: No really, it's just JavascriptBrian Mann
 
Ruby from zero to hero
Ruby from zero to heroRuby from zero to hero
Ruby from zero to heroDiego Lemos
 
Object Oriented JavaScript
Object Oriented JavaScriptObject Oriented JavaScript
Object Oriented JavaScriptDonald Sipe
 
Descobrindo a linguagem Perl
Descobrindo a linguagem PerlDescobrindo a linguagem Perl
Descobrindo a linguagem Perlgarux
 
Everything is Permitted: Extending Built-ins
Everything is Permitted: Extending Built-insEverything is Permitted: Extending Built-ins
Everything is Permitted: Extending Built-insAndrew Dupont
 
Introduction to Ruby Programming Language
Introduction to Ruby Programming LanguageIntroduction to Ruby Programming Language
Introduction to Ruby Programming LanguageNicolò Calcavecchia
 
Hacker 101/102 - Introduction to Programming w/Processing
Hacker 101/102 - Introduction to Programming w/ProcessingHacker 101/102 - Introduction to Programming w/Processing
Hacker 101/102 - Introduction to Programming w/ProcessingDan Chudnov
 
Beginning Object-Oriented JavaScript
Beginning Object-Oriented JavaScriptBeginning Object-Oriented JavaScript
Beginning Object-Oriented JavaScriptStoyan Stefanov
 
purely_functional_play_framework_application
purely_functional_play_framework_applicationpurely_functional_play_framework_application
purely_functional_play_framework_applicationNaoki Aoyama
 
Perl.Hacks.On.Vim
Perl.Hacks.On.VimPerl.Hacks.On.Vim
Perl.Hacks.On.VimLin Yo-An
 

What's hot (20)

Ruby - Uma Introdução
Ruby - Uma IntroduçãoRuby - Uma Introdução
Ruby - Uma Introdução
 
CodeFest 2010. Иноземцев И. — Fantom. Cross-VM Language
CodeFest 2010. Иноземцев И. — Fantom. Cross-VM LanguageCodeFest 2010. Иноземцев И. — Fantom. Cross-VM Language
CodeFest 2010. Иноземцев И. — Fantom. Cross-VM Language
 
Coffee Script
Coffee ScriptCoffee Script
Coffee Script
 
Exhibition of Atrocity
Exhibition of AtrocityExhibition of Atrocity
Exhibition of Atrocity
 
Exploring Ceylon with Gavin King - JUG BB Talk - Belrin 2014
Exploring Ceylon with Gavin King - JUG BB Talk - Belrin 2014Exploring Ceylon with Gavin King - JUG BB Talk - Belrin 2014
Exploring Ceylon with Gavin King - JUG BB Talk - Belrin 2014
 
Rapid Development with Ruby/JRuby and Rails
Rapid Development with Ruby/JRuby and RailsRapid Development with Ruby/JRuby and Rails
Rapid Development with Ruby/JRuby and Rails
 
Slides chapter3part1 ruby-forjavaprogrammers
Slides chapter3part1 ruby-forjavaprogrammersSlides chapter3part1 ruby-forjavaprogrammers
Slides chapter3part1 ruby-forjavaprogrammers
 
Ruby 入門 第一次就上手
Ruby 入門 第一次就上手Ruby 入門 第一次就上手
Ruby 入門 第一次就上手
 
Real world gobbledygook
Real world gobbledygookReal world gobbledygook
Real world gobbledygook
 
Coffeescript: No really, it's just Javascript
Coffeescript: No really, it's just JavascriptCoffeescript: No really, it's just Javascript
Coffeescript: No really, it's just Javascript
 
Ruby from zero to hero
Ruby from zero to heroRuby from zero to hero
Ruby from zero to hero
 
Object Oriented JavaScript
Object Oriented JavaScriptObject Oriented JavaScript
Object Oriented JavaScript
 
1 the ruby way
1   the ruby way1   the ruby way
1 the ruby way
 
Descobrindo a linguagem Perl
Descobrindo a linguagem PerlDescobrindo a linguagem Perl
Descobrindo a linguagem Perl
 
Everything is Permitted: Extending Built-ins
Everything is Permitted: Extending Built-insEverything is Permitted: Extending Built-ins
Everything is Permitted: Extending Built-ins
 
Introduction to Ruby Programming Language
Introduction to Ruby Programming LanguageIntroduction to Ruby Programming Language
Introduction to Ruby Programming Language
 
Hacker 101/102 - Introduction to Programming w/Processing
Hacker 101/102 - Introduction to Programming w/ProcessingHacker 101/102 - Introduction to Programming w/Processing
Hacker 101/102 - Introduction to Programming w/Processing
 
Beginning Object-Oriented JavaScript
Beginning Object-Oriented JavaScriptBeginning Object-Oriented JavaScript
Beginning Object-Oriented JavaScript
 
purely_functional_play_framework_application
purely_functional_play_framework_applicationpurely_functional_play_framework_application
purely_functional_play_framework_application
 
Perl.Hacks.On.Vim
Perl.Hacks.On.VimPerl.Hacks.On.Vim
Perl.Hacks.On.Vim
 

Similar to あたかも自然言語を書くようにコーディングしてみる

Petitparser at the Deep into Smalltalk School 2011
Petitparser at the Deep into Smalltalk School 2011Petitparser at the Deep into Smalltalk School 2011
Petitparser at the Deep into Smalltalk School 2011Tudor Girba
 
Threequals - Case Equality in Ruby
Threequals - Case Equality in RubyThreequals - Case Equality in Ruby
Threequals - Case Equality in RubyLouis Scoras
 
Why Java Sucks and C# Rocks (Final)
Why Java Sucks and C# Rocks (Final)Why Java Sucks and C# Rocks (Final)
Why Java Sucks and C# Rocks (Final)jeffz
 
Crystal presentation in NY
Crystal presentation in NYCrystal presentation in NY
Crystal presentation in NYCrystal Language
 
Hacking with ruby2ruby
Hacking with ruby2rubyHacking with ruby2ruby
Hacking with ruby2rubyMarc Chung
 
A limited guide to intermediate and advanced Ruby
A limited guide to intermediate and advanced RubyA limited guide to intermediate and advanced Ruby
A limited guide to intermediate and advanced RubyVysakh Sreenivasan
 
Ruby presentasjon på NTNU 22 april 2009
Ruby presentasjon på NTNU 22 april 2009Ruby presentasjon på NTNU 22 april 2009
Ruby presentasjon på NTNU 22 april 2009Aslak Hellesøy
 
Ruby presentasjon på NTNU 22 april 2009
Ruby presentasjon på NTNU 22 april 2009Ruby presentasjon på NTNU 22 april 2009
Ruby presentasjon på NTNU 22 april 2009Aslak Hellesøy
 
Ruby presentasjon på NTNU 22 april 2009
Ruby presentasjon på NTNU 22 april 2009Ruby presentasjon på NTNU 22 april 2009
Ruby presentasjon på NTNU 22 april 2009Aslak Hellesøy
 
Making JavaScript Libraries More Approachable
Making JavaScript Libraries More ApproachableMaking JavaScript Libraries More Approachable
Making JavaScript Libraries More ApproachablePamela Fox
 
jRuby: The best of both worlds
jRuby: The best of both worldsjRuby: The best of both worlds
jRuby: The best of both worldsChristopher Spring
 
Uses & Abuses of Mocks & Stubs
Uses & Abuses of Mocks & StubsUses & Abuses of Mocks & Stubs
Uses & Abuses of Mocks & StubsPatchSpace Ltd
 
Postobjektové programovanie v Ruby
Postobjektové programovanie v RubyPostobjektové programovanie v Ruby
Postobjektové programovanie v RubyJano Suchal
 
Playfulness at Work
Playfulness at WorkPlayfulness at Work
Playfulness at WorkErin Dees
 
RSpec 3.0: Under the Covers
RSpec 3.0: Under the CoversRSpec 3.0: Under the Covers
RSpec 3.0: Under the CoversBrian Gesiak
 
Write Your Own JVM Compiler
Write Your Own JVM CompilerWrite Your Own JVM Compiler
Write Your Own JVM CompilerErin Dees
 
Attributes Unwrapped: Lessons under the surface of active record
Attributes Unwrapped: Lessons under the surface of active recordAttributes Unwrapped: Lessons under the surface of active record
Attributes Unwrapped: Lessons under the surface of active record.toster
 
AST - the only true tool for building JavaScript
AST - the only true tool for building JavaScriptAST - the only true tool for building JavaScript
AST - the only true tool for building JavaScriptIngvar Stepanyan
 

Similar to あたかも自然言語を書くようにコーディングしてみる (20)

Language supports it
Language supports itLanguage supports it
Language supports it
 
Petitparser at the Deep into Smalltalk School 2011
Petitparser at the Deep into Smalltalk School 2011Petitparser at the Deep into Smalltalk School 2011
Petitparser at the Deep into Smalltalk School 2011
 
Threequals - Case Equality in Ruby
Threequals - Case Equality in RubyThreequals - Case Equality in Ruby
Threequals - Case Equality in Ruby
 
Why Java Sucks and C# Rocks (Final)
Why Java Sucks and C# Rocks (Final)Why Java Sucks and C# Rocks (Final)
Why Java Sucks and C# Rocks (Final)
 
Crystal presentation in NY
Crystal presentation in NYCrystal presentation in NY
Crystal presentation in NY
 
Hacking with ruby2ruby
Hacking with ruby2rubyHacking with ruby2ruby
Hacking with ruby2ruby
 
A limited guide to intermediate and advanced Ruby
A limited guide to intermediate and advanced RubyA limited guide to intermediate and advanced Ruby
A limited guide to intermediate and advanced Ruby
 
Ruby presentasjon på NTNU 22 april 2009
Ruby presentasjon på NTNU 22 april 2009Ruby presentasjon på NTNU 22 april 2009
Ruby presentasjon på NTNU 22 april 2009
 
Ruby presentasjon på NTNU 22 april 2009
Ruby presentasjon på NTNU 22 april 2009Ruby presentasjon på NTNU 22 april 2009
Ruby presentasjon på NTNU 22 april 2009
 
Ruby presentasjon på NTNU 22 april 2009
Ruby presentasjon på NTNU 22 april 2009Ruby presentasjon på NTNU 22 april 2009
Ruby presentasjon på NTNU 22 april 2009
 
Tork03 LT
Tork03 LT Tork03 LT
Tork03 LT
 
Making JavaScript Libraries More Approachable
Making JavaScript Libraries More ApproachableMaking JavaScript Libraries More Approachable
Making JavaScript Libraries More Approachable
 
jRuby: The best of both worlds
jRuby: The best of both worldsjRuby: The best of both worlds
jRuby: The best of both worlds
 
Uses & Abuses of Mocks & Stubs
Uses & Abuses of Mocks & StubsUses & Abuses of Mocks & Stubs
Uses & Abuses of Mocks & Stubs
 
Postobjektové programovanie v Ruby
Postobjektové programovanie v RubyPostobjektové programovanie v Ruby
Postobjektové programovanie v Ruby
 
Playfulness at Work
Playfulness at WorkPlayfulness at Work
Playfulness at Work
 
RSpec 3.0: Under the Covers
RSpec 3.0: Under the CoversRSpec 3.0: Under the Covers
RSpec 3.0: Under the Covers
 
Write Your Own JVM Compiler
Write Your Own JVM CompilerWrite Your Own JVM Compiler
Write Your Own JVM Compiler
 
Attributes Unwrapped: Lessons under the surface of active record
Attributes Unwrapped: Lessons under the surface of active recordAttributes Unwrapped: Lessons under the surface of active record
Attributes Unwrapped: Lessons under the surface of active record
 
AST - the only true tool for building JavaScript
AST - the only true tool for building JavaScriptAST - the only true tool for building JavaScript
AST - the only true tool for building JavaScript
 

Recently uploaded

WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
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
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piececharlottematthew16
 
Vector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesVector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesZilliz
 
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
 
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
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clashcharlottematthew16
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 
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
 
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
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 

Recently uploaded (20)

WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
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)
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piece
 
Vector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesVector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector Databases
 
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
 
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
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clash
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 
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
 
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?
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 

あたかも自然言語を書くようにコーディングしてみる

  • 1. Programming Production Code as if writing Natural Language Kazuya NUMATA @kaznum
  • 2. Self-introduction (Kazuya NUMATA) • • � • • • ��������������� •
  • 3. My favorite • • •
  • 5. Communication with team members including stakeholder & Iterative Testing
  • 7. Tools to make BDD effective
  • 8. RSpec (Ruby) • NSpec (.NET) • CppSpec (C++) • JBehave (Java) • instinct (Java) • PHPSpec (PHP) • and more....
  • 10. Question Have you ever experienced *Spec? *Spec ?
  • 11. RSpec example: describe "A new chess board" do before(:each) do @board = Chess::Board.new end it "should have 32 pieces" do @board.should have(32).pieces end end D. Chelimsky. The RSpec Book Section 13.7 Generated Descriptions
  • 12. RSpec example: describe "A new chess board" do before(:each) do @board = Chess::Board.new end it "should have 32 pieces" do @board.should have(32).pieces end end D. Chelimsky. The RSpec Book Section 13.7 Generated Descriptions
  • 13. RSpec example: $ rspec -fd board_spec.rb (Output is...) A new chess board should have 32 pieces D. Chelimsky. The RSpec Book Section 13.7 Generated Descriptions
  • 14. It is just Natural Language!
  • 15.
  • 16. The reality is that it’s hard for the Japanese.
  • 17. Cucumber (
  • 18. Cucumber Example: : : " " " " " " " Cucumber" " " " Cucumber" ( ∀ )o sasata299's blog http://blog.livedoor.jp/sasata299/archives/51278697.html
  • 19.
  • 20. /Spec Before BDD After Spec Spec BDD
  • 22.
  • 23.
  • 24.
  • 25. Uncle Bob Complex fulcrumPoint = Complex.FromRealNumber(23.0); is generally better than Complex fulcrumPoint = new Complex(23.0); Consider enforcing their use by making the corresponding constructors private. ( )
  • 27. Person name true false
  • 28. Ruby Example: name 1 ex1 class Person attr_accessor :name def initialize(name = nil) @name = name end end shimada = Person.new(“Shimada”) if shimada.name.split(//)[0] == “S” puts “Match” end
  • 29. Ruby Example: name 1 ex2 class Person attr_accessor :name def initialize(name = nil) @name = name end def has_a_name_that_begins_with?(expected) @name.split(//)[0] == expected end end shimada = Person.new(“Shimada”) if shimada.has_a_name_that_begins_with?(“S”) puts “Match” end
  • 30. Ruby Example: name 1 ex3 class Person attr_accessor :name def initialize(name = nil) @name = name end def has_a_name_that_begins_with?(expected) @name.split(//)[0] == expected end def method_missing(m, *args, &block) if m.to_s =~ /has_(a|the)_name_(that|which)_begins_with?/ has_a_name_that_begins_with?(args) else super end end end shimada = Person.new(“Shimada”) puts “Match” if shimada.has_a_name_that_begins_with?(“S”) puts “Match” if shimada.has_the_name_that_begins_with?(“S”) puts “Match” if shimada.has_a_name_which_begins_with?(“S”) puts “Match” if shimada.has_the_name_which_begins_with?(“S”)
  • 31. Ruby Example: name 1 ex4 name String has_(a|the)_(.+)_(which|that)_begins_with? Dynamic setter undef Singleton Method class Person def initialize(args) args.each do |key, value| self.class.send(:attr_accessor, :"#{key}") unless instance_variables.include?(:"@#{key}") instance_variable_set(:"@#{key}", value) end end def self.undef_has_a_var_which_begins_with(var) method_name = "has_a_#{var}_which_begins_with?" send("undef_method", method_name) if method_defined? method_name end def self.define_has_a_var_which_begins_with(var) method_name = "has_a_#{var}_which_begins_with?" define_method(method_name) do |expectation| value = instance_variable_get(:"@#{var}") if value.is_a?(String) value.split(//)[0].downcase == expectation.downcase else self.class.undef_has_a_var_which_begins_with(var) method_missing(method_name.to_sym) end end end def method_missing(m, *args, &block) if m.to_s =~ /has_(a|the)_(.+)_(which|that)_begins_with?/ && instance_variables.include?(:"@#{Regexp.last_match[2]}") && instance_variable_get(:"@#{Regexp.last_match[2]}").is_a?(String) var_name = Regexp.last_match[2] self.class.define_has_a_var_which_begins_with(var_name) send("has_a_#{var_name}_which_begins_with?".to_sym, *args, &block) else super(m, *args, &block) end end end #### sample ##### shimada = Person.new(:name => "Shimada", :age => 18, :sex => :half, :fuga => "bababa") p shimada.has_a_name_which_begins_with?("S") ? "Good" : "Suck" p shimada.has_the_name_which_begins_with?("S") ? "Good" : "Suck" shimada.name = 5 p shimada.has_the_name_which_begins_with?("5") ? "Good" : "Suck" #=> undefined method
  • 32.
  • 33. if air_plane.is_created_by? :bowing if he.is_eligible_to_get? reward if selected_value.is_valid? → can_..., is_,
  • 34. is does was did module Kernel def is(expected) expected end alias_method :does, :is alias_method :was, :is alias_method :were, :is alias_method :did, :is # alias_method :do, :is × do end is air_plane.created_by?(bowing) does [1,2,3].include? is he.eligible_to_get?(bonus) does [1,2,3].include? is "h".included_in?("hello") is she, nancy # ?
  • 35. Conclusion & Impression • Spec • • • Receiver Array#sort • Ruby Standard Library if obj.instance_of?(exp) be (Is Object#is Is#method_missing self return...) • • •

Editor's Notes

  1. \n
  2. \n
  3. \n
  4. \n
  5. \n
  6. \n
  7. \n
  8. \n
  9. \n
  10. \n
  11. \n
  12. \n
  13. \n
  14. \n
  15. \n
  16. \n
  17. \n
  18. \n
  19. \n
  20. \n
  21. \n
  22. \n
  23. \n
  24. \n
  25. \n
  26. \n
  27. \n
  28. \n
  29. \n
  30. \n
  31. \n
  32. \n
  33. \n
  34. \n
  35. \n
  36. \n