Wednesday, April 29, 2009

Notes on seven habits of highly effective people

To be rather than to seem.

This quote illustrates the importance of self-reflection. What others think matter little if you know.

Circle of Concern and Circle of Influence

The circle of concern are things that affect you but that you can do nothing about, such as the weather, stock market, etc. The circle of influence is things that affect you, that you can do something about. Don’t worry about the first kind.

Important or Urgent

What is important to most people, family, friends, etc., is often neglected because urgent matters take their place. Make up you mind on what is important to you and make sure that matters that are less important, however urgent, don’t let you neglect them.

Organize Weekly

A smaller time period will force you to only prioritize crisis. The week is a time period that is large enough to give you time for all important things, yet small enough, to give a sense of perspective for what the big things are.

Monday, April 27, 2009

Notes on Pragmatic Thinking and Learning

Andy Hunt has written a good book on thinking and learning. It contains light reading about how our minds work. Here are some gems from it. This is by no means a review of the book it is just my notes on things that I had not heard before or felt I needed to remind myself of.

Always consider the context.

Nothing happens out of context. Nothing! There is no objective truth.

Learn by synthesis as well as by analysis.

This is learning by doing instead of by studying. Instead of dissecting a frog, try to build one, to figure out how it works.

Every read is a write!

This has to do with our thinking and it means is that every thought we think affect our brains and thus all the rest of our thoughts. No wonder thinking positively has profound effects on us.

Our brain works in two modes, linear and holistic.

To take advantage of the holistic part we need to defocus and allow the “back” of our brain to do its work. The R-mode as the holistic part is called cannot verbalize its thoughts and we are therefore forced to use the L-mode to be able to talk about the ideas that R-mode may have come up with. Beware that details may be lost in the process.

Are you making a logical argument, an emotional one or just a familiar one?

It is an interesting question to ponder every time you get into an argument.

SQ3R – Scan, Question, Read, Recite, Review

To get the most out of a book, use SQ3R.

It is by logic we prove; it is by intuition we discover. —Henri Poincaré

It is important to acknowledge that the seed to our knowledge have nothing to do with logic at all.

You got to be careful if you don’t know where you’re going, because you might not get there. —Yogi Berra

Set goals!

SMART – Specific, Measurable, Achievable, Relevant, Time-boxed

Goals that are not SMART are visions, important in the large, but they need to be complemented with SMART goals.

Documenting is as important as documentation.

Writing documentation brings out problems and clarifies what the code or product is supposed to do. The insights from this process may greatly improve it.

Establish rules of engagement to manage interruptions.

Since context-switching is very expensive it is very important for teams to have clear rules for when, where and why anyone can be disturbed.

Thursday, April 23, 2009

Does a Dog Have Buddha Nature?

A Zen monk approached a cow in an attempt to understand the concept of Buddha nature. As he started to speak he noticed a dog wandering, and asked Does a dog have Buddha nature?

Almost before the monk could finish asking the question, the cow said, “Mu!”

Thursday, April 16, 2009

Developer Summit 2009, day 2

A Technical Drilldown into “All Things M” by Brian Loesgen

M is a new modelling language that allows you to create domain specific languages or DSLs.

M today consists of three parts
  • MSchema is a language for defining domain models.
  • MGrammar is the language for defining DSLs.
  • MGraph a data graph consumed by a runtime.

IntellliPad is an editor that understands MSchema and MGrammar. It allows you to define schemas and grammars and view them as graphs. The editor grammar is defined in itself. It seems to be very cool.

The specifications are open and it is possible to implement them for other platforms.

RESTful Enterprise Integration with Atom and AtomPub by Ian Robinson

Atom is the specification of the format.

AtomPub is an application protocol for editing Web resources using HTTP transfer of atom-formatted representation.

Ian demonstrated RESTBucks application that used an event-driven architecture that communicated via rest. Out of three different implementation options, point-to-point, bus and having the consumer pull the events the latter was chosen.

The product management system published the service by publishing an Atom feed. The client the pulls this feed to get the updates. The feed represents an event-stream. The feed contains a link to a previous feed-archive and the archive is immutable and therefore cacheable. An atom-entry represents an event.

Leonard Richardsson’s Web Service Maturity Heuristics

  • Divide and conquer to spread complexity around with URIs.
  • Do the same things in the same way to reduce complexity with uniform interface.
  • Describe special behavior in a standrad way to make complexity learnable with hypermedia.

Taylorism och massproduktion by Marcus Ahnve

In the past man has been first; in the future systems must be first.

Taylor wrote a book about principles of how to get more work done. This was done by having management define the work to be done and then someone else has to do it.

Look out for:

  • Division of labor
  • Best Practice
  • Standardized work
  • Grouping of skills

Leaderful Moves for Managing Team Promises by Deborah Hartmann Preuss

What does your team really care about? Do you know? Do they?

Refactoring Books

Here is a list of the books mentioned in my talk on Large Scale Refactoring.

Refactoring: Improving the Design of Existing Code is the original book written by Martin Fowler. It is a must have to anyone doing object-oriented programming.

Refactoring to Patterns is a very good book written by Joshua Kerievsky. This book is one of the best books I have read on patterns. It shows how some smells in code can be removed by refactoring them into design patterns.

Refactoring Databases: Evolutionary Database Design is a superb book that deals with refactoring databases. If you do any work with databases, you have to read this book.

Refactoring in Large Software Projects is a book about how to refactor large software systems. It is an OK book, but very far from the other refactoring books mentioned above.

The Mythical Man-Month by Fred Brooks is the classic, more than 30 years old, dealing with problems in software development. It is well worth reading. You can also listen to his talk at OOPSLA 2007, which is very, very good.

Developer Summit 2009, day 1

Who do You Trust? Beware of your Brain by Linda Rising

In The Robbers’ Cave Experiment two groups of 12 year old boys were transported separately to a boy scout camp. In the first phase the groups formed identities by giving themselves a name, evolving rules, leadership, etc. In the end of phase 1 the groups became aware of each other. The reactions were strong. This is our swimming hole, they, whom they had never seen were given bad names.

In phase 2 the staff scheduled competitions and nice prizes were given to encourage competition. War broke out! The boys collected weapons and fights erupted.

I phase 3 the staff experimented to resolve the conflicts. The boys watched movies and had fun together. The conflicts could not be resolved.

Finally, the staff had the boys do projects together that were important to all of them. They had to work together to remove a tree that was dangerous to all of them. This pulled the groups together.

Blue-eyes vs. Brown was another experiment where a teacher told her students that brown-eyed children were smarter than blue-eyed children. The blue-eyed children were given collars to make everyone aware that they were not as smart. During the course of that day the children started treating the other group, whom they had known all their lives, badly.

Stereotyping is the act of labelling people.

Managers divide employees into winners and losers as early as 3 weeks after starting to work with them.

We forgive our behavior but not others’. The solution to avoiding conflicts with others is to give them the excuse that you would use for yourselves in the same situation.

When people are stereotyped and told that they are not as good as someone else the prophesy is usually fulfilled.

Since stereotypes are prophetic, the #1 rule for good management: Catch them doing something right.

In the Strange Phone Conversation experiment, men where given a photo and a bio and then had to call her. The men that thought they talked to attractive, smart women, influenced the conversation so much that when the women’s part of the conversation was given to other men and there was a correlation between the expectations of the first group and the impressions of the other.

The key to collaboration can be summed up with: I want to know what you think?

Deception and Estimation: How We Fool Ourselves by Linda Rising

Lisa’s message is: we naturally deceive ourselves and others, constantly!

Smarter people are better at deception, because they can create better “rational” explanations.

We cannot estimate! The only solution is experimenting.

Lean by Scott Bellware

In Scrum we make a plan at the beginning of the Sprint and try to estimate what we can fit into the time-box.

In Lean in contrast you don’t have a time-box instead you have just work. The goal is to eliminate waste. The waste in this case is the planning in the beginning and the work that does not fit into the time-box. This means that we have multiple plans, the release plan does not have to the same pace as the development plan, which does not have to have the same pace as the planning plan.

The Kanban is the glue and it is filled with work items that are produced by the planning process.

Cloud Computing a la Microsoft by Robert Folkesson

Windows Azure is Microsoft’s take on cloud computing. The session was just a demonstration of a new Visual Studio project type for cloud computing. The usual demonstration of point-and-click programming. It would be interesting to see it in work with command-line tools and continuous integration.

The one interesting thing mentioned was that all the different services provided by the Azure cloud are RESTful.

Can I deploy a local cloud? No!

Can I deploy the application with command-line tools or have my continuous integration server deploy the application. Yes

Good Test, Better Code by Scott Bellware

Scott talked about a BDD like framework called Machine Specification or mspec. He also mentioned the BDD goals of tests as documentation and design as well as test.

Specify the experience and not the implementation

Readable Code is not as important as Scannable code.

He also talked a bit of DDD and mentioned that Entities should not have dependencies and that services could. He also said that primary dependencies, like a data access service, should be injected into the constructor and that secondary dependencies, like a logger, should be injected with setters. I can agree with that, its not too controversial.

Wednesday, March 25, 2009

Scandinavian Developers Conference Report

This is a short report from SDC. My comments are in italics.

Habits for Agility, Kent Beck

Kent changed his topic in the last minute. I would have liked to hear the promised talk on Responsive Design. Instead he talked about more general things.

Attitude

The desire to see reality as it is and to respond. What is reality? Whose reality?

Accountability, take responsibility for your work, no excuses.

Action

Effective teams are biased towards action. If you have a problem, research it, and know instead of think. Try instead of guess.

Time

Find focused time to work. The Pomodoro technique, do something for 25 minutes without interruptions. After finishing something, take some time to reflect before starting on the next task.

Connections

Analogies will help improving communication. Sales people are good at being accountable, because their salary depends on it. Customers are people whose daily lives are affected by your software. Good connections improve understanding between people.

Perspective

A perspective is about the same as an elevator pitch. What do you do? This is essential since this will help you when things get complicated.

Everything that is completely repeatable should be automated. The goal of development is to automate everything.

Support

Good teams find a way to get support, by meeting the needs of the people that can give you support.

Reflection

The cycle goes from action to reflection, ...

Ancient Philosophers and Blowhard Jamborees by Neil Ford

Neil had a nice presentation on the lore of software development.

Those who cannot learn from history are doomed to repeat it.

Books that are part of the lore of software. Smalltalk Best Practice Patterns, Mythical Man Month, The Pragmatic Programmer

Plato invented object orientation. The best way to solve problems is to think.

Aristotele, developed some important ideas like essential properties and accidental properties.

Galileo, didn’t believe anything he was told. Some things are counter-intuitive, anti-patterns.

Occam’s razor, given a set of solutions the simplest one is the best.

Fred Brooks, the second system is the most dangerous to build since you have all the knowledge of what went wrong with the first system it may be too difficult to get started with the second. KISS!

Cloud Computing, John Davies

John Davies talked about mostly about Amazons Web Services and showed how easy it is to set up an EC2 account. He also talked a bit about cloud computing in general. It seems to me that cloud computing is popular because it is easier to set up a new server in the cloud than it it to get the IT-department on the company to set it up. Something is wrong with this picture.

Google App Engine, for application written in Python. Amazon’s Web Services (AWS) include EC2, S3, Elastic Block Service, SimpleDB, and Simple Queue Service.

Advantages of cloud computing are reliability, security, scalability, volume testing, development with continuous integration and version control. It’s simple to setup new machines.

Setting up an EC2 account

  • http://aws.amazon.com
  • Create x509 certificate
  • Download the EC2 API Tools
  • Setup some environment variables
  • Create a ssh key pair.
  • AMI, Amazon Machine Instance
  • Run instances, wait a minute, and log in.

Cool Tools

  • Elastic Fox – firefox plugin
  • ElasticPod – iPhone App

Functional, parallel, and asynchronous programming in F#, Don Syme

Don’s hands on approach to presentation is very nice. He didn’t show much that I hadn’t already seen though.

Why is Microsoft researching functional programming.

  • Pleasure
  • Economics
  • Programmer Productivity

Started with an introduction of the F# language, nothing new. Then the interesting part started, the asynchronous, parallel coding.

let run x = Async.RunSynchronousy x

run(async {return 1+1})

run(ASync.Parallel [{return 2+2}, {return 3+3}])

Simple parallelism.

Outside In – Black Belt TDD/BDD, Niclas Nilsson

Niclas talked about why test first outside-in (or top-down) is better that inside-out. The reason is of course that you don’t create any code that is not necessary and that you know when you are done.

Moder IDEs will also support this style of coding since they can generate the missing method at will.

Thursday, March 12, 2009

It is my fault!

I did it! It is my fault! It was my idea that didn’t work! I fucked up!

I say the words and feel the relief flow through my body. Why? Because now the problem is under my control. One of the primary causes of stress is that the problem is beyond our control. So, just by acknowledging that the fault is mine, my stress level will lower and I will be in a better position to solve the problem. Now, when the problem is mine, I have plenty of options.

Seppuku

This will certainly solve the problem. It has unfortunate side-effects though.

Quit

If the problem is work-related, quitting will solve it. I may not get very good references from my employer, but maybe the employer is the problem in the first place. If the problem is not work-related, just decide that it is not worth the effort and quit, get divorced, throw your children out, whatever it takes.

Solve the actual problem

This is the path I usually choose, but it is good to know that the other options exist.

Programming Problems

For programming problems I usually find two gumption traps

I didn’t change anything

Sure I did, checking the status of the files, git status, quickly shows me that I made a number of changes. I can find the problem in one of those changes or I can just revert back to the previous working version and start over. A good reason for frequently checking in working code is that reverting to a previous version is less painful.

The stupid library isn’t working

Sure it is! The assertion is wrong. It should read The stupid library isn’t working as I expect it to! Now, I’m on the right track.

Why isn’t the stupid library working the way I expect it to? Because my expectations are wrong!

Did I RTFM? Yeah, kind of! All of it? Not bloody likely!

Do I know what all the things in the code means or did I just copy them from someone else? I copied some of it. Did the person I copied it from know what they were doing? I don’t know!

Whose fault is it then? Mine!

Is the stupid library really not working? No. Why am I using it? Because it solves a lot of other issues that I need to solve. Is it worth the effort? Yes? No?

Whose fault is it? Mine!

People Problems

People and process problems can be handled in a similar way. I find that many of them go away if we just realize that the problem is ours.

There is nothing wrong with Scrum, hell, there is not even anything wrong with RUP (even though I’ve written that in the past). The problem is ours.

The stupid process is not working! Sure it is! It should read the stupid process is not working as we expect it to!

The stupid process is not working as we expect it to! How do we expect it to work? Well, we don’t know. DOH!

Why is the stupid process not working as we expect it to? Because, we are not making it work as we expect it to.

Whose fault is it? Ours!

Sunday, March 08, 2009

Git it on

I switched to Git as my main version control system about five months ago and I haven’t looked back. I’m currently working on a Javascript project where I have to test and develop code both on the Mac and on the Windows VM-Ware images. I have usually had problems with this kind of setup, not so with Git.

Git Basics

I set up my git repository with the usual:

# Create directory
mkdir projectname

# Change to it
cd projectname

# Initialize the repsitory
git init


Then I add a .gitignore file with the specifics for this project.

# Local .gitignore
dist
pkg

And then I add the file to project and commit it.

# Add the .gitignore file
git add .gitignore

# Commit the changes
git commit -m 'initial'

My global ignore file $HOME/.gitignore contains everything that I have common for all projects.

# Global $HOME/.gitignore
*~
.DS_Store
tags
*.gz

Git works with changes, this is important, so you are not actually adding a file to the repository, you are adding the changes. This means that you will have to add files every time you have made a change to them. I like this since it gives me an extra level of control, but if you don’t, you can always use the -a option when you commit and it will include the changes to files that have been added to the repository at least once.

# Add and commit the changes
git commit -a -m 'changes to all added files'

After setting up the initial repository and adding the .gitignore file, I am set to go. I usually start with creating a new branch for development.

# Create the branch but don't switch to it.
git branch dev 

# Or, create the branch and switch to it.
git co -b dev 

# The co above is an alias for checkout, it was created like this
git config --global alias.co "checkout"

After creating, and moving to, this branch I create another branch for the task that I am going to work on. For example

# Create a new branch, setup_tests
git co -b setup_tests

I do what I have to do to get the task done and then I switch to the dev branch and merge the changes in.

# Switch branch to dev
git co dev

# Merge in the changes from setup_tests
git merge setup_tests

If at any point I feel like I need to do something that doesn’t have to do with this task, such as add some utility functions, I just commit the current branch and start a new one from where I am. This gives me very fine-grained control over the source code and it lets me throw away changes that goes bad without parsing and removing the bad changes manually.

If I forget to do my fine-grained branching, Git allows me to just add some of the changes from a file. The simplest way to do this is via the interactive add command.

# Enter git interactive add 
git add -i

Another command I find myself using more and more is stash. If the change that I need to do is totally unrelated to what I am doing now and I just need to fix it, I stash my current branch on the stash-stack and move to the branch where I need the change.

# Saves the changes on the stash stack
git stash

# Switch branch, change, and commit
git co development
git commit -a -m 'urgent change'

#Switch back, and apply the stash.
git co setup_tests
git stash apply

Like I said, the stash is a stack and the command git stash apply applies the top of the stack. If you have the need to apply a stash that is not on top, this is also possible. See the help, git help stash, for information on this.

Cross-VM Workflow

When I need to test my changes on Windows, especially on the awful IE6, I switch to this virtual machine and then I clone the repository.

# Clone the repository
git clone path_to_my_local_mac_directory

Now, I have a perfect copy of my repository and I can test and make the needed changes at will. After this I just push the changes back to the Mac again and pull them back to windows from now on.

# Pushes the current branch
git push 

# Pull the changes back
git pull

I usually find doing this in the development branch the best way to go and then I reserve the merging into the master branch to the repository that I have designated as main, the one on the Mac.

At the moment I am developing on my main repository and there is one caveat with this. If you push changes into this repository the working directory will not be updated. Thus, if you have local changes in your working directory and just commit them without checking the status. You will revert the changes that have been made on the remote repository. This is by no means a fatal problem since you can just revert your changes and move on, but it is still annoying. The lesson to learn is to always use git status before you commit.

# Shows the status of the repository
git status

Parallel Branches

In addition to working on a Project with Javascript, I am also developing a course in it. It is called Javascript, the Esperanto of the Web because that is what Javascript has become. When Java didn’t cut it as the language for the web, Javascript was there and that was all that it took.

When developing this course I have the usual issues with keeping questions in sync with the answers. Git solves this without any problems at all. All I do is to keep to branches of the tree, master, and solution. I do all the course development in the solution-branch and then I just merge it into the master branch where I remove all the correct answers. After that I move back to developing in the solution-branch.

If you want to get started with Git I can highly recommend the series of screencasts at “Gitcasts”: Start with the RailsConf Git Talk, it gives a good overview. If you’re on Windows and like GUI tools move on with the Git on Windows Talk. I use the Cygwin version for my windows version of Git since I have these tools installed anyway.

Friday, March 06, 2009

Time for Smalltalk again

March 24th, I’ll be giving another presentation on Smalltalk at the Scandinavian Developers Conference

The presentation will include:

  • An introduction to Smalltalk.
  • An overview of the language.
  • A very basic enumeration of the persistence options in Smalltalk.
  • Highlights from Seaside, templating in Smalltalk, and continuations.
  • Finally I will wrap up with the reason the Smalltalk is still the best language when it comes to small and medium scale development. The living environment than enables refactoring and the complete availability of open classes that allows putting functionality in its proper place.

The presentation will be a mix between live demos and slides.

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.

Friday, February 27, 2009

Learning to Type, a frustrating and liberating experience

About three months ago I read Steve Yegge’s blog about typing. Man, did his message hit home. I realized quickly that he was right and that I was not as good as I wanted to simply because I was not able to get my thoughts into the computer fast enough. And, “fap, fap, fap”, did I ever have that experience.

Every day I did that exactly thing, type a sentence or two then realized that I had a typo so I had to go back and fix it. So, I finally bit the bullet and downloaded a couple of programs to help me on my way. One of them was aTypeTrainer for the Mac which is free and good enough. I started learning, slowly, slowly. I practiced almost everyday, but programming was too slow and it made me very frustrated.

After about one month of frustration I decided to take a test to see how I was doing. 10 WPM and a couple of spelling mistakes. That is really, REALLY, slow. Should I quit, am I too old to learn this. I wish I did this when I was fifteen, or twenty, or even thirty, anytime but now. But, I hate quitting, so I kept doing it. To add to the frustration I’m using a standard keyboard with a standard layout which makes it difficult to get at those curly braces. But I like to have the Swedish characters available when I type, so switching to an American layout is not an option. I did do some customization, to get rid of the dead keys as I wrote about “before”.

On top of all this I am doing multi-platform development in Javascript which forces me to hack on different platforms everyday. I was using Textmate on the Mac and I tried to use the E-editor, the Textmate for Windows, on Windows. But they are not quite equal and the small nuances makes it very annoying. Then one day I was having an argument at work about editors and I found myself defending Vim since the modes that it uses allows you to have very accurate movements without having to resort to control-keys. I never really made the leap to Vim before and now I found myself defending it just because it lets me move around a file without forcing me to move my hands away from the standard typing position. As a consequence I’m writing this in Vim and I feel quite happy about it. I got the basic movement patterns down in a few hours and now I have to see if I have the stamina to keep Vimming, just as I have kept on touch typing.

I am by no means a good typist yet, but I’m up to 30 WPMs right now and I feel that I can get into a typing flow that I have never experienced before and it feels very good. It is actually fun to comment code, since my hands fly over the keyboard while I’m doing it. Ok, ok, maybe not fly, but at least they crawl at a decent speed :). So, thank you Mr. Steve Yegge, for all the pain and suffering that you’ve given me.

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.

Monday, January 19, 2009

Making the Mac OS X Terminal Hum

I recently had reason to get back to hacking at the command line again and it certainly is a pleasure. At least it was before some annoyances started to ruin my day.

The Terminal in the Mac has been improved with tabs in Leopard making the iTerm application that I used on Tiger redundant. New tabs are easily opened with Cmd-T and closed again with Cmd-W. But if I want to move between them I have to press Cmd-{ and Cmd-} which is closer to a vulcan nerve pinch than I am comfortable with.

Luckily my old license of Menu Master comes to my rescue. Menu Master ($12) is a simple tool that lets you reconfigure the menu shortcuts painlessly. So now the tabs can be easily switched with Cmd-Left and Cmd-Right as they should.

Next step is to configure bash to support my commands. My Emacs days are long gone and I don’t like to have different sets of shortcuts for the same thing in different applications. Bash uses readline for editing on the command line. I can choose between Emacs-mode and VI-mode. Emacs is still closer to my heart so I start out with this.

Aaargh!, What!, the Option key is not sent as a Meta-key and nothing works as it should. A quick look in the Terminal preference window on the Keyboard tab, shows me that I can check the use option as meta key. That sounds right…ok, here we go: Meta-delete – deletes word, Meta-. – inserts last argument of previous command, Meta-T transpose words,... Hey, we’re moving!

Ok, now I’ll just check what I did since yesterday:

git log @{yesterday}

What! No friendly at-sign appeared by the cursor, instead we move into some stupid digit-argument mode. Bastard international keyboard requiring me to use the Option key to write a simple at-sign. Ok, back to the drawing board. readline can be configured with an .inputrc file. Here’s a fix to all the number keys.

"\e1": "©"
"\e2": "@"
"\e3": "£"
"\e4": "$"
"\e5": "∞"
"\e6": "§"
"\e7": "|"
"\e8": "["
"\e9": "]"
"\e0": "≈"
"\e/": "\\"
"\e(": "{"
"\e)": "}"

While we’re editing this file we might as well add some candy to the sugar.

# Shows all files instead of beep when tab-completing
set show-all-if-ambiguous on
# Ignore case when completing, very nice!
set completion-ignore-case on


"\e[1~": beginning-of-line    # Home key
"\e[4~": end-of-line    # End key
"\e[3~": delete-char    # Delete key
"\e[5C": forward-word    # Ctrl+right 
"\e[5D": backward-word    # Ctrl+left 
"\e\e[C": forward-word    # Alt+right 
"\e\e[D": backward-word    # Alt+left
"\C-K": unix-line-discard   # Ctrl+K 
"\e\"": "@{}\e[D"     # Insert @{} move cursor into braces

Thanks to Antibaddy on Stack Overflow for help with the last one. Ok, we’re on track again. I’ll just update my .bashrc with the nice git bash extension, git-completion.bash.


mate ~/.bashrc

Sure enough, no tilde appears. I thought I could go back to .inputrc again to fix this. But the tilde is a dead key on my Swedish keyboard and it does not even seem to arrive to the Terminal when the option as meta is on. I never liked dead keys anyway but how can I get rid of them. When installing Ubuntu it is as easy as selecting a Swedish keyboard with no dead keys. Not as easy on the user friendly Mac… Can mighty Google help me. Not really. I found a couple a clues in the Apple developer notes, but it seemed to involve firing up XCode and hacking away at a brand new keyboard layout!

I’ll ask Stack Overflow again. Sure enough, a tool called Ukelele can be used. Just start it up, base your new keyboard layout on the one you are using, double-click on the dead keys, and terminate them. I got rid of all my dead keys and while I was at it I changed my umlaut (¨) to tilde (~) and vice versa. I type tilde quite often in comparison with umlaut and I’m wiling to make the mistakes I will make on a foreign keyboard.

Now I’m finally set to go. :)

Friday, December 19, 2008

The Y-Combinator

I finally found the time to grok the Y-combinator. There are already multiple examples available but I am to thick to get them and, therefore, wanted to derive it myself.

The Y-combinator is a wonderful piece of software that allows you to create self-referential programs without built-in support. That is, it allows me to create anonymous recursive functions. This is best shown by an example.

; The factorial function
(define fact
  (lambda (n)
    (if (< n 2) 1 (* n (fact (- n 1))))))

In the recursive function above the fact refers to itself by name. This relies on the name being available before it is actually defined. To avoid this we can send the function as a parameter to itself. Like so:

; Define a local variable g as the function.
; The function takes a function (itself) as an extra parameter.
; The function is called with itself as a parameter:  (g g 5)).
; This doesn't compile since the function h (that is g) requires 
; an additional parameter.
(let ((g (lambda (h n)
           (if (< n 2) 1 (* n (h  (- n 1)))))))
  (g g 5))

; The working version needs h to also call itself (h h (- n 1)).
(let ((g (lambda (h n)
           (if (< n 2) 1 (* n (h h (- n 1)))))))
  (g g 5))

We can now abstract over the h parameter with a technique reminiscent of currying.

; A new lambda is abstracted over h.
; Note that the function calls to g and h need to change ((g g) 5)) 
; and ((h h) (- n 1)) to ensure that they agree with the definitions.
(let ((g (lambda (h)
           (lambda (n)
             (if (< n 2) 1 (* n ((h h) (- n 1))))))))
  ((g g) 5))

We can now abstract over n and (h h) creating a new lambda with the parameters q and m.

; Function f is declared locally with the parameters q and m 
; and then called directly (f (h h) n).
(let ((g (lambda (h)
           (lambda (n)
             (let ((f (lambda (q m)
                        (if (< m 2) 1 (* m (q (- m 1)))))))               
               (f (h h) n)))))
      ((g g) 5)))

Notice that f is independent of it’s context and can be moved to the top level.

; f moved to the top level.
(let ((f (lambda (q m)
           (if (< m 2) 1 (* m (q (- m 1)))))))
  (let ((g (lambda (h)
             (lambda (n)
               (f (h h) n)))))
    ((g g) 5)))

I can now abstract over q to isolate the definition of fact.

; Notice that the inner function of f is the original fact function.
(let ((f (lambda (q) 
           (lambda (m)
             (if (< m 2) 1 (* m (q (- m 1))))))))
  (let ((g (lambda (h)
             (lambda (n)
               ((f (h h)) n)))))
    ((g g) 5)))


Now I abstract over the local variable f and declare a new variable Y. The call to ((g g) 5) is replaced (g g) and moved to the Y function instead.

; A new variable Y is created for the abstraction over f.
; The function call is moved to the application of Y.
(let ((Y (lambda (f)
           (let ((g (lambda (h)
                      (lambda (n)
                        ((f (h h)) n)))))
             (g g)))))
  ((Y (lambda (q) 
        (lambda (m)
          (if (< m 2) 1 (* m (q (- m 1))))))) 5))

Finally we replace the local variable Y with a the function Y, the Y-combinator.

(define Y
  (lambda (f)
    (let ((g (lambda (h)
               (lambda (n)
                 ((f (h h)) n)))))
      (g g))))

Excellent!

Monday, December 15, 2008

Thoughts on Simplicity

A scientific theory should be as simple as possible, but no simpler. —Albert Einstein

Do the simplest thing that could possibly work. Keep it simple by refactoring. —Kent Beck

If you think something is clever and sophisticated, beware: it is probably self-indulgence. —Donald Norman

Simplicity does not precede complexity, but follows it. —Alan Perlis

To make something generic is to make the simple things complex. —Adam Keys

Simple things should be simple. Complex things should be possible. —Alan Kay

Don’t EVER make the mistake that you can design something better than what you get from ruthless massively parallel trial-and-error with a feedback cycle. That’s giving your intelligence much too much credit. —Linus Torvalds

Consistency is Simplicity: A consistent approach to style and solutions can make code easier to maintain. —Ken Pugh

If you think you’re designing something for idiots, the odds are that you’re not designing something good, even for idiots. —Paul Graham

It is better to be wrong than to be vague. —Fred Brooks

Simplicity is the ultimate sophistication. —Leonardo da Vinci

If you want to make something 10 times cheaper, remove 90 percent of the material—Amy Smith

Wednesday, December 10, 2008

What is "declarative" anyway?

Declarative programming often seems – to me – as the holy grail of programming. But what does it really mean?

According to Dictionary.com

Declarative – serving to declare, make known, or explain: a declarative statement.

or

Declarative – a mood (grammatically unmarked) that represents the act or state as an objective fact [syn: indicative mood]

or

Declarative – making declaration, proclamation, or publication; explanatory; assertive; declaratory.

So, the word means explanatory or stated as facts.

In the context of programming declarative is usually contrasted with imperative and procedural, where imperative programming means programming by changing state and procedural programming means that a detailed algorithm is used.

Wikipedia states

Declarative programming is a programming paradigm that expresses the logic of a computation without describing its control flow.

or

Declarative programming attempts to minimize or eliminate side effects by describing what the program should accomplish, rather than describing how to go about accomplishing it.

So, in this context, declarative means without describing the control flow and without side effects.

Does this mean that I am programming declaratively when I am writing immutable object oriented code (without side effects) with fluent interfaces (explanatory)?

Or does it mean I am programming declaratively when I set up a large table, or even a database, of stated facts that I use to drive my application?

Or, who cares?

Wednesday, November 19, 2008

Report from Öredev day 1

Keynote with Ted Neward

The renaissance in development, according to Neward, is the renaissance of programming languages. The reason the renaissance is here is that the practitioners and the academics are, finally, working towards the same goal. Historically there has been downright hostility between them. This is because the academics and the practitioners are working towards different goals. The academics want to prove a concept while the practitioners wants to get work done. When the practitioners finally get what the academics have done the academics have left the project years ago.

Three forces work together to create the renaissance.

  • Virtualization – virtual machines allow programmers to ignore the low-level details and to focus on the real problem. The same is true for language designers.
  • Tools – IDEs, analyzers, debuggers, profilers, etc. are used by programmers and language designers use parser generators, AST generators, grammar debuggers, etc.
  • Linguistics – Functional languages introduce new ideas, at least to the common programmer. Languages become more diverse to conceptualize different constructs, not everything is an object anymore. We have functions, aspects, meta-object protocols.

Technical challenges of the next generation are for example

  • Concurrency
  • Security
  • Distribution and services
  • User interface expression

There are more languages than ever and it is easier than ever to create your own language.

5(2) aspects you’ve never heard about by Alef Arendsen

Started with a quick introduction to AOP for logging. AOP is about the three Ws: Where?, When?, and What?.

Before, a business service, log a message.

  • A pointcut is an expression for finding a number of joinpoints.
  • A joinpoint is a place where you can inject an aspect.
  • An advice is the code that is injected in the joinpoint.
  • An aspect is the combination of a pointcut and an advice.
  • Pointcuts should always be singular.

Aspect 1: Mixing Hibernate and JDBC usage

Hibernate uses transactional write-behind which will put the database and the cache out of sync. If I try to access the code via JDBC it will not get the correct data.

This can be solved with an aspect that flushes the cache to the database before a JDBC call is performed.

Before any JDBC operations flush the Hibernate session.

Aspect 2: Specific criteria should be applied based on orthogonal data.

I only want to get data from a specific location when performing a query.

Before a top level business service propagate location and after a top level business service delete location.

The advantage of this approach is again that it applies to both the Hibernate code and the JDBC code. It requires adding views to the database, but that would probably be a good idea anyway.

Dynamic Languages on .Net with J. Hartley

In five years we will look at compilation as the weakest form of unit testing.

Jim started out by saying that Ruby is not just simpler, but better :) Generics in C# is nice but it comes at a tremendous cost of obscuring the actual code.

IronPython supports Decorators to allow adding functionality through attributes. It will be supported in Visual Studio in 2009. An IronPython ScriptingEngine can be embedded into an application with a just a few lines of code.

What makes a programming language productive by Walter Bright

The D language is created by a diverse community of experts. It is a multi-paradigm language that supports c-style, OO, scripting, template metaprogramming, assembler, and functional programming. It is meant to replace C++.

The right way is the easy way. Work harder to do it the wrong way.

D supports simple template syntax. Header files are optional, type inference, foreach loops, reducing the source code with 30 percent compared to C++.

Diversity Challenges in Agile Teams by Aslam Khan

Writing software is cerebral but EQ overrides all IQ.

Leadership is taught to all, but followship is never taught.

Tuesday, November 18, 2008

Time for Smalltalk

Öredev is coming up and I’ll be giving a talk called Time for Smalltalk. The title of the talk is supposed to imply that the time for Smalltalk is finally here. I claim this since the publicity of dynamic languages like Ruby and Python has paved the way for Smalltalk. Only a few hardcore developers are still resisting the power of modern IDEs, so the barrier of Smalltalk adaption is considerably lower than it was a in the beginning of the eighties when Smalltalk first arrived.

The reason developers in dynamic languages should switch to Smalltalk is that the Smalltalk environment is alive. You are working inside a running system and instead of constantly trying to create new worlds, the Smalltalk way is to modify the world to fit your needs. This metaphor fits a lot better with the way good systems are usually developed. Start small and let the system grow incrementally.

The liveness property of Smalltalk also gives you the ability to refactor the code in a safe way. At runtime I can just ask the system in what classes a certain method is implemented and then I can let the system rename it as I wish.

Three of my new colleagues from factor10 Jimmy Nilsson, Aslam Khan and Lennart Ohlsson will also be speaking at the conference.

Saturday, November 08, 2008

What should be in an application 2008?

Listed here are features that I want in any application. The features are separate from the domain specific service that the application is designed to provide.

Search

The feature that I want more than anything is search. Everything should be indexed: menus, toolbars, dialogs, windows, selection boxes, shortcuts, help files, configuration files, application components, objects, scripts, the works! It should be possible to make generic full-text searches for anything matching my criteria, but it should also be possible to make specific searches by category or tag. It should also be possible to save the searches for later.

Search should also be available in all places possible. It does not have to be a search field, it can be a selection box or a textfield. It should preferably be integrated into the components to help me out whenever it is possible.

External tools should also be able to search. Tools like Google Desktop and Spotlight, and Launchers like Quicksilver and Launchy must be kept in mind when designing for search.

Tags

Anything searchable should also be taggable. It is possible that my terminology is different from the one that the application developers have. I may also want to group things together that does not appear related to anyone else. It should of course be possible to assign multiple tags to the same thing.

Scripting

Everything should be scriptable. Whatever is possible to do in the GUI should be possible to script. This lets me create my own automated tasks that I can re-use later or share with other users. It should be possible to run and create the scripts both inside and outside the application. The scripts should not be limited to use application functionality, they should be allowed to call operating system commands or other applications. The scripts will thus also serve as plugins for the application.

As with search it is important to have external tools like Quicksilver and Launchy in mind, but when it comes to scripting the scope is wider and you need to think about command line interfaces and other external applications too. Provide many entries to your application.

Shortcuts

It should be possible to assign shortcuts to any action available in the system. This includes saved searches, tags and scripts. Shortcuts should allow Emacs-style multi-key-shortcuts, such as Ctrl-C, Esc-V, M.

Persistence

It should be possible to save the state of the application at any time!. It does not matter to me that a form or that whatever I’m doing is an invalid state. Perhaps I like invalid.

It should be possible to save it anyway. It should also be possible to take snapshots at any time and to reset the application to a previous snapshot at any time. Preferably it should also be possible to compare different snapshots with each other in a useful way.

All in all I want persistence to work like a versioning system giving me the possibility to move through history at my leisure.

Export – Import

Exporting is just a different flavor of persistence. It should be possible to export (persist) the application data into some format that is useful to another similar application. This format should naturally also be importable.

Since exporting is just a flavor of persistence I naturally want versioning of my exports to. Perhaps it’s a good idea to just use git as a persistence engine?

Validation

I mentioned validation above on persistence. Validation is a valuable tool in an application but more often than not it gets in the way. The validation should not force me to enter data in a specified order unless it is absolutely necessary. It is good and even helpful to provide hints and markers along the way. But let me work the way I want to work and stay out of my way.

The important thing with validation is that it should indicate an error as soon as it appears but it should not force me to do anything about it until whenever I try to do something fatal such as, to quote Simon Peyton Jones, launch missiles.

Wiki

I find it really helpful to be able to link things together in Wiki style. The need for this is very dependent on the type of application but I find it very useful to be able to relate one item to another when I commonly need them together.

Conclusion

This list is by no means meant to cover everything, but I think it is a good starting point for anyone who want to make a useful application that can evolve with time.