nested class modularity in squeak/smalltalk · 2019-12-14 · (effective java, 2nd edition) 6...

32
Nested Class Modularity in Squeak/Smalltalk Matthias Springer Software Architecture Group, Hasso Plattner Institute Master’s Thesis Disputation August 21, 2015

Upload: others

Post on 24-Jun-2020

11 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Nested Class Modularity in Squeak/Smalltalk · 2019-12-14 · (Effective Java, 2nd edition) 6 Matthias Springer “On the Criteria To Be Used in Decomposing ... Java generics, C++

Nested Class Modularity in Squeak/Smalltalk

Matthias Springer Software Architecture Group, Hasso Plattner Institute

Master’s Thesis Disputation

August 21, 2015

Page 2: Nested Class Modularity in Squeak/Smalltalk · 2019-12-14 · (Effective Java, 2nd edition) 6 Matthias Springer “On the Criteria To Be Used in Decomposing ... Java generics, C++

What is Modularity?According to Bertrand Meyer (Object-oriented Software Construction)

• Decomposability

• Composability

• Understandability

• Continuity

• Protection

2Nested Class Modularity in Squeak/Smalltalk Matthias Springer

Page 3: Nested Class Modularity in Squeak/Smalltalk · 2019-12-14 · (Effective Java, 2nd edition) 6 Matthias Springer “On the Criteria To Be Used in Decomposing ... Java generics, C++

Modularity in Squeak• Classes as modular units

• Problems

• Duplicate Class Names

• Dependency/Version Management

• Hierarchical Decomposition

3Nested Class Modularity in Squeak/Smalltalk Matthias Springer

Page 4: Nested Class Modularity in Squeak/Smalltalk · 2019-12-14 · (Effective Java, 2nd edition) 6 Matthias Springer “On the Criteria To Be Used in Decomposing ... Java generics, C++

Duplicate Class Names

same class names

4Nested Class Modularity in Squeak/Smalltalk Matthias Springer

Page 5: Nested Class Modularity in Squeak/Smalltalk · 2019-12-14 · (Effective Java, 2nd edition) 6 Matthias Springer “On the Criteria To Be Used in Decomposing ... Java generics, C++

Dependency Management• Library version conflict

• Transitive dependency version conflict

• Overhead of dependency management systems

5Nested Class Modularity in Squeak/Smalltalk Matthias Springer

Page 6: Nested Class Modularity in Squeak/Smalltalk · 2019-12-14 · (Effective Java, 2nd edition) 6 Matthias Springer “On the Criteria To Be Used in Decomposing ... Java generics, C++

Hierarchical Decomposition• “group together what belongs together”

(Effective Java, 2nd edition)

6 Matthias Springer

“On the Criteria To Be Used in Decomposing Systems into Modules”

(David L. Parnas)

Page 7: Nested Class Modularity in Squeak/Smalltalk · 2019-12-14 · (Effective Java, 2nd edition) 6 Matthias Springer “On the Criteria To Be Used in Decomposing ... Java generics, C++

Concept

7Nested Class Modularity in Squeak/Smalltalk Matthias Springer

Page 8: Nested Class Modularity in Squeak/Smalltalk · 2019-12-14 · (Effective Java, 2nd edition) 6 Matthias Springer “On the Criteria To Be Used in Decomposing ... Java generics, C++

Matriona

• Module system based on class nesting for Squeak

• Matryoshka ~ Matriona

• No VM changes, minor changes to Smalltalk compiler

• GUI based on Vivide

8Nested Class Modularity in Squeak/Smalltalk Matthias Springer

Page 9: Nested Class Modularity in Squeak/Smalltalk · 2019-12-14 · (Effective Java, 2nd edition) 6 Matthias Springer “On the Criteria To Be Used in Decomposing ... Java generics, C++

Nested Classes in Matriona

• Nested classes belong to enclosing class (like class instance variables)

• Access using message sends

• Nested classes are methods returningthe class object

9Nested Class Modularity in Squeak/Smalltalk Matthias Springer

Page 10: Nested Class Modularity in Squeak/Smalltalk · 2019-12-14 · (Effective Java, 2nd edition) 6 Matthias Springer “On the Criteria To Be Used in Decomposing ... Java generics, C++

Accessing the Lexical Scope

• enclosing: enclosing class

• outer: all enclosing classes

• scope: self, then all enclosing classes

10Nested Class Modularity in Squeak/Smalltalk Matthias Springer

Page 11: Nested Class Modularity in Squeak/Smalltalk · 2019-12-14 · (Effective Java, 2nd edition) 6 Matthias Springer “On the Criteria To Be Used in Decomposing ... Java generics, C++

Example: Lexical Scope

11Nested Class Modularity in Squeak/Smalltalk Matthias Springer

Page 12: Nested Class Modularity in Squeak/Smalltalk · 2019-12-14 · (Effective Java, 2nd edition) 6 Matthias Springer “On the Criteria To Be Used in Decomposing ... Java generics, C++

Parameterized Classes(A B: 1) C: 2

scope p2

scope p3

Use Cases:

• External Configuration

• Mixins12Nested Class Modularity in Squeak/Smalltalk Matthias Springer

Page 13: Nested Class Modularity in Squeak/Smalltalk · 2019-12-14 · (Effective Java, 2nd edition) 6 Matthias Springer “On the Criteria To Be Used in Decomposing ... Java generics, C++

Implementation

13Nested Class Modularity in Squeak/Smalltalk Matthias Springer

Page 14: Nested Class Modularity in Squeak/Smalltalk · 2019-12-14 · (Effective Java, 2nd edition) 6 Matthias Springer “On the Criteria To Be Used in Decomposing ... Java generics, C++

Notation

SpaceCleanup class>>Level < class > ^ Morph subclass

SpaceCleanup class>>Level>>render …

14Nested Class Modularity in Squeak/Smalltalk Matthias Springer

Page 15: Nested Class Modularity in Squeak/Smalltalk · 2019-12-14 · (Effective Java, 2nd edition) 6 Matthias Springer “On the Criteria To Be Used in Decomposing ... Java generics, C++

Notation

NewClass < class > ^ Object subclassWithInstVars: ’foo bar’ classVars: ’Bar’ classInstVars: ’Foo’

15Nested Class Modularity in Squeak/Smalltalk Matthias Springer

Page 16: Nested Class Modularity in Squeak/Smalltalk · 2019-12-14 · (Effective Java, 2nd edition) 6 Matthias Springer “On the Criteria To Be Used in Decomposing ... Java generics, C++

Notation

• Class generator method: method which returns the target class for model instantiation

• Class definition: target class is uninitialized

• Class extension: target class is already initialized

16Nested Class Modularity in Squeak/Smalltalk Matthias Springer

Page 17: Nested Class Modularity in Squeak/Smalltalk · 2019-12-14 · (Effective Java, 2nd edition) 6 Matthias Springer “On the Criteria To Be Used in Decomposing ... Java generics, C++

Meta Model

17Nested Class Modularity in Squeak/Smalltalk Matthias Springer

Page 18: Nested Class Modularity in Squeak/Smalltalk · 2019-12-14 · (Effective Java, 2nd edition) 6 Matthias Springer “On the Criteria To Be Used in Decomposing ... Java generics, C++

Class Definition

18Nested Class Modularity in Squeak/Smalltalk Matthias Springer

Page 19: Nested Class Modularity in Squeak/Smalltalk · 2019-12-14 · (Effective Java, 2nd edition) 6 Matthias Springer “On the Criteria To Be Used in Decomposing ... Java generics, C++

Class Extension

19Nested Class Modularity in Squeak/Smalltalk Matthias Springer

Page 20: Nested Class Modularity in Squeak/Smalltalk · 2019-12-14 · (Effective Java, 2nd edition) 6 Matthias Springer “On the Criteria To Be Used in Decomposing ... Java generics, C++

Keywords

20

scope

Nested Class Modularity in Squeak/Smalltalk Matthias Springer

Page 21: Nested Class Modularity in Squeak/Smalltalk · 2019-12-14 · (Effective Java, 2nd edition) 6 Matthias Springer “On the Criteria To Be Used in Decomposing ... Java generics, C++

Implicit LexicalScope vs. Squeak Environments

• LexicalScope: late-bound lookup

• Squeak environments: early-bound lookup

• Late-bound lookup makes it easier to react to structural changes/source code changes

• Parameterized classes cannot be early bound

21Nested Class Modularity in Squeak/Smalltalk Matthias Springer

Page 22: Nested Class Modularity in Squeak/Smalltalk · 2019-12-14 · (Effective Java, 2nd edition) 6 Matthias Springer “On the Criteria To Be Used in Decomposing ... Java generics, C++

Use Cases

22Nested Class Modularity in Squeak/Smalltalk Matthias Springer

Page 23: Nested Class Modularity in Squeak/Smalltalk · 2019-12-14 · (Effective Java, 2nd edition) 6 Matthias Springer “On the Criteria To Be Used in Decomposing ... Java generics, C++

Duplicate Class Names

23Nested Class Modularity in Squeak/Smalltalk Matthias Springer

Page 24: Nested Class Modularity in Squeak/Smalltalk · 2019-12-14 · (Effective Java, 2nd edition) 6 Matthias Springer “On the Criteria To Be Used in Decomposing ... Java generics, C++

Versioning

MyApp class»MathLib ^ MathLibrary v1 latest

MyApp class»…»…»Geometry ^ scope MathLib Geometry

24Nested Class Modularity in Squeak/Smalltalk Matthias Springer

Page 25: Nested Class Modularity in Squeak/Smalltalk · 2019-12-14 · (Effective Java, 2nd edition) 6 Matthias Springer “On the Criteria To Be Used in Decomposing ... Java generics, C++

External Configuration

(PaintbrushWithMatrix: Matrix IO: ReaderWriter) class»Bitmap class»load: aFile | instance |

instance := self new. scope ReaderWriter readPixelsFrom: aFile do: [ :point :color | instance setPixel: point color: color ]. ^ instance

25Nested Class Modularity in Squeak/Smalltalk Matthias Springer

Page 26: Nested Class Modularity in Squeak/Smalltalk · 2019-12-14 · (Effective Java, 2nd edition) 6 Matthias Springer “On the Criteria To Be Used in Decomposing ... Java generics, C++

Mixins

MyCollection»do: aBlock …

CollectionFilter: base < class > ^ base subclass

(CollectionFilter: base)»detect: aBlock self do: [ :el | (aBlock value: el) ifTrue: [ ^ el ] ]. self error: ‘element not found’

26Nested Class Modularity in Squeak/Smalltalk Matthias Springer

Mixin = abstract subclass / class transformator function

Page 27: Nested Class Modularity in Squeak/Smalltalk · 2019-12-14 · (Effective Java, 2nd edition) 6 Matthias Springer “On the Criteria To Be Used in Decomposing ... Java generics, C++

Hierarchical Decomposition

27Nested Class Modularity in Squeak/Smalltalk Matthias Springer

Page 28: Nested Class Modularity in Squeak/Smalltalk · 2019-12-14 · (Effective Java, 2nd edition) 6 Matthias Springer “On the Criteria To Be Used in Decomposing ... Java generics, C++

Future Work

28Nested Class Modularity in Squeak/Smalltalk Matthias Springer

Page 29: Nested Class Modularity in Squeak/Smalltalk · 2019-12-14 · (Effective Java, 2nd edition) 6 Matthias Springer “On the Criteria To Be Used in Decomposing ... Java generics, C++

Future Work

• Performance (byte code transformation)

• Squeak integration + GUI (browser)

• Extension methods

• Migration of legacy code

29Nested Class Modularity in Squeak/Smalltalk Matthias Springer

Page 30: Nested Class Modularity in Squeak/Smalltalk · 2019-12-14 · (Effective Java, 2nd edition) 6 Matthias Springer “On the Criteria To Be Used in Decomposing ... Java generics, C++

Related Work

30Nested Class Modularity in Squeak/Smalltalk Matthias Springer

Page 31: Nested Class Modularity in Squeak/Smalltalk · 2019-12-14 · (Effective Java, 2nd edition) 6 Matthias Springer “On the Criteria To Be Used in Decomposing ... Java generics, C++

Related Work• Duplicate Class Names:

Packages / Namespaces (VisualWorks, Java, Ruby), Squeak environments, Newspeak modules

• Class Nesting: Newspeak, BETA, Java, Ruby, Python

• Dependency Management: Newspeak, Maven, RubyGems, pip, Metacello

• Parameterized Classes / Mixins: Java generics, C++ templates, Newspeak, Ruby, Python, Traits

31Nested Class Modularity in Squeak/Smalltalk Matthias Springer

Page 32: Nested Class Modularity in Squeak/Smalltalk · 2019-12-14 · (Effective Java, 2nd edition) 6 Matthias Springer “On the Criteria To Be Used in Decomposing ... Java generics, C++

Summary• Matriona: a module system for Squeak based on class nesting

• “Design Principles Behind Smalltalk” (D. H. Ingalls)

• Personal Mastery: entire system should be comprehensible by a single individual

• Factoring: each independent component appears only once

• Modularity: no component should depend on internal details of another component

• Good Design: system should be built with a minimum set of unchangeable parts, which are as generic as possible

32Nested Class Modularity in Squeak/Smalltalk Matthias Springer