SlideShare ist ein Scribd-Unternehmen logo
1 von 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 :)

Weitere ähnliche Inhalte

Was ist angesagt?

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
 

Was ist angesagt? (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
 

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

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
 

Ähnlich wie あたかも自然言語を書くようにコーディングしてみる (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
 

Kürzlich hochgeladen

GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
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 Scriptwesley chun
 
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
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
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...Drew Madelung
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
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.pdfEnterprise Knowledge
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsRoshan Dwivedi
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
[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
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 

Kürzlich hochgeladen (20)

GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
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
 
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
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
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...
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
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
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
[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
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 

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

  • 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...) • • •

Hinweis der Redaktion

  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