Monday, June 22, 2009

Markdown

Markdown is a simple syntax for writing text documents. It is better than HTML since it does not contain as much clutter. HTML may be used in a Markdown document but block level elements must be surrounded with blank lines.

Headers

Headers come in two types.

  • Underlined headers, =====, and -----
  • Prefix headers, which uses # as prefix, # = h1, and ### = h3

Emphasis

  • Emphasis can be shown with * or with _ .
  • If you double them up they will become strong instead ** and __

List

  • Unordered lists are indicated with *, + or -
  • Ordered lists are indicated with number followed by period, 1.

Lists may be span several lines and may also use hanging indents. To wrap the list items in paragraphs simply leave a blank line between item lines.

Blockquotes

Blockquotes are indicated by prefixing lines with >. They may be nested > > . If you only prefix the first line in a paragraph, everything up to the next blank line will be part of the blockquote.

Code

Markdown produces literal markup if the lines are indented with one tab or four spaces. This kind of code will be wrapped with <pre><code>

Lines

Lines may be indicated by putting three or more asterisks (***) or hyphens (---) on a line by itself.

Links

Markdown support both inline and reference links.

Inline links

  • Absolute [text for link](http://url.to.site)
  • Relative [text for link](relative_url)
  • With title [text for link](relative_url "my title")

Reference links

  • [text for link][anders]
  • Same text and id [anders][]

The referenced link ids must be defined somewhere else in the document like this:

[anders]: http:/anders.janmyr.com "Optional title"

The link definitions are inserted into the actual links and removed after the page is processed.

Automatic links

URLs surrounded with angle brackets <> are automatically inserted as links this may be used both for links and email:

  • <anders.janmyr@email.com>
  • <http://anders.janmyr.com>

Images

Images are inserted with link syntax, preceded with an exclamation point !.

  • ![Alt text](/path/to/img.jpg)
  • ![Alt text](/path/to/img.jpg "Optional title")
  • ![Alt text][id]

Escapes

Most of the Markdown special characters such as * and - may be escaped by preceding them with a backslash \.

Monday, June 08, 2009

Ruby Method Lookup

There are three different kinds of methods containers in Ruby, Classes, Modules and Singleton Classes. When a method is invoked all of them are searched for the first matching method to execute.

A class may contain methods

class Mammal 
  def breathe
  end
end

A class may inherit its methods from one other class.

class Tapir < Mammal
end

A class may also mix in methods from several modules.

class Tapir 
  include Swimmable, Runnable
end

Methods may also be defined on the object itself, this is actually the anonymous Singleton Class that is available to every object.

kjell = Tapir.new
# kjell can not only swim, he can crawl
def kjell.crawl 
end

So what happens if all these different method containers define the same method? How will the interpreter know what to execute?

When a method is called:
  • The Singleton Class is searched. —the anonymous class of kjell
  • The modules included in the Singleton Class is searched. —in this case none.
  • The class is searched. —this is the Tapir class
  • The modules included in the class is searched in reverse order of inclusion, the modules override each other as they are included. —Runnable, then Searchable
  • Then the search continuous in the superclass of the class and the modules included in it.
  • If the search reaches the top of the hierarchy and no method is found, method_missing is invoked on the initial object and the search for method_missing follows the same path.

That’s almost it. There is one caveat. If the Singleton Class is a meta-class, that is the singleton class of a class, then the class belongs to a meta-class hierarchy that parallels the hierarchy of the normal classes. This allows for inheritance of class methods and gives us the ability to override class methods such as new. The lookup path is changed to search the meta-class’ superclass after step two, before the class of the class (i.e. instance methods of class Class).

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.

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.