Out of the Tar Pit

Rasmus Buchmann & Maximilian Klein

Last Talk

We want to write
Programs

Biggest Obstacle?

Biggest Obstacle?

Stuff doesn't work ™

Biggest Obstacle?

Stuff doesn't work ™

The question is: Why?

"Out of the Tar Pit"

One cannot hope to develop, maintain or improve a large program if one is unable to understand it

Understanding the Tar Pit

Reasons

Understanding the Tar Pit

Focus

Complexity

Understanding the Tar Pit

State

Have you tried turning it off and on again?

When [programmers] encounter complexity, they consider it a challenge to overcome, rather than an obstacle to remove. Overcoming complexity isn't work, it's waste.
Rich Hickey, Inventor of Clojure
Understanding the Tar Pit

Example

      
std::string WhatDoIDo?(const std::vector & dirs , char separator) {
  std::vector::const_iterator vsi = dirs.begin();
  int mCC = vsi->length();
  std::string compareString = *vsi;
  for (vsi = dirs.begin() + 1; vsi != dirs.end(); vsi++) {
    std::pair p =
      std::mismatch(compareString.begin(), compareString.end(), vsi->begin());
     if ((p.first - compareString.begin()) < mCC)
       mCC = p.first - compareString.begin();
  }
  std::string::size_type found = compareString.rfind(separator, mCC);
  return compareString.substr(0 , found);
}
  
Understanding the Tar Pit

Keep in mind

Understanding the Tar Pit

Keep in mind

Templates?
Understanding the Tar Pit

Keep in mind

Templates?
Operator precedence?
Understanding the Tar Pit

Keep in mind

Templates?
Operator precedence?
Implicit Casts?
Understanding the Tar Pit

Keep in mind

Templates?
Operator precedence?
Implicit Casts?
Copy constructors?
Understanding the Tar Pit

Keep in mind

Templates?
Operator precedence?
Implicit Casts?
Copy constructors?
Ownership?
Understanding the Tar Pit

Keep in mind

Templates?
Operator precedence?
Implicit Casts?
Copy constructors?
Ownership?
Pre- or Postincrement?
Understanding the Tar Pit

Keep in mind

Templates?
Operator precedence?
Implicit Casts?
Copy constructors?
Ownership?
Pre- or Postincrement?
Exceptionsafe?
Understanding the Tar Pit

Attention is limited

Understanding the Tar Pit

Simple Example

Understanding the Tar Pit

Why is that a problem?

Programming is hard, right?

Understanding the Tar Pit

Why is that a problem?

None of this complexity comes from the task we want to solve!

Understanding the Tar Pit

Traditional solutions

Understanding the Tar Pit

Traditional problems

"I invented the term Object-Oriented and I can tell you I did not have C++ in mind."
Alan Kay, inventor of Smalltalk

What can we do?

Some suggestions

Most important: Learn your stuff, think about solutions

The right tool

Choose the right language/paradigm!

Prerequisite:

Know more than one...

New languages?

Stevey's Blog Rants

Haskell Researchers Announce Discovery of Industry Programmer Who Gives a Sh*t

[...] Programming languages are not merely technologies, but habits of mind as well, and nothing changes slower
Paul Graham, Lisp programmer and writer
Viaweb anecdote
The right tool

Sapir-Whorf

Well designed languages introduce new concepts and ways to think about programs

The right tool

Even if you're not going to use them directly!

The right tool

Some suggestions

Every sufficiently advanced program includes an ad-hoc, informally specified, slow, bug-ridden implementation of half of Common Lisp
Greenspun's tenth rule
The right tool

Lisp

The right tool

Python

The right tool

Haskell

The right tool

Erlang

The right tool

Others

The right tool

Summary

Invent new ways to avoid problems rather than new hacks to work around them

The right tool

Summary

Work towards writing declarative programs, rather than imperative

The right tool

Systems everywhere

Usually never writing an isolated program - heterogenity

Correctness over performance

Premature optimization is the root of all evil.
Donald Knuth, no introduction needed
Correctness over performance

Example: Locks

Alternatives: STM, Erlang style message passing, etc... Not as efficient, but:

Correctness over performance

Example: Locks

Correctness over performance

Rule of thumb

Optimize at the very last step, it will frequently be unnecessary

Correctness over performance

Even Better

Why should you be concerned with performance at all?

Data is Data is Data

Data is Data

...is not an Object!

Don't wrap what is essentially data in a class!

Data is Data

Use Data to

Talk about point classes in topology lib
Data is Data

Immutable Data

Simple isn't easy

Simple isn't easy

Two meanings

Further Reading/Watching/Fun

Thank you for your attention!


Next presentation: 15 May, 17:00, here

Topic:Bret!