SlideShare ist ein Scribd-Unternehmen logo
1 von 26
programming
    basics
    basics

Ladislav Martincik
Content
   - Simple question
   - Complexity OF MODELING
     reality (Not-reality)
   - OOP
   - Coupling (Connascence)
   - big applouse ;)

ALL the time discussion please!
Why oop?
class Component
  attr_accessor :name, :price

  def initialize name, price
    @name = name
    @price = price
  end

  def to_s
    "#{name}: $#{price}"
  end
end
What is better?
def pay(from, to, amount, rounding = 0.5)
  ....
end


def pay(transaction)
  ....
end
Holy OOP

   Keep “large”* software projects
   manageable by human
   programmers.




* what is LARGE?
Real Programming

   HUMAN to HUMAN **

   Complexity our brain can
   handle 4/+-2



** This is one of the reasons why we have high-level
programming languages and not assembler.
REal OOP
Modeling based on Real world experience and
Mathematics

- Modularization- Abstraction -- Understandability
- Encapsulation -- Information Hiding-
Composability -- Structured Design- Hierarchy-
Continuity
Modularization




 Decompose problem into smaller subproblems
 that can be solved separately.
Modularization
 class Component
   include PrintableComponent
   attr_reader :name, :price
   ...
 end

 module PrintableComponent
   def to_s
     "#{name}: $#{price}"
   end
 end
Abstraction --
Understandability



 Terminology of the problem domain is reflected
 in the software solution. Individual modules are
 understandable by human readers.
Abstraction --
Understandability
 set :environment, :development
 set :user, :deploy

 desc "Deploy to production"
 task :deploy do
   scp :local, "deploy@#{server}/#{root_dir}"
 end
Composability --
Structured Design



 Interfaces allow to freely combine modules to
 produce new systems.
Composability --
Structured Design
  gem "bundler"

  plugins

  module Namespace
    module Namespace2
      class X; end
      class Y < X; end
    end
  end
Hierarchy

 class Component
   attr_reader :sub_components
 end

 class Car < Component
   def initialize(color, type)
     @sub_components << Wheel.new('left top')
     @sub_components << Door.new('left driver')
   end
 end
Continuity




 Changes and maintenance in
 only a few modules does not affect
 the architecture.
Continuity
 DRY - Do not repeat yourself
 Coupling - ConNascence
ConNascence

Two software components are connascent if a
change in one would require the other to be
modified in order to maintain the overall
correctness of the system. Connascence is a
way to characterize and reason about certain
types of complexity in software systems.
ConNascence
Strength - The stronger the form of connascence, the more difficult,
and costly, it is to change the elements in the relationship.
Name < Type < Meaning < Position < ...
Degree - The acceptability of connascence is related to the degree
of its occurrence.def fun1(x1, x2) < def fun1(x1, x2, x3, x4, ...)
Locality - Stronger forms of connascence are acceptable if the
elements involved are closely related.
 - Stronger forms of connascence are acceptable if the elements
involved are closely related.
 - Stronger forms of connascence are acceptable if the elements
involved are closely related.
 - Stronger forms of connascence are acceptable if the elements
involved are closely related.
 - Stronger forms of connascence are acceptable if the elements
involved are closely related.
C of Name
 def pay(from, to, amount, correction)
   transaction do
     from.move(to, amount, correction)
   end
 end
C of TYPE
    def pay(transaction)
      if transaction.kind_of? Array

                                      DUCK TYPING
        transaction.each do |t|
          t.run
        end
      else
        transaction.run               def pay(transaction)
      end                               if transaction.respond_to :each
    end                                   transaction.each do |t|
                                             t.run
                                          end
                                        else
                                          transaction.run
                                        end
def pay(transaction)                  end
  Array(transaction).each do |x|
    x.run
  end
end
C of MEANING
class Role
  def can_access_admin?(role_id = 0)
    if role_id == 1     # Admin
      true
    elsif role_id == 2 # Ambassador
      true
    else
      false
    end                         class Role
  end                             ADMIN = 1; AMBASSADOR = 2
end                               def can_access_admin?(role_id = 0)
                                    if role_id == ADMIN
                                      true
                                    elsif role_id == AMBASSADOR
                                      true
                                    else
                                      false
                                    end
                                  end
                                end
C of Position
def pay(from, to, amount, correction)
  ....
end

def pay(options = {})
  ....
end



                        def pay(from, to, options = {})
                          ...
                        end
C of Algorithm
 class User
   def self.encrypt_password
     Digest::SHA1.hexdigest(password)
   end
 end

 class User
   attr_writer :encryption

   def initialize
     encryption = Digest::SHA1.hexdigest
   end

   def self.encrypt_password
     encryption.call password
   end
 end
Conclusion


  Name < Type < Meaning < Position < ALGORITHM
   Name < Type < Meaning < Position < ALGORITHM
Thank you


 Questions? Opinions?

 ladislav.martincik@gmail.com
 martincik.com
            martincik.com
OOP - NEXT time
- Single responsibility principle
- Open/closed principle
- Liskov substitution principle
- Interface segregation principle
- Dependency inversion principle

Weitere ähnliche Inhalte

Was ist angesagt?

C C++ tutorial for beginners- tibacademy.in
C C++ tutorial for beginners- tibacademy.inC C++ tutorial for beginners- tibacademy.in
C C++ tutorial for beginners- tibacademy.inTIB Academy
 
Concept of scoping in programming languages
Concept of scoping in programming languagesConcept of scoping in programming languages
Concept of scoping in programming languagesMd. Jafar Sadik
 
Powerpoint presentation final requirement in fnd prg
Powerpoint presentation final requirement in fnd prgPowerpoint presentation final requirement in fnd prg
Powerpoint presentation final requirement in fnd prgalyssa-castro2326
 
Swift Programming
Swift ProgrammingSwift Programming
Swift ProgrammingCodemotion
 
The Swift Programming Language - Xcode6 for iOS App Development - AgileInfowa...
The Swift Programming Language - Xcode6 for iOS App Development - AgileInfowa...The Swift Programming Language - Xcode6 for iOS App Development - AgileInfowa...
The Swift Programming Language - Xcode6 for iOS App Development - AgileInfowa...Mark Simon
 
Final requirement in programming niperos
Final requirement in programming   niperosFinal requirement in programming   niperos
Final requirement in programming niperosmarkings17
 
Final requirement in programming vinson
Final requirement in programming  vinsonFinal requirement in programming  vinson
Final requirement in programming vinsonmonstergeorge
 
Final project powerpoint template (fndprg) (1)
Final project powerpoint template (fndprg) (1)Final project powerpoint template (fndprg) (1)
Final project powerpoint template (fndprg) (1)heoff
 
Kuliah komputer pemrograman
Kuliah  komputer pemrogramanKuliah  komputer pemrograman
Kuliah komputer pemrogramanhardryu
 
Intorudction into VBScript
Intorudction into VBScriptIntorudction into VBScript
Intorudction into VBScriptVitaliy Ganzha
 
Flow of control by deepak lakhlan
Flow of control by deepak lakhlanFlow of control by deepak lakhlan
Flow of control by deepak lakhlanDeepak Lakhlan
 
Conditional statement c++
Conditional statement c++Conditional statement c++
Conditional statement c++amber chaudary
 

Was ist angesagt? (19)

C C++ tutorial for beginners- tibacademy.in
C C++ tutorial for beginners- tibacademy.inC C++ tutorial for beginners- tibacademy.in
C C++ tutorial for beginners- tibacademy.in
 
Concept of scoping in programming languages
Concept of scoping in programming languagesConcept of scoping in programming languages
Concept of scoping in programming languages
 
Powerpoint presentation final requirement in fnd prg
Powerpoint presentation final requirement in fnd prgPowerpoint presentation final requirement in fnd prg
Powerpoint presentation final requirement in fnd prg
 
Flow of Control
Flow of ControlFlow of Control
Flow of Control
 
Swift Programming
Swift ProgrammingSwift Programming
Swift Programming
 
VB Script
VB ScriptVB Script
VB Script
 
The Swift Programming Language - Xcode6 for iOS App Development - AgileInfowa...
The Swift Programming Language - Xcode6 for iOS App Development - AgileInfowa...The Swift Programming Language - Xcode6 for iOS App Development - AgileInfowa...
The Swift Programming Language - Xcode6 for iOS App Development - AgileInfowa...
 
Final requirement in programming niperos
Final requirement in programming   niperosFinal requirement in programming   niperos
Final requirement in programming niperos
 
Monad Fact #6
Monad Fact #6Monad Fact #6
Monad Fact #6
 
Final requirement in programming vinson
Final requirement in programming  vinsonFinal requirement in programming  vinson
Final requirement in programming vinson
 
Vb script
Vb scriptVb script
Vb script
 
Final project powerpoint template (fndprg) (1)
Final project powerpoint template (fndprg) (1)Final project powerpoint template (fndprg) (1)
Final project powerpoint template (fndprg) (1)
 
C++ STATEMENTS
C++ STATEMENTS C++ STATEMENTS
C++ STATEMENTS
 
Vb script tutorial
Vb script tutorialVb script tutorial
Vb script tutorial
 
Kuliah komputer pemrograman
Kuliah  komputer pemrogramanKuliah  komputer pemrograman
Kuliah komputer pemrograman
 
C++ Chapter II
C++ Chapter IIC++ Chapter II
C++ Chapter II
 
Intorudction into VBScript
Intorudction into VBScriptIntorudction into VBScript
Intorudction into VBScript
 
Flow of control by deepak lakhlan
Flow of control by deepak lakhlanFlow of control by deepak lakhlan
Flow of control by deepak lakhlan
 
Conditional statement c++
Conditional statement c++Conditional statement c++
Conditional statement c++
 

Andere mochten auch

Andere mochten auch (11)

Object Oriented Programming Basics
Object Oriented Programming BasicsObject Oriented Programming Basics
Object Oriented Programming Basics
 
Programming Basics
Programming BasicsProgramming Basics
Programming Basics
 
Super team
Super teamSuper team
Super team
 
Programming SOLID
Programming SOLIDProgramming SOLID
Programming SOLID
 
People Pattern Power
People Pattern PowerPeople Pattern Power
People Pattern Power
 
Efektivní učení
Efektivní učeníEfektivní učení
Efektivní učení
 
Super kariera
Super karieraSuper kariera
Super kariera
 
SOLID Principles of Refactoring Presentation - Inland Empire User Group
SOLID Principles of Refactoring Presentation - Inland Empire User GroupSOLID Principles of Refactoring Presentation - Inland Empire User Group
SOLID Principles of Refactoring Presentation - Inland Empire User Group
 
The Basics of programming
The Basics of programmingThe Basics of programming
The Basics of programming
 
C programming basics
C  programming basicsC  programming basics
C programming basics
 
Creating HTML Pages
Creating HTML PagesCreating HTML Pages
Creating HTML Pages
 

Ähnlich wie Programming basics and object-oriented principles

name name2 n
name name2 nname name2 n
name name2 ncallroom
 
name name2 n2
name name2 n2name name2 n2
name name2 n2callroom
 
name name2 n
name name2 nname name2 n
name name2 ncallroom
 
name name2 n
name name2 nname name2 n
name name2 ncallroom
 
name name2 n2.ppt
name name2 n2.pptname name2 n2.ppt
name name2 n2.pptcallroom
 
Ruby for Perl Programmers
Ruby for Perl ProgrammersRuby for Perl Programmers
Ruby for Perl Programmersamiable_indian
 
Advanced Internationalization with Rails
Advanced Internationalization with RailsAdvanced Internationalization with Rails
Advanced Internationalization with RailsClinton Dreisbach
 
Pydiomatic
PydiomaticPydiomatic
Pydiomaticrik0
 
Recursion vs. Iteration: Code Efficiency & Structure
Recursion vs. Iteration: Code Efficiency & StructureRecursion vs. Iteration: Code Efficiency & Structure
Recursion vs. Iteration: Code Efficiency & Structurecogaxor346
 
Functional Objects in Ruby: new horizons – Valentine Ostakh
Functional Objects in Ruby: new horizons  – Valentine OstakhFunctional Objects in Ruby: new horizons  – Valentine Ostakh
Functional Objects in Ruby: new horizons – Valentine OstakhRuby Meditation
 

Ähnlich wie Programming basics and object-oriented principles (20)

The Joy Of Ruby
The Joy Of RubyThe Joy Of Ruby
The Joy Of Ruby
 
ppt7
ppt7ppt7
ppt7
 
ppt2
ppt2ppt2
ppt2
 
name name2 n
name name2 nname name2 n
name name2 n
 
name name2 n2
name name2 n2name name2 n2
name name2 n2
 
test ppt
test ppttest ppt
test ppt
 
name name2 n
name name2 nname name2 n
name name2 n
 
ppt21
ppt21ppt21
ppt21
 
name name2 n
name name2 nname name2 n
name name2 n
 
ppt17
ppt17ppt17
ppt17
 
ppt30
ppt30ppt30
ppt30
 
name name2 n2.ppt
name name2 n2.pptname name2 n2.ppt
name name2 n2.ppt
 
ppt18
ppt18ppt18
ppt18
 
Ruby for Perl Programmers
Ruby for Perl ProgrammersRuby for Perl Programmers
Ruby for Perl Programmers
 
ppt9
ppt9ppt9
ppt9
 
Advanced Internationalization with Rails
Advanced Internationalization with RailsAdvanced Internationalization with Rails
Advanced Internationalization with Rails
 
Pydiomatic
PydiomaticPydiomatic
Pydiomatic
 
Python idiomatico
Python idiomaticoPython idiomatico
Python idiomatico
 
Recursion vs. Iteration: Code Efficiency & Structure
Recursion vs. Iteration: Code Efficiency & StructureRecursion vs. Iteration: Code Efficiency & Structure
Recursion vs. Iteration: Code Efficiency & Structure
 
Functional Objects in Ruby: new horizons – Valentine Ostakh
Functional Objects in Ruby: new horizons  – Valentine OstakhFunctional Objects in Ruby: new horizons  – Valentine Ostakh
Functional Objects in Ruby: new horizons – Valentine Ostakh
 

Kürzlich hochgeladen

#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxOnBoard
 
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
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
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
 
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your Budget
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your BudgetHyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your Budget
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your BudgetEnjoy Anytime
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAndikSusilo4
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphNeo4j
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
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
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
 
Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraDeakin University
 

Kürzlich hochgeladen (20)

#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptx
 
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
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
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 ...
 
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your Budget
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your BudgetHyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your Budget
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your Budget
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & Application
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food Manufacturing
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
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
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
 
Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning era
 

Programming basics and object-oriented principles

  • 1. programming basics basics Ladislav Martincik
  • 2. Content - Simple question - Complexity OF MODELING reality (Not-reality) - OOP - Coupling (Connascence) - big applouse ;) ALL the time discussion please!
  • 3. Why oop? class Component attr_accessor :name, :price def initialize name, price @name = name @price = price end def to_s "#{name}: $#{price}" end end
  • 4. What is better? def pay(from, to, amount, rounding = 0.5) .... end def pay(transaction) .... end
  • 5. Holy OOP Keep “large”* software projects manageable by human programmers. * what is LARGE?
  • 6. Real Programming HUMAN to HUMAN ** Complexity our brain can handle 4/+-2 ** This is one of the reasons why we have high-level programming languages and not assembler.
  • 7. REal OOP Modeling based on Real world experience and Mathematics - Modularization- Abstraction -- Understandability - Encapsulation -- Information Hiding- Composability -- Structured Design- Hierarchy- Continuity
  • 8. Modularization Decompose problem into smaller subproblems that can be solved separately.
  • 9. Modularization class Component include PrintableComponent attr_reader :name, :price ... end module PrintableComponent def to_s "#{name}: $#{price}" end end
  • 10. Abstraction -- Understandability Terminology of the problem domain is reflected in the software solution. Individual modules are understandable by human readers.
  • 11. Abstraction -- Understandability set :environment, :development set :user, :deploy desc "Deploy to production" task :deploy do scp :local, "deploy@#{server}/#{root_dir}" end
  • 12. Composability -- Structured Design Interfaces allow to freely combine modules to produce new systems.
  • 13. Composability -- Structured Design gem "bundler" plugins module Namespace module Namespace2 class X; end class Y < X; end end end
  • 14. Hierarchy class Component attr_reader :sub_components end class Car < Component def initialize(color, type) @sub_components << Wheel.new('left top') @sub_components << Door.new('left driver') end end
  • 15. Continuity Changes and maintenance in only a few modules does not affect the architecture.
  • 16. Continuity DRY - Do not repeat yourself Coupling - ConNascence
  • 17. ConNascence Two software components are connascent if a change in one would require the other to be modified in order to maintain the overall correctness of the system. Connascence is a way to characterize and reason about certain types of complexity in software systems.
  • 18. ConNascence Strength - The stronger the form of connascence, the more difficult, and costly, it is to change the elements in the relationship. Name < Type < Meaning < Position < ... Degree - The acceptability of connascence is related to the degree of its occurrence.def fun1(x1, x2) < def fun1(x1, x2, x3, x4, ...) Locality - Stronger forms of connascence are acceptable if the elements involved are closely related. - Stronger forms of connascence are acceptable if the elements involved are closely related. - Stronger forms of connascence are acceptable if the elements involved are closely related. - Stronger forms of connascence are acceptable if the elements involved are closely related. - Stronger forms of connascence are acceptable if the elements involved are closely related.
  • 19. C of Name def pay(from, to, amount, correction) transaction do from.move(to, amount, correction) end end
  • 20. C of TYPE def pay(transaction) if transaction.kind_of? Array DUCK TYPING transaction.each do |t| t.run end else transaction.run def pay(transaction) end if transaction.respond_to :each end transaction.each do |t| t.run end else transaction.run end def pay(transaction) end Array(transaction).each do |x| x.run end end
  • 21. C of MEANING class Role def can_access_admin?(role_id = 0) if role_id == 1 # Admin true elsif role_id == 2 # Ambassador true else false end class Role end ADMIN = 1; AMBASSADOR = 2 end def can_access_admin?(role_id = 0) if role_id == ADMIN true elsif role_id == AMBASSADOR true else false end end end
  • 22. C of Position def pay(from, to, amount, correction) .... end def pay(options = {}) .... end def pay(from, to, options = {}) ... end
  • 23. C of Algorithm class User def self.encrypt_password Digest::SHA1.hexdigest(password) end end class User attr_writer :encryption def initialize encryption = Digest::SHA1.hexdigest end def self.encrypt_password encryption.call password end end
  • 24. Conclusion Name < Type < Meaning < Position < ALGORITHM Name < Type < Meaning < Position < ALGORITHM
  • 25. Thank you Questions? Opinions? ladislav.martincik@gmail.com martincik.com martincik.com
  • 26. OOP - NEXT time - Single responsibility principle - Open/closed principle - Liskov substitution principle - Interface segregation principle - Dependency inversion principle