SlideShare a Scribd company logo
1 of 65
Carlo Pescio @CarloPescio http://physicsofsoftware.com
Carlo Pescio
On Growth and Software
(or: applying some Physics of Software)
Carlo Pescio @CarloPescio http://physicsofsoftware.com
Inspired by a classic
Carlo Pescio @CarloPescio http://physicsofsoftware.com
Form as a Diagram of Forces
Carlo Pescio @CarloPescio http://physicsofsoftware.com
Form as a Recipe for Reaction
My own little step – don’t blame D’Arcy 
Material and shape encode reactions to “forces”
Carlo Pescio @CarloPescio http://physicsofsoftware.com
Form as a Recipe for Growth
Carlo Pescio @CarloPescio http://physicsofsoftware.com
Good ol’ book
+ - U
U
Carlo Pescio @CarloPescio http://physicsofsoftware.com
The ring binder
U
D
D
U
U
C
C
Carlo Pescio @CarloPescio http://physicsofsoftware.com
Growth Model
Carlo Pescio @CarloPescio http://physicsofsoftware.com
Growth Model
Carlo Pescio @CarloPescio http://physicsofsoftware.com
[Mis]Aligned Growth Model
(ideal) growth in
decision space
(actual) growth in
artifact space
Carlo Pescio @CarloPescio http://physicsofsoftware.com
“Growth” in computing
Extensibility Scalability
C/D features in code C/D run-time load
Code as artifacts Run-time behavior
C/D feature -> C/D load ->
C/D artifact C/D machines / CPU
Carlo Pescio @CarloPescio http://physicsofsoftware.com
Carlo Pescio @CarloPescio http://physicsofsoftware.com
Extensibility?
Carlo Pescio @CarloPescio http://physicsofsoftware.com
Symmetry in Growth [model]
Create feature
Delete feature
decision space
Create artifacts
Delete artifacts
artifact space
Carlo Pescio @CarloPescio http://physicsofsoftware.com
Why bother???
- Product families
- Plug-in architectures, 3rd party modules
- Modular understanding
- “zero impact” evolution
Carlo Pescio @CarloPescio http://physicsofsoftware.com
In practice?
A simple, specific problem
with a specific growth model.
Lessons here apply to similar growth models.
Not everything will / should follow this model.
The final shape is not universal
the method of investigation kinda is
Carlo Pescio @CarloPescio http://physicsofsoftware.com
Easy
Carlo Pescio @CarloPescio http://physicsofsoftware.com
Some physics required 
Carlo Pescio @CarloPescio http://physicsofsoftware.com
Vector drawing for dummies
Carlo Pescio @CarloPescio http://physicsofsoftware.com
Growth Model
- New shape types will come over time
- New behaviors will come over time
- Behaviors can be composed out of a fixed core
- That entire menu only requires {bounding box, move}
I’m dealing only with geometry right now
Carlo Pescio @CarloPescio http://physicsofsoftware.com
Context
We have an open, discrete set of “concepts”
{ Square, Triangle, Circle, … }
It’s open and so will grow by addition.
T3
T2
T1
+
+
T = { Ti }
Carlo Pescio @CarloPescio http://physicsofsoftware.com
In code?
How do we mirror in code?
• N types: OK
• N classes: OK
• N objects / prototypes: OK
• through closures / records of functions: ok as well
• Case classes: Maybe
• 1 sum type: NO
+
T = { Ti }
N trivial classes (Scala)
class Point( var x : Float,
var y : Float ) {}
class Box( var topLeft : Point,
var bottomRight : Point ) {}
class Circle( var center : Point,
var radius : Float ) {}
class Square( var topLeft : Point,
var side : Float ) {}
+
1 sum type (Haskell): nope
type Point = (Float,Float)
type Radius = Float
type Side = Float
data Shape =
Circle Point Radius |
Square Point Side
+ U
Carlo Pescio @CarloPescio http://physicsofsoftware.com
Context
We have a closed set of “core behaviors”
{ BoundingBox, Move, Scale, Rotate, Mirror }
^
H = { Hi }H
Carlo Pescio @CarloPescio http://physicsofsoftware.com
Context
“Core behaviors” depends on concepts.
More precisely: when we create/delete a concept,
we create/delete its implementation of core
behaviors.
^
Ti
C/D > HTi
T3
T2
T1
+
HT3
HT2
HT1
+
Carlo Pescio @CarloPescio http://physicsofsoftware.com
In code?
How do we mirror
• Member functions (class, objects): ok
• Functions (+ optional overloading): ok
• 1 function per behavior + pattern matching: NO
• That removes case classes from the table
^
Ti
C/D > HTi
Case classes (Scala): nope
abstract class Shape
case class Circle(center:Point, radius:Float) extends Shape
case class Square(topLeft:Point, side:Float) extends Shape
+
U
object moveTool {
def move( sh : Shape, newCenter : Point ) : Shape = {
sh match {
case Circle(center, radius) =>
new Circle( newCenter, radius);
case Square( topLeft, side) =>
new Square(Point(topLeft.x-side/2,
topLeft.y-side/2), side);
}
}
}
Carlo Pescio @CarloPescio http://physicsofsoftware.com
Context
We can:
a) create instances of those concepts and keep
them available for selection
b) select some of those instances (mixed
concepts) from a bounding box
c) apply composite behaviors to those (mixed)
instances
Carlo Pescio @CarloPescio http://physicsofsoftware.com
Context
a) We want to create instances and
keep them “available” for selection
In code:
• A single collection: OK
• A collection for each type: OK
A collection for each type is ok, as we still transfer
creation (of concept) into creation (of a new list).
Carlo Pescio @CarloPescio http://physicsofsoftware.com
Context
b) We want to select a (mixed) subset by
dragging a selection box.
So we need a selection function looping over all
the available shapes and checking their bounding
boxes (BB is a “core behavior” for shapes).
Carlo Pescio @CarloPescio http://physicsofsoftware.com
selection
box
f
selection
1 collection per type won’t work anymore
+
+
U
Same reasoning applies
to any of the composite
behaviors
shapes
selected
shapes
Carlo Pescio @CarloPescio http://physicsofsoftware.com
Context
We have an open set of “composite behaviors”
+
B = { Bi }
e.g.
{ align left, distribute horizontally, flip vertical}
They operate on collections of concepts
(instances).
^
Bi ≡ ·(H)
Carlo Pescio @CarloPescio http://physicsofsoftware.com
Context
+
T = { Ti }
*
+
B = { Bi }
^ +
(HTi)
·
C/D
Two problems with Bi here:
1) Works on a set of shapes
(same as selection)
2) Composed from a set of
type-dependent core
behaviors (same as
selection w/ BB)
Carlo Pescio @CarloPescio http://physicsofsoftware.com
A single collection of shapes
That would require either:
• A dynamic language
• mixing types is natural
• A way to form a placeholder type as substitute
for the individual types:
• Base type + subtypes
• Base class / interface + derived classes
• [objects as] Records of closures
• Existential types / Abstract types
Carlo Pescio @CarloPescio http://physicsofsoftware.com
Classes in Scala (easy)
abstract class Shape {
def explain() : String;
def boundingBox() : Box;
def moveCenter(newCenter:Point) :
Shape;
}
Classes in Scala (easy)
class Circle(private var center: Point,
private var radius: Float)
extends Shape {
def explain(): String =
{ "circle " + center.x + " " +
center.y + " " + radius; }
def boundingBox(): Box = { new Box(
Point(center.x-radius, center.y-radius),
Point(center.x+radius, center.y+radius)
); }
def moveCenter(newCenter: Point): Shape =
{ new Circle(newCenter, radius); }
}
Classes in Scala (easy)
class Square(private var topLeft: Point,
private var side: Float)
extends Shape {
def explain(): String =
{ "square " + topLeft.x + " " +
topLeft.y + " " + side; }
def boundingBox(): Box = { new Box(
topLeft,
Point(topLeft.x+side, topLeft.y+side)); }
def moveCenter(newCenter: Point): Shape =
{ new Square(Point(topLeft.x-side/2,
topLeft.y-side/2), side); }
}
Classes in Scala (easy)
object MainObject {
def main(args: Array[String]): Unit = {
val c1 = new Circle( Point(1,1), 4 ) ;
val s1 = new Square( Point(0,0), 4 ) ;
val sh : List[Shape] = List( c1, s1 );
var d : String = sh.map( s =>
s.moveCenter(Point(5,5)).explain()
).reduce((s1,s2) => s1 + " ; " + s2) ;
println( d ) ;
}
}
Records of Closures (Haskell)
type Point = (Float,Float)
type Box = (Point,Point)
data Shape = Shape {
explain :: String,
boundingBox :: Box,
moveCenter :: Point -> Shape
}
Records of Closures (Haskell)
circle :: Point -> Float -> Shape
circle (x,y) r =
Shape explain boundingBox moveCenter
where
explain = "circle " ++ show x ++ " "
++ show y ++ " " ++ show r
boundingBox = ( (x-r, y-r),
(x+r, y+r) )
moveCenter (x1,y1) = circle (x1, y1) r
Records of Closures (Haskell)
square :: Point -> Float -> Shape
square (t,l) s =
Shape explain boundingBox moveCenter
where
explain = "square " ++ show t ++ " "
++ show l ++ " " ++ show s
boundingBox = ( (t, l), (t+s, l+s) )
moveCenter (x1,y1) =
square (x1-s/2, y1-s/2) s
Carlo Pescio @CarloPescio http://physicsofsoftware.com
Records of Closures (Haskell)
main = do
let c1 = circle (1,1) 3
let s1 = square (1,1) 3
let sh = [ c1, s1 ]
putStrLn
(concat ( map (s ->
(explain (moveCenter s (5,5)))
++ " ; ") sh ) )
Existential type (Haskell)
type Point = (Float,Float)
type Box = (Point,Point)
class ShapeTC a where
explain :: a -> String
boundingBox :: a -> Box
moveCenter :: a -> Point -> Shape
data Shape = forall a. ShapeTC a => Shape a
instance ShapeTC Shape where
explain (Shape shape) = explain shape
boundingBox (Shape shape) = boundingBox shape
moveCenter (Shape shape) = moveCenter shape
Existential type (Haskell)
data Circle = Circle Point Float
instance ShapeTC Circle where
explain (Circle (x,y) r ) =
"circle " ++ show x ++ " " ++ show y ++
" " ++ show r
boundingBox (Circle (x,y) r) =
( (x-r, y-r), (x+r, y+r) )
moveCenter (Circle (x,y) r) (x1,y1) =
circle (x1, y1) r
circle :: Point -> Float -> Shape
circle (x,y) r = Shape (Circle (x,y) r)
Existential type (Haskell)
data Square = Square Point Float
instance ShapeTC Square where
explain (Square (t,l) s) =
"square " ++ show t ++ " " ++ show l ++
" " ++ show s
boundingBox (Square (t,l) s) =
( (t, l), (t+s, l+s) )
moveCenter (Square (t,l) s) (x1,y1) =
square (x1-s/2, y1-s/2) s
square :: Point -> Float -> Shape
square (t,l) s = Shape (Square (t,l) s)
Existential type (Haskell)
main = do
let c1 = circle (2,2) 3
let s1 = square (2,2) 3
let sh = [ c1, s1 ]
putStrLn
(concat ( map (s ->
(explain (moveCenter s (6,6)))
++ " ; ") sh ) )
“misaligned” growth model
B3
B2
B1
+
T3
T2
T1
+
HT3
HT2
HT1
+
UU
(madness)
B3
B2
B1
+
T3
T2
T1
+
HT3
HT2
HT1
+
OK 
H
B3
B2
B1
+
T
T3
T2
T1
+
HT3
HT2
HT1
+
Carlo Pescio @CarloPescio http://physicsofsoftware.com
Work in progress
^
Ha = { Hi }
+
T = { Ti }
*
+
B = { Bi }
^ +
HTi
·
C/D
^
Ta
+
T = { Ti }
*
+
B = { Bi }
^ +
(HTi)
·
C/D
Carlo Pescio @CarloPescio http://physicsofsoftware.com
Every type has identity (to keep it simple: name)
F knows identities in => F unstable
So:
- F should not know identities in
- F needs to operate on values of those types.
=> F must be isolated from type identity.
Identity and Isolation
+
T
+
T
Carlo Pescio @CarloPescio http://physicsofsoftware.com
Common techniques for isolation:
- Add a new “abstract type” Ta, make every Ti an
instance or subtype of Ta
- Requires late binding as F will only know Ta
- Relationship between Ti and Ta can be implicit
(structural conformance)
- Add a new concrete type Tc exposing only
functions, and bind every instance of Ti to an
instance of Tc
- That’s again providing late binding as F won’t know
the identity of the functions it’s calling
Isolation Techniques
Carlo Pescio @CarloPescio http://physicsofsoftware.com
structures vs paradigms
Carlo Pescio @CarloPescio http://physicsofsoftware.com
OO
SUCKS!
Carlo Pescio @CarloPescio http://physicsofsoftware.com
Get your trick question ready
1. The next time someone shows you a decent use
for OO-like polymorphism & encapsulation, what
can you say?
what about serialization in multiple formats?
Carlo Pescio @CarloPescio http://physicsofsoftware.com
Remember this?
Carlo Pescio @CarloPescio http://physicsofsoftware.com
Elastic yet bent !?
Carlo Pescio @CarloPescio http://physicsofsoftware.com
We only have geometry so far
I want rendering (new core behaviors!)
I may want only geometry
I may want only rendering
I may want both
=> Geometry and Rendering in distinct artifacts
Breaking the growth model
Carlo Pescio @CarloPescio http://physicsofsoftware.com
Growing and Breaking
partial class Circle
{
private readonly Point center;
private readonly double radius;
public Circle( Point center, double radius )
{
this.center = center;
this.radius = radius;
}
}
interface Shape
{
Shape Move(Point newCenter);
}
partial class Circle : Shape
{
public Shape Move(Point newCenter)
{
return new Circle(newCenter, radius);
}
}
interface Drawing
{
void Render();
}
partial class Circle : Drawing
{
public void Render()
{
Console.WriteLine(
"I'm a Circle with radius " +
radius.ToString());
}
}
static void Main(string[] args)
{
Shape c = new Circle(new Point(10, 10), 5);
Drawing d = c as Drawing;
d.Render();
}
constraint
Shape => Drawing
Carlo Pescio @CarloPescio http://physicsofsoftware.com
“Design Process”
I didn’t use
- Design principles
- Patterns
- Tests
- Religion
I only aimed for symmetry
- Features growth model
- Artifacts growth model
Break a symmetry
to get a symmetry 
Carlo Pescio @CarloPescio http://physicsofsoftware.com
…Monads 
Or polymorphism
Or existential types
Or type system constraints
Or many things yet to be invented
Just by understanding forces 
You may have invented…
Carlo Pescio @CarloPescio http://physicsofsoftware.com
Get in touch
@CarloPescio
carlo.pescio@gmail.com
http://physicsofsoftware.com
/forum

More Related Content

What's hot

JDD2015: Functional programing and Event Sourcing - a pair made in heaven - e...
JDD2015: Functional programing and Event Sourcing - a pair made in heaven - e...JDD2015: Functional programing and Event Sourcing - a pair made in heaven - e...
JDD2015: Functional programing and Event Sourcing - a pair made in heaven - e...
PROIDEA
 
Introduction to Monads in Scala (2)
Introduction to Monads in Scala (2)Introduction to Monads in Scala (2)
Introduction to Monads in Scala (2)
stasimus
 

What's hot (20)

The Ring programming language version 1.5.3 book - Part 36 of 184
The Ring programming language version 1.5.3 book - Part 36 of 184The Ring programming language version 1.5.3 book - Part 36 of 184
The Ring programming language version 1.5.3 book - Part 36 of 184
 
The Ring programming language version 1.2 book - Part 24 of 84
The Ring programming language version 1.2 book - Part 24 of 84The Ring programming language version 1.2 book - Part 24 of 84
The Ring programming language version 1.2 book - Part 24 of 84
 
Mikhail Khristophorov "Introduction to Regular Expressions"
Mikhail Khristophorov "Introduction to Regular Expressions"Mikhail Khristophorov "Introduction to Regular Expressions"
Mikhail Khristophorov "Introduction to Regular Expressions"
 
The Ring programming language version 1.5.4 book - Part 36 of 185
The Ring programming language version 1.5.4 book - Part 36 of 185The Ring programming language version 1.5.4 book - Part 36 of 185
The Ring programming language version 1.5.4 book - Part 36 of 185
 
The Ring programming language version 1.5.2 book - Part 35 of 181
The Ring programming language version 1.5.2 book - Part 35 of 181The Ring programming language version 1.5.2 book - Part 35 of 181
The Ring programming language version 1.5.2 book - Part 35 of 181
 
SacalaZa #1
SacalaZa #1SacalaZa #1
SacalaZa #1
 
The Ring programming language version 1.6 book - Part 39 of 189
The Ring programming language version 1.6 book - Part 39 of 189The Ring programming language version 1.6 book - Part 39 of 189
The Ring programming language version 1.6 book - Part 39 of 189
 
[Expert Fridays] Александр Чичигин - Как перестать бояться и полюбить COQ
[Expert Fridays] Александр Чичигин - Как перестать бояться и полюбить COQ[Expert Fridays] Александр Чичигин - Как перестать бояться и полюбить COQ
[Expert Fridays] Александр Чичигин - Как перестать бояться и полюбить COQ
 
Scala by Luc Duponcheel
Scala by Luc DuponcheelScala by Luc Duponcheel
Scala by Luc Duponcheel
 
Scala or functional programming from a python developer's perspective
Scala or functional programming from a python developer's perspectiveScala or functional programming from a python developer's perspective
Scala or functional programming from a python developer's perspective
 
The Ring programming language version 1.5.3 book - Part 30 of 184
The Ring programming language version 1.5.3 book - Part 30 of 184The Ring programming language version 1.5.3 book - Part 30 of 184
The Ring programming language version 1.5.3 book - Part 30 of 184
 
JDD2015: Functional programing and Event Sourcing - a pair made in heaven - e...
JDD2015: Functional programing and Event Sourcing - a pair made in heaven - e...JDD2015: Functional programing and Event Sourcing - a pair made in heaven - e...
JDD2015: Functional programing and Event Sourcing - a pair made in heaven - e...
 
Optics with monocle - Modeling the part and the whole
Optics with monocle - Modeling the part and the wholeOptics with monocle - Modeling the part and the whole
Optics with monocle - Modeling the part and the whole
 
Introduction to Monads in Scala (2)
Introduction to Monads in Scala (2)Introduction to Monads in Scala (2)
Introduction to Monads in Scala (2)
 
The Ring programming language version 1.5.4 book - Part 30 of 185
The Ring programming language version 1.5.4 book - Part 30 of 185The Ring programming language version 1.5.4 book - Part 30 of 185
The Ring programming language version 1.5.4 book - Part 30 of 185
 
Scala 101
Scala 101Scala 101
Scala 101
 
The Ring programming language version 1.9 book - Part 38 of 210
The Ring programming language version 1.9 book - Part 38 of 210The Ring programming language version 1.9 book - Part 38 of 210
The Ring programming language version 1.9 book - Part 38 of 210
 
Data structures
Data structuresData structures
Data structures
 
The Ring programming language version 1.8 book - Part 35 of 202
The Ring programming language version 1.8 book - Part 35 of 202The Ring programming language version 1.8 book - Part 35 of 202
The Ring programming language version 1.8 book - Part 35 of 202
 
Scala基礎勉強会: Featherweight Scalaの紹介および型付け規則の決定可能性について
Scala基礎勉強会: Featherweight Scalaの紹介および型付け規則の決定可能性についてScala基礎勉強会: Featherweight Scalaの紹介および型付け規則の決定可能性について
Scala基礎勉強会: Featherweight Scalaの紹介および型付け規則の決定可能性について
 

Viewers also liked

Design final review sculpture
Design final review sculptureDesign final review sculpture
Design final review sculpture
Riverwood HS
 
Principle of design
Principle of designPrinciple of design
Principle of design
Mika Lee
 
Design printmaking terms pics
Design printmaking terms picsDesign printmaking terms pics
Design printmaking terms pics
Riverwood HS
 
Introduction to sculpture
Introduction to sculpture Introduction to sculpture
Introduction to sculpture
cequinn1
 
STAND 2 - MANINDIGAN SA TAMANG PRINSIPYO - PTR VETTY GUTIERREZ - 7AM MABUHAY ...
STAND 2 - MANINDIGAN SA TAMANG PRINSIPYO - PTR VETTY GUTIERREZ - 7AM MABUHAY ...STAND 2 - MANINDIGAN SA TAMANG PRINSIPYO - PTR VETTY GUTIERREZ - 7AM MABUHAY ...
STAND 2 - MANINDIGAN SA TAMANG PRINSIPYO - PTR VETTY GUTIERREZ - 7AM MABUHAY ...
Faithworks Christian Church
 
Sculpture(2)
Sculpture(2)Sculpture(2)
Sculpture(2)
Dave Roen
 
elemento ng sining
elemento ng sining elemento ng sining
elemento ng sining
Maritoni Lat
 
Types of sculptures my report
Types of sculptures my reportTypes of sculptures my report
Types of sculptures my report
Tootchie Sanchez
 

Viewers also liked (20)

Design final review sculpture
Design final review sculptureDesign final review sculpture
Design final review sculpture
 
Principle of design
Principle of designPrinciple of design
Principle of design
 
Design printmaking terms pics
Design printmaking terms picsDesign printmaking terms pics
Design printmaking terms pics
 
SCULPTURES
SCULPTURESSCULPTURES
SCULPTURES
 
Principles of design
Principles of designPrinciples of design
Principles of design
 
Sculpture Introduction
Sculpture IntroductionSculpture Introduction
Sculpture Introduction
 
Introduction to sculpture
Introduction to sculpture Introduction to sculpture
Introduction to sculpture
 
What is Sculpture?
What is Sculpture? What is Sculpture?
What is Sculpture?
 
Sculpture
SculptureSculpture
Sculpture
 
Lecture 1 b definition of principle of design
Lecture 1 b definition of principle of designLecture 1 b definition of principle of design
Lecture 1 b definition of principle of design
 
STAND 2 - MANINDIGAN SA TAMANG PRINSIPYO - PTR VETTY GUTIERREZ - 7AM MABUHAY ...
STAND 2 - MANINDIGAN SA TAMANG PRINSIPYO - PTR VETTY GUTIERREZ - 7AM MABUHAY ...STAND 2 - MANINDIGAN SA TAMANG PRINSIPYO - PTR VETTY GUTIERREZ - 7AM MABUHAY ...
STAND 2 - MANINDIGAN SA TAMANG PRINSIPYO - PTR VETTY GUTIERREZ - 7AM MABUHAY ...
 
Principles
PrinciplesPrinciples
Principles
 
Sculpture
SculptureSculpture
Sculpture
 
Sculpture(2)
Sculpture(2)Sculpture(2)
Sculpture(2)
 
Bec pelc sining
Bec pelc siningBec pelc sining
Bec pelc sining
 
Humanities 100: Sculpture and Architecture
Humanities 100: Sculpture and ArchitectureHumanities 100: Sculpture and Architecture
Humanities 100: Sculpture and Architecture
 
elemento ng sining
elemento ng sining elemento ng sining
elemento ng sining
 
Types of sculptures my report
Types of sculptures my reportTypes of sculptures my report
Types of sculptures my report
 
introduction to sculpture
introduction to sculptureintroduction to sculpture
introduction to sculpture
 
Sculpture ppt
Sculpture pptSculpture ppt
Sculpture ppt
 

Similar to On Growth and Software

Haskell retrospective
Haskell retrospectiveHaskell retrospective
Haskell retrospective
chenge2k
 
(How) can we benefit from adopting scala?
(How) can we benefit from adopting scala?(How) can we benefit from adopting scala?
(How) can we benefit from adopting scala?
Tomasz Wrobel
 
High Wizardry in the Land of Scala
High Wizardry in the Land of ScalaHigh Wizardry in the Land of Scala
High Wizardry in the Land of Scala
djspiewak
 
Real World Haskell: Lecture 4
Real World Haskell: Lecture 4Real World Haskell: Lecture 4
Real World Haskell: Lecture 4
Bryan O'Sullivan
 

Similar to On Growth and Software (20)

DS MOD2 (1) (1).pptx
DS MOD2 (1) (1).pptxDS MOD2 (1) (1).pptx
DS MOD2 (1) (1).pptx
 
Haskell retrospective
Haskell retrospectiveHaskell retrospective
Haskell retrospective
 
Introduction to Scala
Introduction to ScalaIntroduction to Scala
Introduction to Scala
 
The Ring programming language version 1.2 book - Part 26 of 84
The Ring programming language version 1.2 book - Part 26 of 84The Ring programming language version 1.2 book - Part 26 of 84
The Ring programming language version 1.2 book - Part 26 of 84
 
Scala in Places API
Scala in Places APIScala in Places API
Scala in Places API
 
(How) can we benefit from adopting scala?
(How) can we benefit from adopting scala?(How) can we benefit from adopting scala?
(How) can we benefit from adopting scala?
 
SDC - Einführung in Scala
SDC - Einführung in ScalaSDC - Einführung in Scala
SDC - Einführung in Scala
 
A bit about Scala
A bit about ScalaA bit about Scala
A bit about Scala
 
Stacks
StacksStacks
Stacks
 
Lambda? You Keep Using that Letter
Lambda? You Keep Using that LetterLambda? You Keep Using that Letter
Lambda? You Keep Using that Letter
 
Scala - brief intro
Scala - brief introScala - brief intro
Scala - brief intro
 
Sequence and Traverse - Part 2
Sequence and Traverse - Part 2Sequence and Traverse - Part 2
Sequence and Traverse - Part 2
 
Introduction to Scala for JCConf Taiwan
Introduction to Scala for JCConf TaiwanIntroduction to Scala for JCConf Taiwan
Introduction to Scala for JCConf Taiwan
 
High Wizardry in the Land of Scala
High Wizardry in the Land of ScalaHigh Wizardry in the Land of Scala
High Wizardry in the Land of Scala
 
Slides
SlidesSlides
Slides
 
The Object Oriented Paradigm in perspective
The Object Oriented Paradigm in perspectiveThe Object Oriented Paradigm in perspective
The Object Oriented Paradigm in perspective
 
Real World Haskell: Lecture 4
Real World Haskell: Lecture 4Real World Haskell: Lecture 4
Real World Haskell: Lecture 4
 
Empathic Programming - How to write comprehensible code
Empathic Programming - How to write comprehensible codeEmpathic Programming - How to write comprehensible code
Empathic Programming - How to write comprehensible code
 
Rewriting Java In Scala
Rewriting Java In ScalaRewriting Java In Scala
Rewriting Java In Scala
 
麻省理工C++公开教学课程(二)
麻省理工C++公开教学课程(二)麻省理工C++公开教学课程(二)
麻省理工C++公开教学课程(二)
 

Recently uploaded

AI/ML Infra Meetup | Improve Speed and GPU Utilization for Model Training & S...
AI/ML Infra Meetup | Improve Speed and GPU Utilization for Model Training & S...AI/ML Infra Meetup | Improve Speed and GPU Utilization for Model Training & S...
AI/ML Infra Meetup | Improve Speed and GPU Utilization for Model Training & S...
Alluxio, Inc.
 

Recently uploaded (20)

AI/ML Infra Meetup | Improve Speed and GPU Utilization for Model Training & S...
AI/ML Infra Meetup | Improve Speed and GPU Utilization for Model Training & S...AI/ML Infra Meetup | Improve Speed and GPU Utilization for Model Training & S...
AI/ML Infra Meetup | Improve Speed and GPU Utilization for Model Training & S...
 
OpenChain @ LF Japan Executive Briefing - May 2024
OpenChain @ LF Japan Executive Briefing - May 2024OpenChain @ LF Japan Executive Briefing - May 2024
OpenChain @ LF Japan Executive Briefing - May 2024
 
Crafting the Perfect Measurement Sheet with PLM Integration
Crafting the Perfect Measurement Sheet with PLM IntegrationCrafting the Perfect Measurement Sheet with PLM Integration
Crafting the Perfect Measurement Sheet with PLM Integration
 
AI/ML Infra Meetup | Perspective on Deep Learning Framework
AI/ML Infra Meetup | Perspective on Deep Learning FrameworkAI/ML Infra Meetup | Perspective on Deep Learning Framework
AI/ML Infra Meetup | Perspective on Deep Learning Framework
 
COMPUTER AND ITS COMPONENTS PPT.by naitik sharma Class 9th A mittal internati...
COMPUTER AND ITS COMPONENTS PPT.by naitik sharma Class 9th A mittal internati...COMPUTER AND ITS COMPONENTS PPT.by naitik sharma Class 9th A mittal internati...
COMPUTER AND ITS COMPONENTS PPT.by naitik sharma Class 9th A mittal internati...
 
AI/ML Infra Meetup | Reducing Prefill for LLM Serving in RAG
AI/ML Infra Meetup | Reducing Prefill for LLM Serving in RAGAI/ML Infra Meetup | Reducing Prefill for LLM Serving in RAG
AI/ML Infra Meetup | Reducing Prefill for LLM Serving in RAG
 
A Python-based approach to data loading in TM1 - Using Airflow as an ETL for TM1
A Python-based approach to data loading in TM1 - Using Airflow as an ETL for TM1A Python-based approach to data loading in TM1 - Using Airflow as an ETL for TM1
A Python-based approach to data loading in TM1 - Using Airflow as an ETL for TM1
 
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
 
Top Mobile App Development Companies 2024
Top Mobile App Development Companies 2024Top Mobile App Development Companies 2024
Top Mobile App Development Companies 2024
 
A Comprehensive Appium Guide for Hybrid App Automation Testing.pdf
A Comprehensive Appium Guide for Hybrid App Automation Testing.pdfA Comprehensive Appium Guide for Hybrid App Automation Testing.pdf
A Comprehensive Appium Guide for Hybrid App Automation Testing.pdf
 
Secure Software Ecosystem Teqnation 2024
Secure Software Ecosystem Teqnation 2024Secure Software Ecosystem Teqnation 2024
Secure Software Ecosystem Teqnation 2024
 
Entropy, Software Quality, and Innovation (presented at Princeton Plasma Phys...
Entropy, Software Quality, and Innovation (presented at Princeton Plasma Phys...Entropy, Software Quality, and Innovation (presented at Princeton Plasma Phys...
Entropy, Software Quality, and Innovation (presented at Princeton Plasma Phys...
 
CompTIA Security+ (Study Notes) for cs.pdf
CompTIA Security+ (Study Notes) for cs.pdfCompTIA Security+ (Study Notes) for cs.pdf
CompTIA Security+ (Study Notes) for cs.pdf
 
KLARNA - Language Models and Knowledge Graphs: A Systems Approach
KLARNA -  Language Models and Knowledge Graphs: A Systems ApproachKLARNA -  Language Models and Knowledge Graphs: A Systems Approach
KLARNA - Language Models and Knowledge Graphs: A Systems Approach
 
Implementing KPIs and Right Metrics for Agile Delivery Teams.pdf
Implementing KPIs and Right Metrics for Agile Delivery Teams.pdfImplementing KPIs and Right Metrics for Agile Delivery Teams.pdf
Implementing KPIs and Right Metrics for Agile Delivery Teams.pdf
 
Abortion ^Clinic ^%[+971588192166''] Abortion Pill Al Ain (?@?) Abortion Pill...
Abortion ^Clinic ^%[+971588192166''] Abortion Pill Al Ain (?@?) Abortion Pill...Abortion ^Clinic ^%[+971588192166''] Abortion Pill Al Ain (?@?) Abortion Pill...
Abortion ^Clinic ^%[+971588192166''] Abortion Pill Al Ain (?@?) Abortion Pill...
 
Workforce Efficiency with Employee Time Tracking Software.pdf
Workforce Efficiency with Employee Time Tracking Software.pdfWorkforce Efficiency with Employee Time Tracking Software.pdf
Workforce Efficiency with Employee Time Tracking Software.pdf
 
StrimziCon 2024 - Transition to Apache Kafka on Kubernetes with Strimzi.pdf
StrimziCon 2024 - Transition to Apache Kafka on Kubernetes with Strimzi.pdfStrimziCon 2024 - Transition to Apache Kafka on Kubernetes with Strimzi.pdf
StrimziCon 2024 - Transition to Apache Kafka on Kubernetes with Strimzi.pdf
 
how-to-download-files-safely-from-the-internet.pdf
how-to-download-files-safely-from-the-internet.pdfhow-to-download-files-safely-from-the-internet.pdf
how-to-download-files-safely-from-the-internet.pdf
 
AI/ML Infra Meetup | ML explainability in Michelangelo
AI/ML Infra Meetup | ML explainability in MichelangeloAI/ML Infra Meetup | ML explainability in Michelangelo
AI/ML Infra Meetup | ML explainability in Michelangelo
 

On Growth and Software

  • 1. Carlo Pescio @CarloPescio http://physicsofsoftware.com Carlo Pescio On Growth and Software (or: applying some Physics of Software)
  • 2. Carlo Pescio @CarloPescio http://physicsofsoftware.com Inspired by a classic
  • 3. Carlo Pescio @CarloPescio http://physicsofsoftware.com Form as a Diagram of Forces
  • 4. Carlo Pescio @CarloPescio http://physicsofsoftware.com Form as a Recipe for Reaction My own little step – don’t blame D’Arcy  Material and shape encode reactions to “forces”
  • 5. Carlo Pescio @CarloPescio http://physicsofsoftware.com Form as a Recipe for Growth
  • 6. Carlo Pescio @CarloPescio http://physicsofsoftware.com Good ol’ book + - U U
  • 7. Carlo Pescio @CarloPescio http://physicsofsoftware.com The ring binder U D D U U C C
  • 8. Carlo Pescio @CarloPescio http://physicsofsoftware.com Growth Model
  • 9. Carlo Pescio @CarloPescio http://physicsofsoftware.com Growth Model
  • 10. Carlo Pescio @CarloPescio http://physicsofsoftware.com [Mis]Aligned Growth Model (ideal) growth in decision space (actual) growth in artifact space
  • 11. Carlo Pescio @CarloPescio http://physicsofsoftware.com “Growth” in computing Extensibility Scalability C/D features in code C/D run-time load Code as artifacts Run-time behavior C/D feature -> C/D load -> C/D artifact C/D machines / CPU
  • 12. Carlo Pescio @CarloPescio http://physicsofsoftware.com
  • 13. Carlo Pescio @CarloPescio http://physicsofsoftware.com Extensibility?
  • 14. Carlo Pescio @CarloPescio http://physicsofsoftware.com Symmetry in Growth [model] Create feature Delete feature decision space Create artifacts Delete artifacts artifact space
  • 15. Carlo Pescio @CarloPescio http://physicsofsoftware.com Why bother??? - Product families - Plug-in architectures, 3rd party modules - Modular understanding - “zero impact” evolution
  • 16. Carlo Pescio @CarloPescio http://physicsofsoftware.com In practice? A simple, specific problem with a specific growth model. Lessons here apply to similar growth models. Not everything will / should follow this model. The final shape is not universal the method of investigation kinda is
  • 17. Carlo Pescio @CarloPescio http://physicsofsoftware.com Easy
  • 18. Carlo Pescio @CarloPescio http://physicsofsoftware.com Some physics required 
  • 19. Carlo Pescio @CarloPescio http://physicsofsoftware.com Vector drawing for dummies
  • 20. Carlo Pescio @CarloPescio http://physicsofsoftware.com Growth Model - New shape types will come over time - New behaviors will come over time - Behaviors can be composed out of a fixed core - That entire menu only requires {bounding box, move} I’m dealing only with geometry right now
  • 21. Carlo Pescio @CarloPescio http://physicsofsoftware.com Context We have an open, discrete set of “concepts” { Square, Triangle, Circle, … } It’s open and so will grow by addition. T3 T2 T1 + + T = { Ti }
  • 22. Carlo Pescio @CarloPescio http://physicsofsoftware.com In code? How do we mirror in code? • N types: OK • N classes: OK • N objects / prototypes: OK • through closures / records of functions: ok as well • Case classes: Maybe • 1 sum type: NO + T = { Ti }
  • 23. N trivial classes (Scala) class Point( var x : Float, var y : Float ) {} class Box( var topLeft : Point, var bottomRight : Point ) {} class Circle( var center : Point, var radius : Float ) {} class Square( var topLeft : Point, var side : Float ) {} +
  • 24. 1 sum type (Haskell): nope type Point = (Float,Float) type Radius = Float type Side = Float data Shape = Circle Point Radius | Square Point Side + U
  • 25. Carlo Pescio @CarloPescio http://physicsofsoftware.com Context We have a closed set of “core behaviors” { BoundingBox, Move, Scale, Rotate, Mirror } ^ H = { Hi }H
  • 26. Carlo Pescio @CarloPescio http://physicsofsoftware.com Context “Core behaviors” depends on concepts. More precisely: when we create/delete a concept, we create/delete its implementation of core behaviors. ^ Ti C/D > HTi T3 T2 T1 + HT3 HT2 HT1 +
  • 27. Carlo Pescio @CarloPescio http://physicsofsoftware.com In code? How do we mirror • Member functions (class, objects): ok • Functions (+ optional overloading): ok • 1 function per behavior + pattern matching: NO • That removes case classes from the table ^ Ti C/D > HTi
  • 28. Case classes (Scala): nope abstract class Shape case class Circle(center:Point, radius:Float) extends Shape case class Square(topLeft:Point, side:Float) extends Shape + U object moveTool { def move( sh : Shape, newCenter : Point ) : Shape = { sh match { case Circle(center, radius) => new Circle( newCenter, radius); case Square( topLeft, side) => new Square(Point(topLeft.x-side/2, topLeft.y-side/2), side); } } }
  • 29. Carlo Pescio @CarloPescio http://physicsofsoftware.com Context We can: a) create instances of those concepts and keep them available for selection b) select some of those instances (mixed concepts) from a bounding box c) apply composite behaviors to those (mixed) instances
  • 30. Carlo Pescio @CarloPescio http://physicsofsoftware.com Context a) We want to create instances and keep them “available” for selection In code: • A single collection: OK • A collection for each type: OK A collection for each type is ok, as we still transfer creation (of concept) into creation (of a new list).
  • 31. Carlo Pescio @CarloPescio http://physicsofsoftware.com Context b) We want to select a (mixed) subset by dragging a selection box. So we need a selection function looping over all the available shapes and checking their bounding boxes (BB is a “core behavior” for shapes).
  • 32. Carlo Pescio @CarloPescio http://physicsofsoftware.com selection box f selection 1 collection per type won’t work anymore + + U Same reasoning applies to any of the composite behaviors shapes selected shapes
  • 33. Carlo Pescio @CarloPescio http://physicsofsoftware.com Context We have an open set of “composite behaviors” + B = { Bi } e.g. { align left, distribute horizontally, flip vertical} They operate on collections of concepts (instances). ^ Bi ≡ ·(H)
  • 34. Carlo Pescio @CarloPescio http://physicsofsoftware.com Context + T = { Ti } * + B = { Bi } ^ + (HTi) · C/D Two problems with Bi here: 1) Works on a set of shapes (same as selection) 2) Composed from a set of type-dependent core behaviors (same as selection w/ BB)
  • 35. Carlo Pescio @CarloPescio http://physicsofsoftware.com A single collection of shapes That would require either: • A dynamic language • mixing types is natural • A way to form a placeholder type as substitute for the individual types: • Base type + subtypes • Base class / interface + derived classes • [objects as] Records of closures • Existential types / Abstract types
  • 36. Carlo Pescio @CarloPescio http://physicsofsoftware.com Classes in Scala (easy) abstract class Shape { def explain() : String; def boundingBox() : Box; def moveCenter(newCenter:Point) : Shape; }
  • 37. Classes in Scala (easy) class Circle(private var center: Point, private var radius: Float) extends Shape { def explain(): String = { "circle " + center.x + " " + center.y + " " + radius; } def boundingBox(): Box = { new Box( Point(center.x-radius, center.y-radius), Point(center.x+radius, center.y+radius) ); } def moveCenter(newCenter: Point): Shape = { new Circle(newCenter, radius); } }
  • 38. Classes in Scala (easy) class Square(private var topLeft: Point, private var side: Float) extends Shape { def explain(): String = { "square " + topLeft.x + " " + topLeft.y + " " + side; } def boundingBox(): Box = { new Box( topLeft, Point(topLeft.x+side, topLeft.y+side)); } def moveCenter(newCenter: Point): Shape = { new Square(Point(topLeft.x-side/2, topLeft.y-side/2), side); } }
  • 39. Classes in Scala (easy) object MainObject { def main(args: Array[String]): Unit = { val c1 = new Circle( Point(1,1), 4 ) ; val s1 = new Square( Point(0,0), 4 ) ; val sh : List[Shape] = List( c1, s1 ); var d : String = sh.map( s => s.moveCenter(Point(5,5)).explain() ).reduce((s1,s2) => s1 + " ; " + s2) ; println( d ) ; } }
  • 40. Records of Closures (Haskell) type Point = (Float,Float) type Box = (Point,Point) data Shape = Shape { explain :: String, boundingBox :: Box, moveCenter :: Point -> Shape }
  • 41. Records of Closures (Haskell) circle :: Point -> Float -> Shape circle (x,y) r = Shape explain boundingBox moveCenter where explain = "circle " ++ show x ++ " " ++ show y ++ " " ++ show r boundingBox = ( (x-r, y-r), (x+r, y+r) ) moveCenter (x1,y1) = circle (x1, y1) r
  • 42. Records of Closures (Haskell) square :: Point -> Float -> Shape square (t,l) s = Shape explain boundingBox moveCenter where explain = "square " ++ show t ++ " " ++ show l ++ " " ++ show s boundingBox = ( (t, l), (t+s, l+s) ) moveCenter (x1,y1) = square (x1-s/2, y1-s/2) s
  • 43. Carlo Pescio @CarloPescio http://physicsofsoftware.com Records of Closures (Haskell) main = do let c1 = circle (1,1) 3 let s1 = square (1,1) 3 let sh = [ c1, s1 ] putStrLn (concat ( map (s -> (explain (moveCenter s (5,5))) ++ " ; ") sh ) )
  • 44. Existential type (Haskell) type Point = (Float,Float) type Box = (Point,Point) class ShapeTC a where explain :: a -> String boundingBox :: a -> Box moveCenter :: a -> Point -> Shape data Shape = forall a. ShapeTC a => Shape a instance ShapeTC Shape where explain (Shape shape) = explain shape boundingBox (Shape shape) = boundingBox shape moveCenter (Shape shape) = moveCenter shape
  • 45. Existential type (Haskell) data Circle = Circle Point Float instance ShapeTC Circle where explain (Circle (x,y) r ) = "circle " ++ show x ++ " " ++ show y ++ " " ++ show r boundingBox (Circle (x,y) r) = ( (x-r, y-r), (x+r, y+r) ) moveCenter (Circle (x,y) r) (x1,y1) = circle (x1, y1) r circle :: Point -> Float -> Shape circle (x,y) r = Shape (Circle (x,y) r)
  • 46. Existential type (Haskell) data Square = Square Point Float instance ShapeTC Square where explain (Square (t,l) s) = "square " ++ show t ++ " " ++ show l ++ " " ++ show s boundingBox (Square (t,l) s) = ( (t, l), (t+s, l+s) ) moveCenter (Square (t,l) s) (x1,y1) = square (x1-s/2, y1-s/2) s square :: Point -> Float -> Shape square (t,l) s = Shape (Square (t,l) s)
  • 47. Existential type (Haskell) main = do let c1 = circle (2,2) 3 let s1 = square (2,2) 3 let sh = [ c1, s1 ] putStrLn (concat ( map (s -> (explain (moveCenter s (6,6))) ++ " ; ") sh ) )
  • 51. Carlo Pescio @CarloPescio http://physicsofsoftware.com Work in progress ^ Ha = { Hi } + T = { Ti } * + B = { Bi } ^ + HTi · C/D ^ Ta + T = { Ti } * + B = { Bi } ^ + (HTi) · C/D
  • 52. Carlo Pescio @CarloPescio http://physicsofsoftware.com Every type has identity (to keep it simple: name) F knows identities in => F unstable So: - F should not know identities in - F needs to operate on values of those types. => F must be isolated from type identity. Identity and Isolation + T + T
  • 53. Carlo Pescio @CarloPescio http://physicsofsoftware.com Common techniques for isolation: - Add a new “abstract type” Ta, make every Ti an instance or subtype of Ta - Requires late binding as F will only know Ta - Relationship between Ti and Ta can be implicit (structural conformance) - Add a new concrete type Tc exposing only functions, and bind every instance of Ti to an instance of Tc - That’s again providing late binding as F won’t know the identity of the functions it’s calling Isolation Techniques
  • 54. Carlo Pescio @CarloPescio http://physicsofsoftware.com structures vs paradigms
  • 55. Carlo Pescio @CarloPescio http://physicsofsoftware.com OO SUCKS!
  • 56. Carlo Pescio @CarloPescio http://physicsofsoftware.com Get your trick question ready 1. The next time someone shows you a decent use for OO-like polymorphism & encapsulation, what can you say? what about serialization in multiple formats?
  • 57. Carlo Pescio @CarloPescio http://physicsofsoftware.com Remember this?
  • 58. Carlo Pescio @CarloPescio http://physicsofsoftware.com Elastic yet bent !?
  • 59. Carlo Pescio @CarloPescio http://physicsofsoftware.com We only have geometry so far I want rendering (new core behaviors!) I may want only geometry I may want only rendering I may want both => Geometry and Rendering in distinct artifacts Breaking the growth model
  • 60.
  • 61. Carlo Pescio @CarloPescio http://physicsofsoftware.com Growing and Breaking
  • 62. partial class Circle { private readonly Point center; private readonly double radius; public Circle( Point center, double radius ) { this.center = center; this.radius = radius; } } interface Shape { Shape Move(Point newCenter); } partial class Circle : Shape { public Shape Move(Point newCenter) { return new Circle(newCenter, radius); } } interface Drawing { void Render(); } partial class Circle : Drawing { public void Render() { Console.WriteLine( "I'm a Circle with radius " + radius.ToString()); } } static void Main(string[] args) { Shape c = new Circle(new Point(10, 10), 5); Drawing d = c as Drawing; d.Render(); } constraint Shape => Drawing
  • 63. Carlo Pescio @CarloPescio http://physicsofsoftware.com “Design Process” I didn’t use - Design principles - Patterns - Tests - Religion I only aimed for symmetry - Features growth model - Artifacts growth model Break a symmetry to get a symmetry 
  • 64. Carlo Pescio @CarloPescio http://physicsofsoftware.com …Monads  Or polymorphism Or existential types Or type system constraints Or many things yet to be invented Just by understanding forces  You may have invented…
  • 65. Carlo Pescio @CarloPescio http://physicsofsoftware.com Get in touch @CarloPescio carlo.pescio@gmail.com http://physicsofsoftware.com /forum