The Buggy Way of Programming
Rasmus Buchmann & Maximilian Klein
What are these talks about
- Different ways of programming
- No persuasion to change
- Provocation!
Once you think you know what you are doing you stop looking around for other things [...]
you become blind
Bret Victor in The Future of Programming
Programming should be
- Fun!
- Creative
- About getting ideas into programs
- A tool that helps people
Programming usually is
- Not so much fun!
- Not so creative
- about getting bugs out of programs
- a tool that will annoy you!
Structure
- Creativity
- Reusability
- Simplicity
Creativity
Is Programming a creative task?
- Programming is full of choices
- Is there the one right way?
- Or can we be creative?
Creativity
The Shoe Analog
Creativity
A Shoe should be
Breathable
Creativity
A Shoe should be
Robust
Breathable
Creativity
A Shoe should be
Comfortable
Robust
Breathable
Creativity
A Shoe should be
Good Fitting
Comfortable
Robust
Breathable
Creativity
A Shoe should be
Foot Shaped
Good Fitting
Comfortable
Robust
Breathable
Creativity
A Shoe should be
Weather-proof
Foot Shaped
Good Fitting
Comfortable
Robust
Breathable
Creativity
Implementations differ
Creativity
Creativity is bad for Programming ?
- Libraries must have well defined interfaces
- You cannot use APIs without learning those interfaces
Creativity
No!
- Creativity is vital!
- But it conflicts...
Creativity
No!
- Creativity is vital!
- But it conflicts... all the time
Creativity
Simple example
grp = createGroup(rgb(0,0,150));
grp.addTextParagraph("Lorem Ipsum...", rgb(0,0,0));
innerGrp = grp.createGroup(rgb(200,0,0));
innerGrp.drawCenteredText("Hello World", rgb(204,203,10));
Creativity
Simple example
grp = createGroup(rgb(0,0,150));
grp.addTextParagraph("Lorem Ipsum...", rgb(0,0,0));
innerGrp = grp.createGroup(rgb(200,0,0));
innerGrp.drawCenteredText("Hello World", rgb(204,203,10));
Why is this code bad for creativity?
Creativity
Simple example
grp = createGroup(rgb(0,0,150));
grp.addTextParagraph("Lorem Ipsum...", rgb(0,0,0));
innerGrp = grp.createGroup(rgb(200,0,0));
innerGrp.drawCenteredText("Hello World", rgb(204,203,10));
Why is this code bad for creativity?
Nobody else can work with the content!
Simple example 2
content = "<div>Lorem Ipsum .... \
<div><center>Hello World</center></div>";
HTMLRenderer.render(content);
Simple example 2
content = "<div>Lorem Ipsum .... \
<div><center>Hello World</center></div>";
HTMLRenderer.render(content);
You can simply work with the content in any way you want
Simple example 2
content = "<div>Lorem Ipsum .... \
<div><center>Hello World</center></div>";
HTMLRenderer.render(content);
You can simply work with the content in any way you want
(even in a way that wasn't intended)
Possible due to the simple/open HTML format
Google would be impossible when...
the web would be a thin-client system!
Google is possible as...
the web is based on data!
Google is possible as...
the web is open!
Google is possible as...
the web allows for creativity!
Creativity
What is Important?
No unnecessary information hiding
Creativity
It is possible to work with Metadata
{
"Translation" : [1,4,0],
"Rotation" : [0.4,1,0,0],
"Metadata" : {
"RotationType" : "Quaternion",
"TranslationUnit" : "Centimeter"
}
}
Creativity
Well...
There is still a problem
How to communicate semantics!... That's hard!
Reusability
The Library Problem
Reusability
The Library Problem
Reusability
The Library Problem
Reusability
The Library Problem
Reusability
The Library Problem
*!#"+*!#$§ !
Reusability
In reality there is no LibAnything
Reusability
The Injection Problem
Reusability
The Injection Problem
Usually interactions are not that simple...
Reusability
The Injection Problem
Libraries introduce custom types...
Reusability
The Injection Problem
Which are used everywhere in MyProgram...
Reusability
The Injection Problem
QMatrix3x3 rotation = ...;
Eigen::Matrix3D eigenRotation;
for(int i=0; i < 9; i++){
eigenRotation[i] = rotation[i%3][i/3];
}
Who doesn't like this?
Reusability
The Dependency Problem
Or we use only a subset of the features..
Reusability
The Dependency Problem
But we are (indirectly) dependent on all features...
And they can have further dependencies...
Reusability
The Dependency Problem
And sometimes you have to fix problems that are / might be irrelevant for you..
Reusability
The Semantic Issue
Two function calls with different names...
Reusability
The Semantic Issue
LibAnything decides to rename the functions...
Reusability
The Library Problem
- Strong dependence (e.g. through type injection)
- Mostly syntactical dependence
Reusability
The Library Problem
- Strong dependence (e.g. through type injection)
- Mostly syntactical dependence
We want semantical dependence!
Reusability
Why semantical dependence?
- We know what we want!
- Others are usually experts in the technical details
Everybody should be responsible for what he is best at!
Simplicity
What's wrong
public int getNextUniqueID(){
uniqueIdCounter = uniqueIdCounter + 1;
return uniqueIdCounter;
}
Simplicity
What's wrong
public int getNextUniqueID(){
uniqueIdCounter = uniqueIdCounter + 1;
return uniqueIdCounter;
}
It's impossible to find an error
... without knowing the semantics
Simplicity
But more important!
Even with semantics.. it is impossible to validate it's correctness..
(with the limited knowledge of the whole program)
Simplicity
That's sad
Two lines.. and we cannot say if the function works correctly
Simplicity
Let's look at another example
class Counter{
private int cnt = 0;
public void increment(){
cnt = cnt + 1;
}
public void decrement(){
cnt = cnt - 1;
}
public int getCount(){
return cnt;
}
}
Simplicity
Let's look at another example
class Counter{
private int cnt = 0;
public void increment(){
cnt = cnt + 1;
}
public void decrement(){
cnt = cnt - 1;
}
public int getCount(){
return cnt;
}
}
Okay we have a limited scope
Simplicity
Let's look at another example
class Counter{
private int cnt = 0;
public void increment(){
cnt = cnt + 1;
}
public void decrement(){
cnt = cnt - 1;
}
public int getCount(){
return cnt;
}
}
Okay we have a limited scope (Check!)
Simplicity
But you can break it!
Simplicity
But you can break it!
With Multithreading!
Simplicity
But you can break it!
- Simply create two threads.
- is constantly incrementing values
- is constantly decrementing values
Simplicity
NO LOCKS!
No!No!No!
Simplicity
NO LOCKS!
No!No!No!No!No!
Simplicity
Use Values
Immutability is key!
Thank you for your attention!
Next presentation: 8 May, 16:15, here
Topic: Out of the Tar Pit