A neat thing and the mess we're in

A neat thing

I made it up to chapter 8 in Programming Erlang, and I had a lot of fun learning about the term->binary functionality. In fact, when I wrote the below, I think I actually said "this is so cool!" out loud.

%% lib_misc.erl
stash_term(Path, Term) ->
    file:write_file(Path, erlang:term_to_binary(Term)).

retrieve_term(Path) ->
    case file:read_file(Path) of
        {ok, BinaryTerm} ->
        {error, Reason} -> throw({read_file, Reason})
$ erl
Erlang/OTP 21 [erts-10.2.4] [64-bit] [smp:1:1] [ds:1:1:10] [async-threads:1]

Eshell V10.2.4  (abort with ^G)
1> c(lib_misc).
2> F = fun (X) -> X * X end .
3> lib_misc:stash_term("square.bin", F).
User switch command
 --> q
$ erl
Erlang/OTP 21 [erts-10.2.4] [64-bit] [smp:1:1] [ds:1:1:10] [async-threads:1]

Eshell V10.2.4  (abort with ^G)
1> c(lib_misc).
2> F = lib_misc:retrieve_term("square.bin").
3> F(2).

You can convert Funs to binary, save them to disk, and restore them later... now I kind of want to play with the idea of the universal function store.

It gets cooler, too. I decided to play around with scoping, and it turns out it will pull in some of the dependencies it requires. So, for example,

> ScaleFactor = 2.
> Square = fun (X) -> X * X end.
> Scale = fun (X) -> X * ScaleFactor end.
> ScaledSquare = fun (X) -> Square(Scale(X)) end.
> c(lib_misc).
> lib_misc:stash_term("scaled_square.bin", ScaledSquare).

Retreiving this term works nearly exactly as expected, and I think the impedence mismatch is really just because I don't yet fully understand the difference between Funs and compiled forms. That this works as well as it does is kind of a delightful surprise. For grins, I tried this in Python using pickle and a lambda, and of course it doesn't work. I want to spend some time reading up on the external term format.

Watching "the mess we're in," which I'll write up below, I learned about the Erlang crypto module, so we can apply that to the binary-encoded fun and start building the universal function feature.

The mess we're in

I was rewatching "the mess we're in" over lunch, and these are some notes on it. I'll try to go back later and clean them up.

The Seven Deadly Sins of software:

  1. Code even you cannot understand a week after you wrote it - no comments.
  2. Code with no specifications.
  3. Code that is shipped as soon as it runs and before it is beautiful.
  4. Code with added features.
  5. Code that is very very faste very very very obscure and incorrect.
  6. Code that is not beautiful.
  7. Code that you wrote without understanding the problem.

Six 32-bit integers have more possible states than the number of atoms on the planet.

Computers are finite state machines. But how many states has it got?

  • State x Event -> NewEvent.

Systems should self-repair, self-configure, and evolve with time.

Writing an Erlang program for embedded required bitbake - download 46k files over several hours.

"Without an Internet Connection I cannot program" is a sad state of affairs.

Dichotomy between efficiency and clarity:

  • To make something clearer, we add a layer of abstraction BUT
  • To make something more efficient, we remove a layer of abstraction.

We don't know that something has happened until we get a message saying that the event has happened.

Quantum mechanics is fun

  • Bremmermann's limit
  • Margolus-Levitin theorem
  • Bekenstein bound
  • Laundauer limit
  • Ultimate physical limits to computation

The entropy reverser

  • Entropy increases the number of files
  • Files mutate, disks are huge
  • What name should a file have
  • Which directory to store the file in
  • What machine should that directory be stored on?
  • How will I find the file later?
  • How can I replicate the file?

How to make the condensor

  • Find all identical files
  • Merge all similar files

Names lets us talk about things.

A little helper

  • Like twitter: get a text box
  • Posting searches, answers questions
    • Is this a new idea?
    • Is this an idea I've had before and just forgotten about?
    • Is this an idea that someone else has had?

Least compression distance algorithm

Computing is about controlling complexity and we have failed miserably at this. 128K is probably about the limit of what the human brain can understand.

Lower power computers so we don't destroy the planet! Computers are using more energy than air traffic, we can make them lower power.