Stéphane Ducasse 1 Objects to the Roots: Learning from beauty.

Slides:



Advertisements
Similar presentations
The Art of Avoiding Work
Advertisements

3-1 Chapter 3 Flow of Control (part a - branching)
S.Ducasse Stéphane Ducasse 1 Numbers.
Stéphane Ducasse«ChapterNr».1 Abstract Classes Should not be instantiated (abstract in Java) But can defined complete methods Defines a protocol common.
Stéphane Ducasse«ChapterNr».1 Arthur Riel Design Heuristics from Object-Oriented Design Heuristics by Arthur Riel Read the Heuristics… –Find reasons why.
Stéphane Ducasse9.1 Inheritance Semantics and Lookup.
Stéphane Ducasse 1 The Taste of Smalltalk.
Selection Statements choice of one among several blocks of code Java supports 3 kinds of selection statements: if statement – selects one block or leaves.
Dynamic Object-Oriented Programming with Smalltalk 1. Introduction Prof. O. Nierstrasz Summer Semester 2006.
S.Ducasse Stéphane Ducasse 1 A Taste of Smalltalk.
Copyright © 2006 The McGraw-Hill Companies, Inc. Programming Languages 2nd edition Tucker and Noonan Chapter 13 Object-Oriented Programming I am surprised.
Bellevue University CIS 205: Introduction to Programming Using C++ Lecture 7: Methods.
03G-1 Everything is an Object Examining builtin classes All these are classes in Little Smalltalk:  Object  Class  Method  Block  Boolean True False.
Stéphane Ducasse5.1 Smalltalk in a Nutshell OO Model in a Nutshell Syntax in a Nutshell.
VB .NET Programming Fundamentals
Stéphane Ducasse 1 Smalltalk in a Nutshell.
Stéphane Ducasse«ChapterNr».1 Basic Objects, Conditionals and Loops Booleans Basic Loops Overview of the Collection hierarchy— more than 80 classes: (Bag,
S.Ducasse Stéphane Ducasse 1 The Taste of Smalltalk.
Chapter 3 Introduction to Logic © 2008 Pearson Addison-Wesley. All rights reserved.
Assertions Program correctness. Assertions Java statement – enables you to assert an assumption about your program. – An assertion contains a Boolean.
1. We’ve learned that our programs are read by the compiler in order, from top to bottom, just as they are written The order of statement execution is.
S.Ducasse Stéphane Ducasse 1 Design Heuristics.
S.Ducasse Stéphane Ducasse 1 The VisualWorks Environment.
Stéphane Ducasse 1 Elements of Design - Simple Smells.
Centralized vs. Decentralized Interpreter Pattern Visitor Pattern.
Stéphane Ducasse 1 Visitor.
Making Decisions (True or False) Relational Operators >greater than =greater than or equal to
Objects & Dynamic Dispatch CSE 413 Autumn Plan We’ve learned a great deal about functional and object-oriented programming Now,  Look at semantics.
Definition of Object - Oriented Language.. Object-oriented programming (OOP) is a programming language model organized around "objects" rather than "actions"
S.Ducasse Stéphane Ducasse savoie.fr e/ e/ 1 Inheritance Semantics and Method Lookup.
Stéphane Ducasse 1 Elements of Design - Inheritance/Compositio n.
Thinking Mathematically
Smalltalk in a.NET World How to write a Smalltalk compiler without writing a VM John Brant
Topic 3: C Basics CSE 30: Computer Organization and Systems Programming Winter 2011 Prof. Ryan Kastner Dept. of Computer Science and Engineering University.
Stéphane Ducasse 1 Singleton.
S.Ducasse Stéphane Ducasse 1 Essential OO Concepts Stéphane Ducasse.
S.Ducasse Stéphane Ducasse 1 Common Mistakes and Debugging in VW.
Stéphane Ducasse 1 Run-Time...
Stéphane Ducasse 1 Strategy.
Chapter 3 Decisions Three control structures Algorithms Pseudocode Flowcharts If…then …else Nested if statements Code blocks { } multi statement blocks.
An Object-Oriented Approach to Programming Logic and Design Chapter 5 Making Decisions.
S.Ducasse Stéphane Ducasse 1 Smalltalk in a Nutshell.
S.Ducasse Stéphane Ducasse savoie.fr e/ e/ 1 Smalltalk in a Nutshell.
Stéphane Ducasse 1 A Little Journey in the Smalltalk Syntax.
1 Review for Midterm 2 Aaron Bloomfield CS 101-E.
Stéphane Ducasse 1 Elements of Design - Unit of Reuse.
Conditional statements and boolean expressions Arithmetic, relational and logical operators.
 2012 Pearson Education, Inc. Slide Chapter 3 Introduction to Logic.
Stéphane Ducasse 1 Abstract Classes.
Review A program is… a set of instructions that tell a computer what to do. Programs can also be called… software. Hardware refers to… the physical components.
Unit 1 Review By: Mr. Jacobs.
Conditional Statements A conditional statement lets us choose which statement will be executed next Conditional statements give us the power to make basic.
Computer Science: A Structured Programming Approach Using C1 Objectives ❏ To understand how decisions are made in a computer ❏ To understand the logical.
1 Case Study: Meta Classes  Class representation in memory  Class variables and class methods  Meta Classes  3 Level System  4 Level System  5 Level.
Introduction to Logic © 2008 Pearson Addison-Wesley.
Truth Tables for Negation, Conjunction, and Disjunction
Introduction To Robot Sensors
Truth Tables and Equivalent Statements
Chapter 2.3 Binary Logic.
Introduction To Robot Sensors
Expressions and Control Flow in JavaScript
Methods The real power of an object-oriented programming language takes place when you start to manipulate objects. A method defines an action that allows.
Introduction To Robot Decision Making
Conditions and Boolean Expressions
Sridhar Narayan Java Basics Sridhar Narayan
Chapter 3 Introduction to Logic 2012 Pearson Education, Inc.
Statements of Symbolic Logic
IAT 800 Foundations of Computational Art and Design
CSE 3302 Programming Languages
Trees That Represent Grammars
Presentation transcript:

Stéphane Ducasse 1 Objects to the Roots: Learning from beauty

S.Ducasse 2 Really?! No primitive types No hardcoded constructs for conditional Only messages Only objects and this works? I mean really? Not even slow? Can’t be real!

S.Ducasse 3 Motto Let’s open our eyes, look, understand, and deeply understand the underlying design aspects of object-oriented programming...

S.Ducasse 4 Booleans 3 > 0 ifTrue: ['positive'] ifFalse: ['negative' ]

S.Ducasse 5 Booleans 3 > 0 ifTrue: ['positive'] ifFalse: ['negative' ] 'positive'

S.Ducasse 6 Yes ifTrue:ifFalse: is a message! Weather isRaining ifTrue: [self takeMyUmbrella] ifFalse: [self takeMySunglasses] ifTrue:ifFalse is sent to an object: a boolean!

S.Ducasse 7 Booleans & | not or: and: (lazy) xor: ifTrue:ifFalse: ifFalse:ifTrue:...

S.Ducasse 8 Lazy Logical Operators false and: [1 error: 'crazy'] PrIt-> false and not an error

S.Ducasse 9 Yes! ifTrue:ifFalse: is a message send to a Boolean. But optimized by the compiler :)

S.Ducasse 10 Implementing not Now you are good and you should implement it Propose an implementation of not in a world where you do not have Booleans false not -> true true not -> false

S.Ducasse 11

S.Ducasse 12 Implementing ifTrue:ifFalse: Now you are good and you should implement it Propose an implementation of not in a world where you do not have Booleans false ifTrue: [ 3 ] ifFalse: [ 5 ] true ifTrue: [ 3 ] ifFalse: [ 5 ]

S.Ducasse 13 Boolean Objects false and true are objects described by classes Boolean, True and False

S.Ducasse 14 Let’s the receiver decide!

S.Ducasse 15 Boolean>>not “Class Boolean is an abstract class that implements behavior common to true and false. Its subclasses are True and False. Subclasses must implement methods for logical operations &, not, controlling and:, or:, ifTrue:, ifFalse:, ifTrue:ifFalse:, ifFalse:ifTrue:” Boolean>>not "Negation. Answer true if the receiver is false, answer false if the receiver is true." self subclassResponsibility

S.Ducasse 16 Not false not -> true true not -> false Boolean>>not "Negation. Answer true if the receiver is false, answer false if the receiver is true.” self subclassResponsibility False>>not "Negation -- answer true since the receiver is false." ^true True>>not "Negation--answer false since the receiver is true." ^false

S.Ducasse 17 | (Or) true | true -> true true | false -> true true | anything -> true false | true -> true false | false -> false false | anything -> anything

S.Ducasse 18 Boolean>> | aBoolean "Evaluating disjunction (OR). Evaluate the argument. Answer true if either the receiver or the argument is true." self subclassResponsibility

S.Ducasse 19 False>> | aBoolean false | true -> true false | false -> false false | anything -> anything False>> | aBoolean "Evaluating disjunction (OR) -- answer with the argument, aBoolean." ^ aBoolean

S.Ducasse 20 True>> | aBoolean true | true -> true true | false -> true true | anything -> true True>> | aBoolean "Evaluating disjunction (OR) -- answer true since the receiver is true." ^ self

S.Ducasse 21 Boolean, True and False

S.Ducasse 22 Implementation Note Note that the Virtual Machine shortcuts calls to boolean such as condition for speed reason. Virtual machines such as VisualWorks introduced a kind of macro expansion, an optimisation for essential methods and Just In Time (JIT) compilation. A method is executed once and afterwards it is compiled into native code. So the second time it is invoked, the native code will be executed.

S.Ducasse 23

S.Ducasse 24 Ok so what? You will probably not implement another Boolean classes So is it really that totally useless?

S.Ducasse 25 Ternary logic Boolean: true, false, unknown

S.Ducasse 26 More important... Message sends act as case statements

S.Ducasse 27 OOP: the art of dispatching Subclasses create your vocabulary

S.Ducasse 28 Avoid Conditional Use objects and messages VM dispatch is a conditional switch: Use it! AntiIfCampaign

S.Ducasse 29 Summary Messages act as a dispatcher Avoid conditional