Tuesday, January 18, 2011

Strings in Ruby vs. C#

In Ruby:
s1 = "string"
s2 = s1
s2 << "a"
s1.should == s2

In C#:
string s1 = "string";
string s2 = s1;
s2.Insert( 0, "a" );
Assert.NotEqual( s1, s2 );

Strings in C# are immutable. So trying to change a string actually creates a new string. So updating s2 does not update s1.

Strings in Ruby are mutable. So strings in Ruby act like pointers and s1 is updated when you update s2.

UPDATE 1/19/2011:
To be more clear, here are some more examples of how Ruby behaves:

s1 = "string"
s2 = s1
s2 += "a"
s2.should_not == s1

s1 = "string"
s2 = s1
s2.should == s1

Monday, January 10, 2011

Withholding Information

I read this blog post titled Team Trap #5: Withholding Information the other day.  It tells the story of a team brainstorming meeting in which the team is eliminating ideas.  When "Harry"'s idea is eliminated, Harry takes it as a personal attack and detaches from the meeting.  The author's take is that by withdrawing from the meeting and not saying anything about his emotional state to the team Harry is withholding information that the team needs to function well.
This sort of thing happens all the time. One member of the team feels like he’s not being heard, or isn’t valued and withdraws. The rest of the group goes on, discusses, makes decisions, starts to act. The team is missing out on the intelligence, creativity and participation of that member. They won’t have his buy-in for decisions, and won’t have his full-hearted support for action. When situations like this aren’t handled, relationship fracture and drains away. When you’re part of team, you need to be willing to say what’s going on for you, so that the team stays healthy and connected.
Now, if everyone took every opportunity to treat things as personal attacks and started telling the team how their emotions had been hurt we'd never get any work done.  But it is true that this kind of thing happens.  And it happens to everyone at one time or another.

That said, I think it's especially important for programmers to keep this in mind because we have a tendency to expect people to be rational, and we don't react well when they aren't.  People aren't machines, and if you're going to build a strong team it's important to remember that.

Also worth noting, "It's just business" is bullshit.  Work can't be done well without emotion.  But you do have to manage those emotions.  Yours, and everyone else's.

Tuesday, January 4, 2011

Learning to Focus

You can't program well, efficiently, and successfully unless you can focus.

The enemy of focus is distractions: your boss walking in, your phone ringing, your co-workers talking to you, emails, IMs, tweets, text messages.  These are distractions that actively steal your focus.  There are also distractions that you create yourself: reading Google Reader, Facebook, Twitter, and Reddit, talking to your neighbors, working on too many things at once, and so on.

These kinds of distractions need to be managed:

  • Turn off email notifications and check them less frequently.
  • If you are on IM, mark yourself busy when you're working.
  • If someone walks in or calls, tell them you need 20 minutes to wrap up.
  • Limit the number of things you are actively working on at one time.
  • Schedule breaks.
  • Expect to be interrupted.

The last two are especially important.  Scheduling regular breaks as in the Pomodoro Technique helps you to stay focused during your work periods.  When you know you have a break coming up its easier to put off answering messages, and reading crap on the internet.

Expecting to be interrupted by phone calls keeps you from getting frustrated when it happens.  It also means you have to work in small increments and keep note of where you're at so when you do get interrupted, you can get back into it more easily.

Hard Work

This is all fine and good, but at the end of the day the hardest part of focusing is that it is hard work.  When I first attempted the Pomodoro Technique I couldn't believe how hard it was to work for 20 minutes straight.  I had no idea how often I was allowing myself to be interrupted, by active interruptions like phone calls and people talking to me, but mostly by interruptions I created myself like reading crap online and talking to other people.


Another important element of staying focused is you need to know what you're working on with enough detail to actually DO SOMETHING.  This shows up in Getting Things Done, when it talks about managing your tasks it recommends you write down both the task and the first actionable step to completing the task.  There is a somewhat subtle but important distinction there.

Focus vs. Interruption Roles

Focus gets very difficult when you have different job responsibilities too.  For example, if you are expected to program and manage a project.  Programming is a role that requires you to be "in the zone", "in flow", "plugged in".  In other words, focused.  But managing a project is an interruption driven role.  Answering peoples questions, meetings, reviews.  Interruption driven roles don't work well with focus driven roles.  To make this work, you have to find ways to set aside time to focus without skimping on your interruption requirements.

Value Your Focus

But no matter what your role is, its absolutely crucial that you understand the importance of focus and that you take your own ability to focus seriously.