Showing posts with label summary. Show all posts
Showing posts with label summary. Show all posts

Thursday, December 30, 2010

Review of Crafting Rails Applications, by José Valim

José Valim is one of the newest members of the Rails core team. Apart from this he has also developed some good gems, Devise, Responders, and SimpleForm, that I use for almost every project.

And now he has written a book, a really good book, about advanced Rails programming techniques, called Crafting Rails Applications.

The book is only 180 pages long, and contains 7 chapters. I wish more books was this thin. The books is written in a clear concise way. José's lightweight test-driven approach clearly introduces every problem it intends to solve, and then solves the problem by introducing a new concept in the Rails framework. Most of the solutions are only a few lines of code, showing the power of Rails and also showing the power of having intimate knowledge of the framework. By hooking into the framework at appropriate places, José is able to provide elegant solutions to a range of problems.

I highly recommend the book to anyone interested in Rails.

If this was an ordinary book, this review could have ended here, but since the book is full of things I really wanted to know but didn't take the time to learn I decided to internalize them by describing parts of the book in my own words.

Chapter 1, Creating our own renderer

In this chapter we learn how to add a new renderer Rails. We add a renderer that handles generating PDF files with Prawn, allowing us to write code that looks like this.

class HomeController < ApplicationController 
  def index
    respond_to do |format| 
      format.html
      # This is the new capability, pdf rendering.
      format.pdf { render :pdf => "contents" }
    end 
  end
end

To allow the following we first have to register pdf as a mime type. We can do this with:

require "action_controller"
# Register a new mime type
Mime::Type.register "application/pdf", :pdf

# Registering the type allows us to write
respond_to do |format|
  format.pdf
end

With that out of the way all we have to do is to register a renderer, that will handle the actual rendering of the registered mime type. This is done with:

require "prawn" 

# Adds a new renderer to ActionController.Renderers
ActionController::Renderers.add :pdf do |filename, options|
  pdf = Prawn::Document.new pdf.text render_to_string(options) 
  send_data(pdf.render, :filename => "#{filename}.pdf",
      :type => "application/pdf", :disposition => "attachment")
end

This is all that is needed to add a rendering of a new type to Rails. José also goes into details about other points of interest where the rendering stack can be customized.

Chapter 2, Easy models with Active Model

Active Model is a Rails module that abstracts common behavior needed by different kinds om models such as Active Record, Active Resource and third party modules like Mongoid. Apart from giving developers of new models utility functionality. Active Model also provides tests for being Active Model compliant. To be compliant means to play well with the Rails view and controllers.

José implements a model for creating sending mail. In doing so he introduces us to a bunch of Active Model modules that will do our work for us.

Here are the modules in alphabetical order:

ActiveModel::AttributeMethods

When you include ActiveModel::AttributeMethods in your model, you get access to helper methods that will help you define additional methods for dealing with the attributes of your model. An example

class Tapir
  include ActiveModel::AttributeMethods
   
  # Define the attributes 
  attr_accessor 'name', 'color'

  # We want to create clear methods for every attribute
  attribute_method_prefix 'clear_'

  # We also want to have query methods for every attribute
  attribute_method_suffix '?'

  # Define the attribute methods that will call the protected methods below
  define_attribute_methods ['name', 'color']

protected
  # The name of this method corresponds to the prefix above
  def clear_attribute(attribute)
    send("#{attribute}=", nil)
  end

  # The name of this method corresponds to the suffix above
  def attribute?(attribute)
    send(attribute).present?
  end
end

   t = Tapir.new
 => #<Tapir:0x00000102769b90> 
> t.name?
 => false 
> t.name= 'kalle'
 => "kalle" 
> t.name?
 => true 
> t.clear_name
 => nil 
> t.name?
 => false 
> t.name

This is the gist of attribute methods, there is also an affix method that will allow you to add both a suffix and a prefix to your attributes. It is also worth taking a look inside the implmentation of this module, since the methods are defined on first usage through method_missing.

ActiveModel::Callbacks

ActiveModel::Callbacks provides methods for creating before_, after_, and `around_' callbacks to your model methods. An example:

class Tapir
  extend ActiveModel::Callbacks

  define_model_callbacks :snort

  def snort
    _run_snort_callbacks do
      snort_snort_snort
    end
  end

end

Then in inheriting classes I can use the callbacks as such:

class MountainTapir < Tapir
  before_snort :do_before_snort

  def before_snort
    i_am_so_cold
  end
end

ActiveModel::Conversion

This module assists with converting to, and representing a specific model instance. It contains three methods.

  • to_model, used for converting to an active model compliant model, in the default case it just returns self.
  • to_param, used for representing a model in routing.
  • to_key, used for representing a model from in a dom page.

ActiveModel::Naming and ActiveModel::Translation

ActiveModel::Naming contains one method model_name, that returns a subclass of String, that handles pluralization, etc. It has methods such as plural, human.

ActiveModel::Translation deals with I18N by adding functionality to human that handles the name lookup by keys using the preferred I18n.backend.

ActiveModel::Validations

The last, but not least of the models, ActiveModel::Validations, deals with validations. José demostrates how naming convetions and Rails constant lookup allow us to add new validators to Rails with ease. An example:

module Validators
  class TapirKindValidator < ActiveModel::EachValidator 
    def validate_each(record, attribute, value)
      unless [:baird, :mountain, :malayan, :lowland].include? value
        record.errors.add(attribute, :invalid, options) 
      end
    end
  end
end


If I now include my new validator wherever I want to use it. I can write code like:

class Tapir
  include Validators
  
  attr_accessor :kind
  validates :kind, :tapir_kind => true
end

t = Tapir.new :kind => :mexican
t.valid? 
# => false
t.errors[:kind] 
# ["is invalid"]


This example is unnecessarily complicated, since the validation could be fixed with:

class Tapir
    attr_accessor :kind
    validates_inclusion_of :kind, :in =>  [:baird, :mountain, :malayan, :lowland]
end

append_view_path

There is one more interesting thing in this chapter, append_view_path. It can be used to add a directory inside a gem to the view lookup path. This is essential to be able to deliver custom Rails components, Railties, with default views.

Chapter 3, Building a template management system

In the third chapter of the book,José takes on view resolvers. A resolver is responsible for looking up the appropriate template for a given request. The traditional resolver looks up the templates by path in the file system, but José guides us through creating a resolver that looks up the template in a database. Perfect for the core of a CMS system. I'm going to alter José's resolver to do the lookup in MongoDB instead.

# Most of this code is borrowed directly from Jos&eacute; Valim
# Only the Mongoid Part is written by me :)
require 'mongoid'
require 'singleton'

class MongoTemplate
  include Mongoid::Document
  field :body
  field :path
  field :locale
  field :format
  field :handler
  field :partial, :type => Boolean
  field :updated_at, :type => Date
    
  validates :body, :path, :presence => true
  validates :format, :inclusion => Mime::SET.symbols.map(&:to_s) 
  validates :locale, :inclusion => I18n.available_locales.map(&:to_s) 
  validates :handler, :inclusion => 
    ActionView::Template::Handlers.extensions.map(&:to_s)

  class Resolver < ActionView::Resolver 
    include Singleton
  protected
    def find_templates(name, prefix, partial, details)
      conditions = {
        :path => normalize_path(name, prefix),
        :locale => normalize_array(details[:locale]).first, 
        :format => normalize_array(details[:formats]).first,
        :handler.in => normalize_array(details[:handlers]), 
        :partial => partial || false
      }
   
      MongoTemplate.where(conditions).map do |record| 
        initialize_template(record)
      end 
    end
    
    # Normalize name and prefix, so the tuple ["index", "users"] becomes 
    # "users/index" and the tuple ["template", nil] becomes "template". 
    def normalize_path(name, prefix)
      prefix.present? ? "#{prefix}/#{name}" : name
    end
   
    # Normalize arrays by converting all symbols to strings.
    def normalize_array(array)
      array.map(&:to_s)
    end

    # Initialize an ActionView::Template object based on the record found.
    def initialize_template(record) 
      source = record.body 
      identifier = "MongoTemplate - #{record.id} - #{record.path.inspect}" 
      handler = ActionView::Template.registered_template_handler(record.handler)
      details = { 
        :format => Mime[record.format], 
        :updated_at => record.updated_at, 
        :virtual_path => virtual_path(record.path, record.partial)
      }
      ActionView::Template.new(source, identifier, handler, details)
    end
    
    # Make paths as "users/user" become "users/_user" for partials.
    def virtual_path(path, partial) 
      return path unless partial 
      if index = path.rindex("/")
        path.insert(index + 1, "_")
      else
        "_#{path}"
      end 
    end
  end
end

A Resolver is implemented by extending ActionView::Resolver and implementing the method find_templates(name, prefix, partial, details) There are a lot of extra information in the book, about caching etc. Obviously Rails caches the templates since it would be too slow to create a template every time. That is why we have the template as a singleton and that is why we clear the cache in the after_save hook above. The hook in Mongoid works exactly the same as in Active Record. Thank you Active Model!

Chapter 4, Multipart Emails with Markdown and Erb

In this chapter José walks us through three topics. The template handler API, Rails generators and Railties. I'm going to skip over the last two in this chapter. Generators are a large topic and they deserve a blog post of their own. José does a great job desribing how they work. The same goes for Railties and Rails Engines, they are definitely worthy of a blog post of their own.


# 
# Again most of the code is stolen from Jos&eacute; :)
#
module ScrambleHandler
  
  # Lookup the ERb handler
  def self.erb_handler
    @@erb_handler ||= ActionView::Template.registered_template_handler(:erb)
  end

  def self.call(template)
    # Call the erb handler, then call the new scrambler method.
    source = erb_handler.call(template)
    if template.formats.include?(:html)
      "Scrambler.from_html(begin;#{source};end).to_s"
    else
      "Scrambler.from_text(begin;#{source};end).to_s"
    end
  end

end

# Register our new handler, it handles index.html.scramble, show.html.scramble, ...
ActionView::Template.register_template_handler :scramble, ScrambleHandler

# This module scrambles text.
# Scrambler.from_text('Once upon a time a beautiful tapir came.')
# -> Ocne upon a time a baeuuitfl tpiar came.
module Scrambler
  def self.from_html html
    doc = Nokogiri::HTML(html) 
    doc.xpath('//text()').each do |node|
      node.content = from_text(node.content)
    end
    doc.to_html
  end

  def self.from_text text
    tokenize(text).map{|token| scramble(token)}.join('') 
  end

  def self.tokenize text
    return nil unless text
    text.scan(/(\p{Word}+|\W+|)/um).flatten
  end

  def self.scramble word
    return word if word =~ /\W/
    return word if word.size < 4
    arr = word.split(//)
    arr[0] + arr[1...-1].shuffle.join('') + arr[-1]
  end
end

Chapter 5, Publishing and subscribing to your applications events

In this chapter José uses the Notifications API to store notifcations in a MongoDB. He also shows how to use Rack middleware to configure what request to log. In order to configure the middleware he uses a Rails Engine. I'm just going to show how the Notifications API works here, and I'll let you read the rest in the book.

# Subscribe to all events and print them to the console
ActiveSupport::Notifications.subscribe do |*args|
  p ActiveSupport::Notifications::Event.new(*args)
end

# Instrument the rendering of Foo
ActiveSupport::Notifications.instrument(:render, :extra => :information) do
  render :text => "Foo"
end


Chapter 6, DRY controllers with Responders

In this chapter José goes through the implementation of responders. This implementation allows you to DRY up your controllers by factoring out common behavior.

def index
  @users = User.all
  respond_to do |format| 
    format.html # index.html.erb 
    format.xml { render :xml => @users }
  end
end

# becomes

def index 
  @users = User.all 
  respond_with(@users)
end


# and
def create 
  @user = User.new(params[:user])
  respond_to do |format| 
  if @user.save
    format.html { redirect_to(@user, :notice => 'User was successfully created.') }
    format.xml { render :xml => @user, :status => :created, :location => @user }
  else
    format.html { render :action => "new" } 
    format.xml { render :xml => @user.errors, :status => :unprocessable_entity }
  end 
end

# becomes
def create 
  @user = User.new(params[:user]) 
  flash[:notice] = 'User was successfully created.' if @user.save 
  respond_with(@user)
end

In this chapter we also learn how to replace the default generators with our own customized generators.

Chapter 7, Translatable app with I18n and Redis

In the final chapter José shows us how the I18N backed system works. He does this by creating a backend the uses Redis instead of the default YAML files. He also developes a simple Sinatra application that he hooks into the Rails routing with the mount method.

# Mount the Sinatra Translator::App at the /translator path.
mount Translator::App, :at => "/translator"

Rack applications normally get the full path inside ENV['PATH_INFO'], but when Rails mounts an application it removes the prefix before it sends it on /translator/en/pt/ becomes /en/pt/. The additional path is sent on in ENV['SCRIPT_NAME'] = '/translator'.

We also get a brief overview of Devise, the state-of-the-art authentication solution written by José himself.

Conclusion

One last thing, the book I have reviewed is a beta book, but the quality of it is higher than most published books I have seen. Congratulations to José and to the pragmatic bookshelf! There is not much more to say, get the book.

Tuesday, November 10, 2009

Adrenaline Junkies and Template Zombies

Since I had plenty of time to read on my flights back and forth to OOPSLA, I managed to read through a few books. One of them was Adrenaline Junkies and Template Zombies by Tom DeMarco et al. Being the sceptic that I am, my attitude when starting to read this book was: "Yeah, I know a lot of people has praised this book and I know that Tom DeMarco has written Peopleware, but what the hell do these bozos know anyway!" ;)

I figured that the six of them could probably scrape together a few decent people patterns, but I am a bit fed up with the whole pattern template style, so my expectations were not as high as they should have been.

Anyway, the book is amazing, the pattern template is really lightweight, basically, a name, an image, a statement, and a story. And the stories, are good. The authors have a remarkable ability to observe human nature and also the ability to write about what they see.

Some Patterns

The book contains 86 patterns, most of them are negative since they are funnier, as one of the authors said on a podcast.

Dead Fish

A dead fish is a project, that every one knows is impossible to start out with, but nobody says anything since the culture in the company is that way. If you say something you may get responses like,

Prove it! Prove that it is not feasible that this project will succeed!

Or,

Are you a weenie or a layabout?

Projects like this are usually worked on until it is inevitable that they will be late, and then everybody acts surprised.

Nanny

A nanny is a project manager that is aware of the capabilities of her staff and nurtures them and lets them at their peek. The nanny is responsible for improving her staff and make responsible project citizen of them. A nanny enables workers to do their job.

Eye Contact

If your life depended on a project, would you want them working close together or in different corners of the world? Human communication goes way beyond words, and it is foolish to think that it is possible to work at full speed with people who don't know each other and live in different places.

Dashboards

A dashboard is a highly visible board, that enable the project members and others to get an instant view of the status of the project. It can be a web page or a board on the wall. What is significant with a dashboard is that it is updated as soon as anything important happens in the project. All project members care for the dashboard since that is the place where they can find out how they are doing. Dashboards contain just the right amount of data.

Film Critics

A film critic is a project member or someone related to the project who thinks that they can succeed even if the project is a failure. They may often have good points, but usually when it is too late to do something about it. It is no use to have a person like this on the team, since they are not really on the team if they don't go down with the ship.

Natural Authority

The word authority have several meanings. The meaning of an authority is a person who knows a great deal about something. Another meaning, in authority, is a person who is in charge. A person who is an authority and in authority is a natural authority. This is the healthy pattern.

The White Line

The white line is the line on a tennis court. The line is a clear signal if the ball is in or out. Occasional dispute may arise over a questionable judgment call, but the line is respected by everyone. Most projects don't have this line. Create a white line for your project so that you know what is inside the project scope and what is not.

Silence Gives Consent

If someone don't oppose an idea, it is, usually, taken as consent. Especially from people who come from different working areas, like management and programmers. Silent consent is not good for anyone, because nobody is sure what has been decided and what has not. A way to remedy this problem is to keep a list of commitments where it is written down who has promised who what. The Scrum sprint backlog is similar to such a list.

Time Removes Cards from Your Hand

The earlier a decision can be made, the better. If you know that a project will not make a deadline, the decision to change the scope should be made as early as possible, since that will allow the team to work on the most important features first. If a decision is delayed until it is too late, the decision is made implicitly by time.

Rhythm

Instead of being daunted by overwhelming tasks, projects with rhythm take small, regular steps thus establishing a regular beat that carries them toward their goal.

This journey of a thousand miles begins with a single step --Lao Tzu

False Quality Gates

False quality gates are quality checks that don't do anything to promote the quality of the project. It is a sign that more attention is concentrated on format, rather than content. It can be a glossary of terms with the wrong content or a word template where most of the sections are filled in with the words "This section must contain text to fulfill company guidelines".

Testing Before Testing

Testing before testing refers to the practice of thinking about how to test a feature at the same time you think about how to implement it. If it cannot be tested how can you know that it does what you say?

Cider House Rules

Cider house rules are rules written by someone unconnected to the project. Rules like this, that give no apparent value, are a burden to the project and therefore often ignored.

Nobody pays attention to them rules. Every year Olive writes them up and every year nobody pays any attention to them. -- John Irving, The Cider House Rules

Talk Then Write

The team makes decisions during conversation, and then immediately communicates the decisions in writing. This is a really important pattern that it is easy to forget!. A common place where this kind of decisions are written down is very helpful.

Practicing the End Game

A team that does not release often and regularly will often take a long time to make a release. The act of releasing a product should be practiced often so that is becomes a natural part of the project.

Data Quality

Data quality often sucks! A common solution is often to attack the problem with technology instead of putting in the manpower that is actually needed to improve the quality of the data. Company web-sites are the prime example of this. They are often full of completely useless information.

Undivided Attention

Complex work is hard and it requires undivided attention to be performed properly. Splitting people's attention over multiple project will severely hinder their performance.

By doing two things at once, you've cut your IQ in half, and believe me, those 40 points can really make a difference. -- Dale Dauden, The New York Times

Orphaned Deliverables

Orphaned deliverables are deliverables that no-one values enough to pay for. Always make sure that there is a sponsor for every artifact that you are developing.

Hidden Beauty

Hidden beauty inside a program, that little extra thing, that may seem unnecessary, is what shows that the creator cares about his work. It is not unnecessary! This caring is what separates a quality product from garbage.

I Don't Know

If you are afraid of saying the words, "I don't know!", you are probably working in an organization where saying it means that you will be taken for a fool. In a healthy organization, "I don't know!", means that you don't know, but you will in a while, if it is important enough.

Loud and Clear

Having a clear goal, that everyone agrees to, is vital to a project. Clear goals allows you to focus the project activity if it starts to move away from its purpose. A PAM statement, that contains the Purpose, Advantage, and Measurements of a project is very helpful.

Conclusion

The patterns described above are just my short summaries, and I don't do them justice, but hopefully I have awoken your interest in this wonderful book.

It made my top-ten list and I recommend it to everyone from programmer to president. I like that the authors don't always provide a solution, but instead just describe the way they see it, it is up to you to figure out a solution to the problem yourself.

Saturday, October 03, 2009

Notes on Greg Young's on DDD

I watched Greg Young talk about DDD on InfoQ. Here are my notes on the talk.

  • Only use domain driven design on appropriate projects. Most projects are not suitable.
  • Use state transition event streams to communicate between different bounded contexts.
  • Bounded contexts are one of the very keys of domain driven design. The same word may have different meanings in different contexts, and this is OK.
  • Use OO, avoid setters. Objects have behaviors, not shapes.
  • If you always have valid objects, you avoid the problem of having to check if an object is valid all the time. IsValid is not the solution.
  • Always use the domain experts and end-users language.
  • Separating commands from queries gives the benefit of eventually consistent, queries may read from a different place than the commands.
  • Coupling is not a problem, if it's in the same layer.
  • Model the view, such as screens, as reports, with no transactional behavior.
  • Explicit state transitions remove the need for auditing. They are the audit.

Wednesday, August 12, 2009

What Eric Evans Would Have Changed in the DDD Book.

Here are my notes of Eric Evans talk What I've learned about DDD since the book

Essentials

Emphasize that the collaboration with the domain experts is essential. It is up to you to show the domain experts how valuable their collaboration is. If they cannot see the value of participating in the project, they will not to a good job, and they will try to avoid it.

Always produce at least three bad models. These models help to emphasize what is important.

The chapters "Distillation of the Core Domain" and "Context Mapping and Boundaries" should have been moved to the start of the big since these are the most essential areas.

Changes to Building Blocks

Domain Events

There is one new Building Block and it is the Event Object. The Event Object is an object the represents an Event that is significant to a domain expert. A benefit of domain events is that they give clearer, more expressive, models.

The events can be used for: - Representing the state (history) of entities. - Decouple systems with event streams (publish-subscribe) - Enable high-performance system.

Aggregates

Evans want to emphasize som things of aggregates. The boundaries of an aggregate need to contain transactions, distribution and concurrency.

When modelling the aggregates it is important to not over-specify on what part of the aggregate the properties and invariants are placed. Even though they are commonly placed on the aggregate root, this is not essential and it gives you a freedom if you not specify it too hard and too early.

Strategic Design

Large-Scale Structure does not come up very often and would probably have been left out of the book.

It is important to not spread modelling to thin, and to focus on the core domain and to create a clean bounded context.

Collaboration Patterns

There is two new collaboration pattern called Partners. This pattern differs from the other collaboration patterns in that it is cooperative and mutually dependent.

Another pattern is the Big Ball of Mud"_. This pattern is known as an anti-pattern since it implies that the code is just fixed as things go. This pattern is utterly pragmatic but the point Evans is making is that if there is a Big Ball of Mud in the system, it is important to define the boundaries of it, so that it doesn't spread to other systems that are more rigorously architected.

Context Mapping

  • What models do we know of?
  • Where does each apply? Define boundaries in words?
  • Where is the information exchanged?
  • The service interface may define a context boundary.

DDD and SOA

  • The service interface must be defined in some context.
  • Internals also, but often not the same one.
  • The service interface may define a context boundary.

Precisions Designs are Fragile

Sophisticated design techniques are wasted in a ball of mud. It must be isolated with an Anti-Corruption Layer.

Not all of a large system will be well designed. Figure out what part of the system is most critical and benefits most from a really nice design.

Monday, August 10, 2009

Notes on The User Illusion, part Two

This is part two of a summary of the fantastic book. The User Illusion

Our conscious mind consists of symbols that map into the rest of our mind. Every second more than 11 million bits are reduced to less than 50 bits of meaningful information at apparently no time at all.

Half a second before we try to do something consciously our brains has started its activity. Half a second!

Experiment
  • Sit down and hold one finger up.
  • Whenever you feel like it, bend your finger.

Half a second before your finger is bent, your brain has started its activity! It does not feel like half a second does it? There is no way! 0.1 second is more likely. But the data has been reproduced and it is undeniable.

The consciousness of wanting to do something appears almost half a second after the brain has initiated its activity.

Our actions are initiated unconsciously.

Benjamin Libet

Benjamin Libet performed some experiments, in the sixties, while a friend of his was performing brain surgery. Libet stimulated the brain with electrical impulses and found that if the brain was stimulated less the half a second, it was not noticed at all. If the brain was stimulated more than halv a second the patient felt it. It appeared to the patient as if a certain area of his body had been touched, since there are no normal sensors inside the brain.

Libet then performed some other experiments. He stimulated a part of the brain that related to the left hand and at the same time he stimulated the right hand and the patient was to say which hand was stimulated first.

The hand had to be stimulated half a second after the brain to give the appearance to the patient that they where stimulated simultaneously.

The conscious experience is projected back in time so that the conscious mind believes that they are almost simultaneous. The brain is fooling itself.

The conscious is delayed, but it does its best to hide it. For itself. It is very convenient since it gives the mind the time to perform the reduction of the sensory data to what is needed to get a full experience.

Everyone knows that it doesn't take half a second to remove a hand from a hot stove, but it takes half a second to get the conscious back-dated experience.

So does this mean that we don't have free will? Libet does not think so. He says that there is time for the conscious mind to veto the unconscious decision.

The conscious is not a top-level unit that gives orders to its underlying processes. It is a selecting mechanism that chooses between the different options that the unconscious provides.

As long as the unconscious action-proposals work in sync with the conscious thoughts and feelings, they are hardly noticed. They are merged together with the conscious motives that take all the credit! --Harald Høffding

The conscious veto is often associated with an uncomfortable feeling, we usually feel best when we are not making conscious decisions. Compare this with for example Flow

I and Me

Nørretranders defines I as the conscious mind and Me as the rest of us.

I have free will, but it is not my I that has it, it is my Me.

The conscious mind is allowed to use its veto in situations where the Me allows it to. In situations where speed is critical, for example when something is threatening us, the conscious mind is left out of the loop.

A comfortable state of mind is when the Me is allowed to do what it does automatically without interference of the I. This state is neither associated with nervousness nor shyness, but with comfort and carelessness.

The User Illusion

The user illusion is a term coined by Alan Kay of Smalltalk fame. He used it to describe the metaphor of the desktop that was invented by him and his colleagues at Xerox PARC. His great idea was that it does not matter what really happens inside the computer as long as the interface presented to the user is useful and consistant.

Nørretranders argues that our consciousness is our user illusion. Our consciousness is our map into ourselves and our possibilities to affect this world. I am the user illusion of Me.

The conscious mind may appear when the brains' simulation of the world has become complete enough to require a model of itself. --Richard Dawkins

Experiments with split-brain patient has shown that the mind doesn't think twice about making up a story that is consistent with something that does not have anything to do with reality. An example of this is:

  • A split brain patient is shown two images
    • The right eye was shown a snowy landscape
    • The left eye was shown a chicken's foot.
  • The patient pointed to two images.
    • The right hand a snow-shovel.
    • The left hand a chicken.
  • When the patient was asked why he pointed at the two images:
    • He said that he picked the chicken because it matched the chicken's foot
    • And that he picked the shovel because you need the shovel to clean out the chicken house.

The mind lied without hesitation to make the selection of images consistent.

Our consciousness is delayed to allow it to perform the required calculations. First we sense, then we simulate, then we experience. But we have no notion of the simulation. Consciousness is depth appearing as shallow.

Learning and Knowing

There are lots of things that we know how to do that we cannot explain. How do you ride a bike? How do you walk? How does your mother look? Its impossible to explain, but simple to know, once it has been learned.

The I's role in learning is to have the disciplin to learn by repetition, and the foresight that when I have learned this I will enjoy practicing it. The consciousness, usually, gets in the way while learning and, certainly, gets in the way when we practice what we have learned.

Science, usually, clarifies what we already know. It explains what we already know but cannot explain to each other.

Science is just refinement of everyday knowledge --Albert Einstein

The relationship between the conscious learning and the non-conscious ability is similar in both practical areas, such as ballet, and theoretical areas such as science; in both cases we must put in a lot of hard work for something we don't completely understand, but that we still can share with others.

The Rise of Consciousness and Religion

Nørretranders brings up another researcher, Julian Jaynes, who argues that the consciousness of man didn't exist 3000 years ago. He has various theories to prove this. Among other things he brings up the Oracles of Ancient Greece and the voices religious people hear as examples of people who are acting without a consciousness. A pre-conscious man is just a me, and a conscious man thinks he is just an I.

He also makes an interesting point about religion. The I has to recognize that there is something greater than itself. But it is not a god it is the me. God is the part of man that the I cannot explain. Religion is too important to be left to the religious. It is the struggle between the carefree me and the worrying I.

The Limits of Consciousness

Most of the processes that go on inside our bodies we know nothing about. We cannot feel the blood flowing in our legs or our immune system attacking viruses, until the problems become large enough for the body to raise the temperature to increase the effect. We cannot hold our breaths long enough to kill ourselves. The unconscious part of us wont let us

The Beginning of the Universe

In the Universe there is as much negative matter as positive matter. The sum of it all is Zero. According to the laws of quantum mechanics it is possible for Nothing to split into something for a very short while. The less it is the longer it is allowed to exist. So, it the sum of everything in the Universe is Nothing can exist forever.

Emergence

Emergence is the appearance of group characteristics when the number of elements increase. An example of this is Temperature. There is no temperature when there are only a few molecules but when the number of molecules increases the Temperature property emerges. In the book Gödel, Escher, Bach, Douglas Hofstadter talks about the emerging properties of the brain, the thoughts that cannot be described at a lower level.

Gödels proof suggests the possibility that an view from a higher level may have an explanation capacity that is totally missing at a lower level. --Douglas Hofstadter

A larger system consisting of simple rules can show characteristics that cannot be deduced from the rules.

It is impossible to know how yourself or another human will react, because it requires you to have access to all the information yourself or this other person has had and this is impossible since human being mostly function unconsciously.

The Liars Paradox, "I'm lying" is not a liars paradox. It is the truth about our consciousness. --Thor Nørretranders

Sunday, July 19, 2009

Notes on The User Illusion, Part One

The User Illusion, is a magnificent book. It is written by the danish author Thor Nørretranders. The Swedish title of the book, "Märk Världen", is a better title. "Märk Världen" means Notice the World it can also be a pun, "Märkvärdigt", means Astonishing.

The popular usage of the term information has been perverted from the original meaning of the word. The original meaning of the word is similar to the word data. It is something that can be transmitted, stored or transformed. It does not have anything to do with meaning. In popular usage the word information is often interpreted as something that has an actual meaning and not just raw data that may or may not mean anything to anyone.

Thor Nørretranders refers to information as data. It does not matter if a conversation over the phone is gossip or if it is an explanation of the theory of relativity. It is information nonetheless. He claims that random information commonly referred to as chaotic as containing more meaning than ordered information. To support this claim he gives a simple example.

A random sequence of coin-tosses (101010101111) cannot be reduced to anything but the same sequence of coin tosses, while a regular sequence (111111111111) can be reduced to the simple statment: 12 ones. Therefore the 12 ones contain less information than the coin-tosses.

Another interesting aspect of this is that it is impossible to know in advance if a sequence can be reduced or not until the actual reduction has been done. This is related both to Turing's halting-problem and to Gödel's incompleteness theorem.

Logical Depth

A conclusion's logical depth is a measurement of its meaning, its value. The harder it is for the sender to reach a conclusion, the larger is its logical depth. The more "calculation time" he has used the greater is its value, since the receiver of the conclusion is relieved from having to perform the same calculation.

Logical depth can informally be defined as the number of steps in a conclusion or causal chain that connects something with its probable origin. Logical depth describes complexity.

A table of moon phases can be calculated by a simple formula, but it takes time. A living organism can be specified by a few genes but it takes a long time to develop the complete organism.

Chaos and disorder cannot be reduced to something less. The shortest program is identical to it all. They have no logical depth.

It is difficult to make things look easy. Clarity demands depth.

Communication and Exformation

To communicate is to take information (a mental state) in the sender, reduce this state to a message that can be transferred over a channel to the receiver, the receiver then interprets this message as information (his own mental state).

The explicitly removed information, Nørretranders calls exformation. A statement has depth if it contains a lot of exformation. That is, information that existed in the sender, but was purged while composing the message, and is no longer present in the final result.

There is no possible way to calculate the exformation of a message from the contents of the message. This can only be found in the context of the message. The sender forms the message so that it refers to a common context allowing the receiver to re-create the meaning from this context. A good communicator not only thinks of himself, but also of what the receiver is thinking about.

Meaning is purged information, removed information, unneeded information, exformation.

Information is not needed to transfer exformation. An example is an agreement between a child and his parents that instead of calling every week, he will only call if he is in trouble. Every week exformation is communicated, all is well, by not sending any information at all.

To communicate well we must be able to take the information in our heads and create meaningful symbols of it. These symbols should represent a common understanding so that the recipient of the symbols can induce the same understanding that we have.

Meaning and Consciousness

What we consciously experience in any given moment, limits itself to a very miniscule part of the flood of information that flow through our senses. --Manfred Zimmermann

The bandwidth of our conscious is less than 50 bits/s. Our senses take in around 11 million bits/s with the vision at 10 million bits/s, touch - 1 million bits/s, hearing and smell - 100 000 bits/s, and taste - 100 bits/s.

Most of what we experience, we can never tell someone else. We experience millions of bits but can only verbally communicate decades.

But we are not limited to verbal communication. Just as our senses can recieve 10 millions of bits our bodies can also communicate. Our bodies send out 100 000 bits/s through body movements, voice modulations, facial expressions, etc. It is just not possible to recieve all this information consciously. This is why there is no substitute for face to face.

A good bedtime story is good since it induces feeling in the adult that the child is able to pick up and react to. The excitement, sadness, and happiness induced by great tales such as The Ugly Duckling, by H.C. Andersen is what makes them great. The tale creates a much wider communication channel than a tale that means nothing to the adult, since the emotions emitted from the adult induces the same feeling in the child at a much higher bandwidth than simple words can communicate.

The unconscious is not hidden from anyone, but the person, who for himself tries to hide the sides of himself that were disliked by the people who he loved while growing up.

Others know more about us than we do.

Most of the information that pass trough us is never experienced consciously, although this information has a noticable effect on our behavior.

The Unconscious

When we meet a new person, we usually make a really quick decision whether we like the person or not. We say, "You nerver get a second chance to make a first impression!" and "We don't have chemistry". These decisions are made so quickly that they cannot possible be made by the limited understanding of our conscious. This is indirect evidence of high-speed channels that operate unconsciously.

The conscious is a much smaller part of our life than we are conscious of, because we cannot be conscious of that which we are not conscious of.

Our conscious is like a flashlight and wherever it looks there is light. The obvious conclusion of the flashlight is that it is light everywhere. We are conscious less than we think, because we cannot be conscious of not being conscious.

I am sure that there are no words in my conscious when I am really thinking. --Jacques Hadamard

Real thinking is not a process that is performed consciously.

Thoughts die the moment that they are put into words. --Schopenhauer

When was the last time you ate fish? Yesterday? Last year? Never?

The moment you started thinking about this, your conscious mind let go. How did you come up with the answer you gave? Did you think through all the meals you have eaten in your life or did it just pop into your head?

Summary part one

The first part of the book sets the stage for the rest of the book. It introduces, and defines, the words: information, exformation, and logical depth. It also introduces the notion of meaning, consciousness and unconsciousness.

Our conscious can contain less than 50 bits per second. While our senses take in more than 11 million. Our brains process the 11 million bits of information and reduces them down to 50 meaningful bits, symbols that map into the rest of our brain and knowledge. But processing takes time even for something as able as our brains. But isn't our conscious perception immediate? No, it's not, but it appears to be! The second part of the book and the second part of this summary deals with this discrepancy.

Wednesday, July 15, 2009

Notes on The Secrets of Consulting

I finally found time to read The Secrets of Consulting by Gerald Weinberg. With all books with titles like, How to Win Friends and Influence People, I very reluctantly start to read them, because, they sound like books on learning how to be manipulative and I don't want to be like that. But when I finally start reading them, after many independent recommendations from people I trust, I find them to be very down-to-earth and not at all manipulative. They are more about how to become a sympathetic human being and because you are, to become successful in other areas too.

The book is full of good ideas and I am going to mention a few that I like from every chapter in the book.

Why consulting is so tough?

The quotes I like best in this chapter are

You'll never accomplish anything if you care who gets the credit.

This is very true. I've seen this many times. People who care about credit, usually, wants a little more than they deserve and this will piss of other people who also wants the credit. Meanwhile, the people who don't care about the credit, just keep on working, making things happen.

When an effective consultant is present, the client solves problems.

And the funny part is that it does not matter as long as I feel that I am doing a good job.

Cultivating a Paradoxical Frame of Mind

The answer to Get it done in the shortest time possible is

What are you willing to sacrifice?

This implies that everything is a tradeoff. The most common tradeoffs are Now versus Later and Risk versus Certainty. Another good reply when someone wants to get something done is

We can do I it - and this is how much it will cost.

This is a very good reply since it shows that you know what you are talking about and that you are not just saying something to get the contract.

Being effective when you don't know what you are doing.

The most important thing to remember is that:

It is always a people problem.

People always want to catch a consultant with a lie, so:

We ought to bend over backwards to understate our qualifictions, but    insecurity makes us all victims to occasional exaggeragtion.

Seeing what's there

If you use the same recipe, you get the same bread.

Learn from history. If you don't listen to the mistakes the client has made you are likely to make the same mistakes.

Study for understanding, not for criticism.

A client is not very likely to help you, if you criticise everything he has done. Look for what you like in the present situation and comment on that. Someone will always comment on what's bad.

We may run out of energy, or air, or water, or food, but we'll never run out of reasons.

People never run out of reasons. We can think of a million reasons to rationalize our behavior and none of them may be the true reason. We may not even know it ourselves.

The name of a thing is not the thing.

This is so very true. Naming is really, really important! But we should always be aware that a name is just a label and there is always more to it than that. If we think the name is the thing, we may miss important points.

When you point a finger at someone, notice where the other three fingers are pointing.

It is always easier to blame someone else.

Seeing what's not there

It is as important to see what's missing as it is to see what is there. Use laundry lists to remember what to look for.

If you can't think of three things that might go wrong with your plans, then there is something wrong with your thinking.

It is easy to become to narrow-minded when it comes to your own thinking.

Words are often useful, but it always pays to listen to the music, especially your own.

Be aware of congruent words and emotions.

Avoiding traps

What you don't know may not hurt you, but what you don't remember always does.

Set triggers to help you remember. Triggers may be anything from songs to one-liners, jokes and mental pictures.

It ain't what we know that gets us into trouble, it's what we know that ain't so.

Never be too sure of anything.

Amplifying your impact

Characteristics of a good consultant:

  • Your task is to influence people, but only at their request.
  • Your task is to make people less dependent on you, rather than more.
  • Try to Jiggle. The less you actually intervene, the better.
  • If your client wants help solving problems, you are able to say no.
  • If you say yes but fail, you can live with that. If you succeed, the least satisfying approach is when you solve the problem for them.
  • More satisfying is to help them solve the problem in such a way that they will be more likely to solve the next problem without help.
  • Most satisfying is to help them learn how to prevent the problems in the first place.
  • You can be satisfied with your accomplishments, even if the client don't give you credit.
  • Your ideal form of influence is first to help people see their world more clearly, and then to let them decide what to do next.
  • Your methods of working are always open for display and discussion with your clients.
  • Your primary tool is merely being the person you are, so you most powerful method of helping other people is to help yourself.

Gaining control of change

Feedback

Fords Fundamental Feedback Formula
1. People can take any amount of water from any stream to use for any purpose desired.
2. People must return an equal amount of water _upstream_ from the point from which they took it.

Believing in what you do

Would you place your own life in the hands of this system?

How to make changes safely

Nothing new ever works.

I have come to this conclusion myself and I heard Joel Spolsky mention a harsher version of this on the Stackoverflow Podcast. He said Nothing ever works! not just new things.

Trust everyone, but cut the cards.

Fundamental skepticism is necessary.

If you must have something new, take one, not two.

When trying out something new, try one thing at the time otherwise you will not now what fails when it fails.

It may look like a crisis, but it the end of an illusion.

When a crisis occurs it is a sure sign that something has not been right in the first place.

What to do when they resist

The first thing to do with resistance is to appreciate it. If you get no resistance something is clearly wrong. When facing resistance Get it out into the open. Name the resistance in a neutral way. * Locate the nature of the resistance.

You can make a buffalo go anywhere, just so long that they want to go there.

Clients tend to overestimate unspoken negative factors and to forget positive ones.

Good questions for defusing potential resistance are:

  • Is there anything you would like to change about this plan?
  • What do you like best about this plan?
  • What is the one thing that you want to be sure does not change?

    People who are realistic about risks don't become consultants.

  • Step away, if you feel the fight cannot be won.

Marketing your services

  1. A consultant can exits it two states, Idle or Busy.
  2. The best way to get clients it to have clients. It is best to look for new business when you have business.
  3. Spend at least one day a week getting exposure.
  4. Clients are more important to you than you can ever be to them.
  5. Never let a single client have more than one-fourth of your business.
  6. The best marketing tool is a satisfied client.
  7. Give away your best ideas.
  8. It tastes better when you add your own egg.
  9. Spend at least one-fourth of your time doing nothing.
  10. Market for quality, not quantity.

Putting a price on your head.

  1. Pricing has many functions, only one of which is the exchange of money.
  2. The more they pay you, the more they love you. The less they pay you, the less they respect you.
  3. The money is usually the smallest part of the price.
  4. Pricing is not a zero-sum game. My gains doesn't have to be their losses.
  5. If you need the money, don't take the job.
  6. If they don't like your work, don't take their money.
  7. Money is more than price. If the clients have paid in advance they are more likely to be prepared for the job.
  8. Price is not a thing; it's a negotiated relationship.
  9. Set the price so you won't regret it either way.
  10. All prices are ultimately based on on feelings, both yours and theirs.

How to be trusted

  1. Nobody but you cares about the reason you let another person down.
  2. Trust takes years to win, moments to lose.
  3. People don't tell you when they stop trusting you.
  4. The trick of earning trust is to avoid all tricks.
  5. People are never liars - in their own eyes.
  6. Always trust your client - and cut the cards.
  7. Never be dishonest, even if the client requests it.
  8. Never promise anything.
  9. Always keep your promise.
  10. Get it in writing, but depend on trust.

Lessons from the farm

  1. Never use cheap seeds.
  2. A prepared soil is the secret of gardening.
  3. Timing is critical.
  4. The plants that hold the firmest are the ones that develop their own roots.
  5. Excessive watering produces weakness, not strength.
  6. In spite of your best efforts, some plants will die.

All in all, this is book full of good advice that is worth reading for anyone, not only consultants. Worth noting is that the consultants in this book are very far from the resource-consultants that are the common case in Sweden. The consultants this book refers to closer resemble what we know as management consultants, although it is not an exact match.

Monday, May 11, 2009

Notes on Strangers to Ourselves

Strangers to Ourselves by Timothy Wilson is a book in the same spirit as the User Illusion by Thor Nørretranders. Both books are about how our unconscious mind plays a much bigger part in our lives than our conscious mind gives it credit for.

Our senses register 11 million bits per second and our conscious mind can only deal with 40. What happens to the other 10 999 960 bits is the topic of this fantastic book!

Adaptive Unconscious

In one study a woman suffering from lack of short-term memory was visited several times by a researcher. Every time he visited her, he had to re-introduce himself, since she didn’t recognize him. Then one time he pricked her with a pin when they shook hands. The next time he visited her, she didn’t recognize him, but she refused to shake his hand.

Attention and selection: the non-conscious filter. We become aware of new things even though we are in the middle of doing something completely different. For example: I am talking to someone at a dinner somewhere and then I hear someone mentioning my name in a different group talking amongst themselves. Suddenly my attention shifts to that of the other group

Interpretation: the non-conscious translator. Our preconceptions affect how we interpret situations. For example: If you after hearing something positive about someone it is a lot more likely that you will interpret their actions as good than if you haven’t heard anything positive. Studies with teachers show that teachers that were told that a random selection of students were likely to succeed, were affected so much that the selected students actually improved more than the other students.

Feeling and emotion: the adaptive unconscious as evaluator. In a study where the subjects were given cards from 4 decks of cards, A, B, C, and D, they were able to select the best decks on “gut-feeling” even though they could not verbalize why they selected as they did.

Unconscious goal setting. When we are playing games with our kids we may select not to win the game to make the kids feel happy and ourselves fell gracious. After doing this a lot our unconscious may automatically select for us not bothering the conscious with the burden to select.

Who’s in Charge?

Is our conscious in charge or are the non-conscious processes in charge? Some believe that our conscious is like a president, and makes all the executive decisions about what our non-conscious processes should be doing, others believe that our consciousness is more like a child playing demo games. They think that they are playing, but in reality it is just a simulation that they can do nothing about.

If I feel hungry and decide to go to the kitchen to eat a sandwich, it may feel like I make a conscious decision but, it may well be that my desire to eat arose non-consciously and triggered both my conscious thought and my trip to the kitchen. The consciousness may just be an illusion.

The truth is probably somewhere in between. Our consciousness, differs from our adaptive unconsciousness in several important ways.

Adaptive unconsciousness Consciousness
Multiple systems One system
On-line pattern detector After the fact check and balancer
Concerned with now Long view
Automatic (fast, unintentional, uncontrollable, effortless) Controlled (slow, intentional, controllable, effortful)
Rigid Flexible
Developed and mature Slower to develop
Sensitive to negative information Sensitive to positive information

Knowing Who We Are

Personality has been defined as the psychological processes that determine a person’s “characteristic behavior and thought”.

We probably have two personalities, one conscious and one unconscious. The conscious is measurable through questionnaires, while the unconscious is only measurable through indirect techniques.

As an effect of our two personalities we are also likely to have dual motives and goals. If our motives and goals and thus our two personalities correspond well, we are more likely to feel emotionally well.

Knowing Why

Our conscious is fantastic at making up causes for why we act the way we act. In a study with a split-brain patient (a patient who have had their brains split in half), researchers showed the patient pictures, one for the left eye and one for the right. At one time he was shown a picture of a snow scene to his left eye and a chicken claw to the right eye. He was then asked to pick up cards that related to the pictures. He picked a shovel with his left hand and a chicken with his right. When he was asked why he picked the cards, his answer was: “I saw a claw and picked a chicken, and you have to clean out the chicken shed with a shovel”. Our speech center is in our left hemisphere so the patients brain knew that it had seen a claw. It had no idea, however, why he had picked a shovel so it made up a reason.

Why do we do the things we do? We really have no idea. When an idea pops up into our head we may trace the thoughts causally back until we reach something that seems to be a reasonable cause of our thought. But, this thought may just be made up by our conscious mind to get a felling of control.

If I decide I want a sallad for lunch today and I am asked why, I will probably justify it with, something like, I am trying to lead a healthier life, etc., etc. But the real reason may be that I saw an obese person earlier this morning and he generated the thought later that day.

The theory is that we have no access to our mental processes, only to the mental contents that are the results of those processes.

Studies made in this area, have shown that a stranger may be as good as we are at predicting why someone did something. It may be as accurate to call a random person up, give them some data about what you have done during the day, and then ask them how you feel as to try to figure it out yourself!

Even if we, personally, have access to more information, there is no reason that this extra information will make our conclusion any more accurate.

Knowing How We Feel

Our feelings have always been believed to reside in our conscious, what good would they do if we didn’t notice them? But, not even our feelings are sure to be completely conscious. The author gives the argument that, sometimes we feel something and not until later do we realize that we didn’t have that feeling at all. Wilsons example is a couple of people that talk about a horse they owned as a kid, one of them says, “Good, I hated that horse!”, and the other person realizes that she has always hated it too. Even though she didn’t acknowledge it at the time.

Another example is that when we experience something scary, like losing control over a car, the feeling of fear doesn’t strike us until after the incident is over. Wilson argues that we get an unconscious feeling and only afterwards does the feeling appear in our conscious.

Other feelings that we fail to recognize are prejudice feelings. We think that we are very liberal but, at a deeper level we feel the feelings anyway and others can tell even if we don’t allow ourselves to see it.

The reason that we have these unconscious feeling is that they react a lot faster than our conscious feelings do. When we see a stick lying on the ground we may first react scared, thinking it is a snake, only to realize afterwards that it was only a stick and move on. If it is a snake the faster reaction may say our life.

Knowing How We Will Feel

If it is difficult to know what we feel at the time, how are we to guess what we will feel in the future? When we try to predict how we will feel in the future we usually exaggerate the feeling. How would you feel if your wife died? I would never get over it. How would you feel if you won twenty million dollars. I would live happily ever after, doing whatever I please.

Neither of these replies are very likely. There are a number of reasons why we exaggerate our future feelings. First, they are thought of in isolation, we don’t take into account all the other things that will happen at the same time as the events take place that we are imagining. Second, as soon as something happen to us, we start to internalize it. If I win the lottery I will be happy for a while but, after a while this will be the status quo that I compare things against.

This implies that we know very little about ourselves. Is there hope for us to improve this?

Introspection and Self-Narratives

It is often thought that to introspect our feelings, to think about why we feel a certain way, is a good approach to self-improvement. But this is not always the case.

The problems with introspection is that we may try to make too much out of what we find. If we are asked why we love our spouses and try to make a list of reasons why, we run the risk of believing that this is the whole story and not just a small subset of it. It may not even have anything to do with why we feel the way we feel. When we try to articulate our feeling we diminish them.

He who deliberates lengthily will not always choose the best. —Goethe

So, are we supposed to ignore why we feel the way we do and just act on impulses? No, it is important to distinguish between informed and uninformed gut-feelings. The trick is to gather enough information to develop an informed gut-feeling and then not analyze that feeling to much. We should let our adaptive unconscious do the job of forming reliable feeling and then trust those feeling, even if we cannot explain them entirely.

If we try to imagine, in detail, the situation that would occur if we acted on our feeling, perhaps we would be better at recognizing our true future feelings

Looking Outward to Know Ourselves

To complement knowing ourselves by introspection, we can look outwards instead. We can look at the research done in psychology. For example, in one study, a group was tested for automatic prejudice. The study showed that people unconsciously made different decisions when they were not given enough time to think over their replies consciously. To know that our unconscious opinion may be different than our conscious one is good knowledge to have.

To try to figure out what we are like by observing how other people react to what we do is an approach that isn’t very fruitful. Our observation of the other person gets filtered by our unconscious and it is not at all unusual to think that someone admires you, while they think you are a complete idiot.

A better approach is to ask others what they think and use their description as a clue to finding out how we are. But the people you ask have to be very honest.

Observing and Changing our Behavior

Despite years of research on self-perception theory, there is an enduring question: Is the self-perception one of self-revelation or one of self-fabrication. Self-revelation is good in that it helps us understand ourselves, while self-fabrication isn’t since it infers things that didn’t exist before.

In the end, the only way to change how we are is to change how we act. Since acting in a way you want to act will make you a person who acts like you want to act.

Tuesday, March 03, 2009

Are your lights on?

I just read the book Are your lights on?, by Donald C. Gaus and Gerald M. Weinberg. In it there are some interesting sayings about problem solving.

  • A problem is a difference between things as desired and things as perceived.
  • You can never be sure that you have a correct definition, but don’t ever stop trying to get one.
  • Don’t solve other people’s problems if they are perfectly capable of doing it themselves.
  • If it’s their problem, make it their problem.
  • If a person is in a position to do something about a problem, but doesn’t have the problem, then do something so he does.
  • There are two kinds of people in the world, those who do work and those who take credit. Keep in the first group, there is much less competition there.
  • Do we really want to solve the problem?

There are som many options available when solving a problem.

The first quote, for example,

A problem is a difference between things as desired and things as perceived.

gives us the options of solving the problem by changing the desire or the perception of the problem instead of actually changing the reality to what is desired.

Wednesday, January 28, 2009

Brain Rules

I just read John Medina’s book Brain Rules. It is a book about how our brains work. What I find most interesting is how it applies to learning.

Attention

Our brains are able to pay attention to three things. It can be characterized by these questions.

  • Does it want to kill me?
  • Can I have sex with it?
  • Does it remind me of anything?

All three questions are relevant to how you give a presentation. If everyone seems to be dozing off they can be awakened by I sudden sound or a picture of something sexy. But these measures are just that, attention grabbers, and if a presentation is so boring that I have to slam the table all the time I’m definitely doing something wrong.

The third question: Does it remind me of anything? is different. It is very important both to giving presentations and to learning. If I can find a way while giving a presentation to have the audience relate to my subject in any way, they are more likely to pay attention. It’s the same with learning. If I’m learning something that reminds me of something else it will be easier for me to put it in a context that means something to me and that will enable me to learn it much better.

I find this very interesting since lately I’ve found that I like doing things that I suck at. The things I like and suck at are very diverse. I have started to like skateboarding, playing Guitar Hero, and even carpentry. I think that it is because I know more now and even if I’m no good at these things they remind me of other things that I’m better at. And just as important, they widen my frame of reference, so next time when maybe I have to weld something I wont find the entrance barrier to high to even imagine doing it. The more I recognize, the more I relate to, the more I like. It is a good loop.

Memory

In the book Medina also talks about memory. There are, at least, two kinds of memory, short-term memory and long-term memory. The short-term memory is our working memory and it is good for very short periods of time. To store something in long-term memory, repetition is required. The more I repeat something, the better I will learn it.

The best books I have read that take advantage of repetitions without being boring are The Little Schemer-series, The Little Schemer, The Seasoned Schemer and The Reasoned Schemer. These books are built up as a series of questions in one column and the answers in another. The difficulty increases gradually as you read more.

The point of The Little Schemer is to teach to think recursively in Scheme. It does a great job of teaching this, probably because of all the repetitions that are involved.

The point of The Seasoned Schemer is to teach more advanced concepts of functional programming in Scheme, such as continuations.

The point of The Reasoned Schemer is to teach logic programming in a functional context.

It is interesting that the concepts taught in the books are quite complex and still they never feel hard when presented in this way. I highly recommend them to anyone.

Another interesting thing about repetition is that it seems to be happening while we sleep. When we are sleeping our brains keep repeating things that we learned during the day. After going to sleep while reading The Seasoned Schemer, I remember waking up one morning and finally getting how continuations work. Quite a good feeling.

Stress

Stress affect learning in a bad way for almost everybody. Stress is defined, to allow researchers to measure it, as having three criteria.

  • It has to create physical arousement.
  • If you could avoid it, you would.
  • It has to feel like it is out of your control.

If any of the above is true, it is said to be stress. When we are stressed our brains cannot focus on the task at hand and this will decrease our learning abilities severely.

You can also listen to John Medina talking about the book on the Ruby on Rails Podcast.