The Buggy Way of Programming

Rasmus Buchmann & Maximilian Klein

What are these talks about

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

Programming usually is

Structure

Creativity!

Creativity

Is Programming a creative task?

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

Implementations differ


A question of taste... (no right or wrong)
Creativity

Creativity is bad for Programming ?

Creativity

No!

Creativity

No!

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
http://www.naturalranks.co.uk/2014/03/how-google-works/

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"
  }
}

So, make it possible!

Creativity

Well...
There is still a problem

How to communicate semantics!... That's hard!

Reusability!

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

Reusability

The Library Problem

We want semantical dependence!
Reusability

Why semantical dependence?

Everybody should be responsible for what he is best at!

Simplicity!

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!

Simplicity

Solutions?

Simplicity

NO LOCKS!

Simplicity

NO LOCKS!
No!

Simplicity

NO LOCKS!
No!No!No!

Simplicity

NO LOCKS!
No!No!No!No!No!

Simplicity

Use Values

Simplicity

Use Values

Immutability is key!

To be continued...

Thank you for your attention!


Next presentation: 8 May, 16:15, here

Topic: Out of the Tar Pit