Wednesday, 21 January 2009

You can't make everyone happy, so don't try too hard


My personality type according to Myers Briggs, sees life as a series of constant battles. In the past that was the case. With age and a pinch of wisdom, that is no longer the trend.

Since this is my professional blog, I'd like to discuss the idea in the context of the workplace and your place in your organisation.

First thing, no one respects a yes man. That is a rule. Remember it.

Having an opinion is always good. You don't always have to voice it all the time but having one is essential. Shutting up is a skill. Learn it.

So how do you balance the need to speak out and at the right time close the gate between the your brain and your mouth?

I'm an extrovert and this is something I've constantly struggled with. Even after ten years of practice, there is no easy answer. I do however have a good handle on being myself and not spending too much time pleasing everyone. There is the saying that "you can not please all of the people, all of the time" and this is true but that doesn't mean you should quit and sit passively by, pretending this is not happening.

Here is how I think you can do this...

Count to Ten

Take your time to form your own opinions. Listen to others who you respect. Think about what you respect and like about their ethos and adopt those things as your own with your flavour. Through discussion, reading and contemplation, form your opinion about things conceptually before being in that actual situation. If a whole complex situation is too much then work with parts of situations.

Don't jump up and voice an opinion on something to the room if you have not thought through what is about to come out of your mouth.


Admit you are wrong, if you are

Often people voice an opinion and stick to it purely out of pride. If you do get it wrong then learn to admit you are wrong. There is nothing wrong with changing your opinion and telling people, if what you think now is different and improved. People will respect you if you are humble enough to admit you a wrong. Don't be too humble though.


Shut Up Already


When you have said your piece and articulated what you think then stop.

Do not make the mistake of saying something over and over again with the assumption that they aren't agreeing because they simply don't understand. Sometimes, people just don't agree with you, for whatever reason. Say what you have to say and then stop saying it.

Give the person you are talking to, time to digest what you have expressed.


Don't try to please only your Managers

One thing I have seen of late is people who state an opinion just to show their bosses that they agree. Managers are not idiots. Ok, some are but if they aren't then they see right through you. If your opinion is an exact parrot of your superiors then all that you will gain is a Mr Burns and not the respect you may crave.

Pleasing only those above you also wins you no friends. I've worked in environments where the rule was to "kiss up and kick down". There is only so far you can go with that war cry. Remember to consider how what you say will filter the views of those around you. All people matter. Not just the ones who decide your pay rise.


If you follow those four rules, you will find that you will be fine. Interpret them how you will but find your voice. Your own voice. Learn when to use and when not to.

Sunday, 18 January 2009

Disabling Enter Causing Submit with jQuery


Recently I was asked to disable the submit event being triggered when the enter key is hit in a textbox input. This is for an ASP.NET MVC application. That means that including this in the site.master will allow identical behaviour across the entire web application.

When you hit enter, the focus will move to the next textbox.

There is also browser sensing code since Firefox needs a different event bound.


jQuery(document).ready(function($) {
   textboxes = $("input:text");

   if ($.browser.mozilla) {
      $(textboxes).keypress(checkForEnter);
   } else {
      $(textboxes).keydown(checkForEnter);
   }

   function checkForEnter(event) {
      if (event.keyCode == 13) {
         currentTextboxNumber = textboxes.index(this);

         if (textboxes[currentTextboxNumber + 1] != null) {
           nextTextbox = textboxes[currentTextboxNumber + 1];
           nextTextbox.select();
      }

         event.preventDefault();
         return false;
      }
   }
});

Friday, 16 January 2009

Rabbit Hole Day


On Lewis Carrol's birthday, change your blogging style for a day.

"January 27th is the birthday of Lewis Carrol, author of ALICE'S ADVENTURES IN WONDERLAND. Alice fell down a rabbit hole into a place where everything had changed and none of the rules could be counted on to apply anymore. I say, let's do the same: January 27th, 2005 should be the First Annual LiveJournal Rabbit Hole Day. When you post on that Thursday, instead of the normal daily life and work and news and politics, write about the strange new world you have found yourself in for the day, with its strange new life and work and news and politics. Are your pets talking back at you now? Has your child suddenly grown to full adulthood? Does everyone at work think you're someone else now? Did Bush step down from the White House to become a pro-circuit tap-dancer? Did Zoroastrian missionaries show up on your doorstep with literature in 3-D? Have you been placed under house arrest by bizarre insectoid women wielding clubs made of lunchmeat?"

Sunday, 11 January 2009

TDD Objective-C : Testing a Cocoa Framework Project

My intention is to write an iPhone application that does something simple, just so I can learn how they are designed, built, tested and deployed. The first step is to design the core functionality that the application will use. For that, I am creating a Cocoa Framework, which is a class library. This project will be test driven.

This describes how I created a Cocoa Framework project and the accompanying unit tests.

Operating System: Mac OSX 10.5.6
IDE: Xcode 3.1.2
Language: Objective-C


Creating a Cocoa Framework Project and Test Target

1. Start Xcode;
2. Go to File -> New Project... and create a new Cocoa Framework project named MyApp;
3. In this MyApp project under Targets, Add -> New Target... of the type Cocoa Unit Test Bundle called MyAppTests.

Making Your Target Dependent on the Main Executable

"When you configure your test target, you need to decide how you want that target to behave. The unit test bundles that come with Xcode can be integrated with your executable in one of two ways. One technique is to configure your test target as a separate entity that you build and run independent of your main executable. The other is to add dependencies to your target that automatically build your executable and run the tests each time you build." -- Xcode Help

I've chosen to run the tests every time I build the framework project, so I followed the steps on this Xcode Help page: To make your test target dependent on your framework project.

Here is a summary of how to make a Cocoa Unit Test Target dependent on your Cocoa Framework by establishing the dependency in your Xcode project:

1. Select your MyAppTests target;

2. Open an inspector for the target;

3. Select the General tab;

4. Add a dependency to the test target by clicking the + button and selecting the framework target MyApp from the list;

5. Select your Unit Test Bundle target;

6. Open an inspector for the target. To get an inspector on a project, just control-click on the test target and choose Get Info. The resulting window is referred to as an inspector. Typing Command-I does the same thing;

7. Set Build -> Linking ->Bundle Loader to $(BUILT_PRODUCTS_DIR)/MyApp.framework/MyApp;


Create a Test Class and a Failing Test

1. Control-click on the MyAppTests target and choose Add -> New File...;

2. Create a new Objective-C Test Case Class and name it MyAppFunctionalityTests. Two files will be created - MyAppFunctionalityTests.h (the declaration) and MyAppFunctionalityTests.m (the definition);

3. In MyAppFunctionalityTests.m, add a test method like this:


//
// MyAppFunctionalityTests .m
// MyApp
//
// Created by Damana Madden on 10/01/09.
// Copyright 2009 __MyCompanyName__. All rights reserved.
//

#import "
MyAppFunctionalityTests.h"


@implementation
MyAppFunctionalityTests

- (void) testThatThisIsTrueForThisCase
{
STAssertTrue(false, @"oops it didn't work.");
}
@end

4. To run the test, build the MyAppTests target. You will see this test fail.

Important: All tests must be prefixed with the word 'test' or they will not be picked up and run.

Thursday, 8 January 2009

You should blog on Ada Lovelace Day


Join a bunch of us in pledging to write a blog post on Ada Lovelace Day about a woman in technology who you admire. It's happening on the 24th of March, 2009. You can even follow the goings-on through Twitter by following @FindingAda.

Sunday, 28 December 2008

Don't Tweet Drunk


The latest meme on Twitter is for twitterers to blog about Twitter and then tweet it so that it can be retweeted. We all sit around and read it and retweet in agreement or scroll on with a little bit of passive aggression.

Since I'm an individual just like everyone else, here is my Twitter post of choice. It addresses the eternal question asked by those outside the twitterverse about what this is all about - What is Twitter and why should I use it?

My first response to that is usually that you don't have to use it. You could go on for the rest of your life not using Twitter and not feel as though you have missed anything. On the other hand, if you do try it out then there are a few things you will experience and gain that are not so easy to list out and debate over Chinese food. These things are additive, like MSG. They add flavour but some people may not react well to it.

Networking
This is networking in whatever sense you want. If there something that you are in to then there are micro-groups on Twitter that share in your passion and will not hesitate to help or support you with your common pursuit. If you want to connect with people around the globe who can encourage your "thing" then Twitter is your forum.

I use Twitter to network with geek girls; software engineers, ThoughtWorkers; friends around the world; and family.

Reading
I use Google Reader less and less to find things I want to read when I'm not rushing around and have time to stop. Instead I steadily open in my browser the links that people tweet about that sound interesting to me. These are sometimes things they produce but most often are links to other places on the 'net. From this I find new things to read and subscribe to that I would not have found on my own in the lifetime of the universe. The Interblag is a big place and following people with common interests can introduce a new source of information to the pool you have already collected.

Thinking
I often find it useful to share my thoughts with people on Twitter and then discuss them in order to articulate what I think. There are many intelligent and switched on people out there who will actively discuss things with you.

Yeah, it is nice to talk about what you are thinking at the time but the coolest part is listening to interesting people bring up ideas that make me you think. Ideas that challenge your own thinking. Ideas you may never ever agree with but are willing to listen to because it's not being shoved down your throat.

On this point, you must be very careful not to get caught up in group-think. This is very easy to do on Twitter. People do complain regularly that there is too much of this on Twitter and that us being to nice and cuddly towards each other is killing original and critical thought. I do see the danger but also believe that an encouraging environment that allows you to test your assumptions and be wrong without fear of the fail whale pushes creativity and individuality. That in itself can overcome the memes that drift in and out of this growing nest of communities and networks.


Twitter is not for everyone but there is a place for you if you choose to follow. It's something different to every person. For all I've expressed here, there will be someone who sees it differently and that's just Twitter.

Try twitter. I recommend it.

Tuesday, 9 December 2008

Learning about Testing ASP.NET MVC


Working on my first commercial implementation of ASP.NET MVC Beta has been rewarding and frustrating to almost even degrees. Learning to test the MVC framework after hearing the promises of Microsoft and the choir has proven that it is still young and the road is long. It feels like being back in .NET 1.1 land again but as an eternal optimist, I see that as meaning that ASP.NET MVC has a promising future. As promising as C#, which had humble beginnings.

Abstracting the business value and corresponding actions in to the C part of MVC has meant that the code behind an ASP.NET Page is reduced to nothing more than specifying the type of model that the strongly typed View uses. That solves an enormous amount of problems that came out of the pre-ASP.NET-MVC world. In particular the classic-ASP-like tendency to put all logic straight in to the events in the code-behind with little to no abstraction. Since you can not instantiate a Page object outside of the ASP.NET framework, it was impossible to unit test the controlling logic in the code-behind. When I have walked on to a project and seen the 3000 lines of code nested in page events, I knew it was almost impossible to safely refactor let alone extend the functionality. All changes in that case had to be additive and in no way morph logic so that nothing legacy would be broken.

The ability to test Controllers has pushed that code out in to a testable .NET class that can be instantiated independently of the framework and then easily tested. That's brilliant if you weren't already doing that but most of us were. I do commend Microsoft on forcing some sort of design on to us but as usual it's all mechanism and no policy. It's another easy way to say "put it all here" but also test it.

What I want to see out of future ASP.NET MVC releases is the ability to test Views with simple xpath searches and annotation validators on Models that feed through to the View. Yes, it's not there now but it will be soon as we can see in MVC Futures. This is not a case of Microsoft missing the point at all. They just have to release something and then they will add to it. They have shown their responsiveness to community feedback. If only they wouldn't refer us to stackoverflow.com.

From the conversations we have had with Microsoft, they have started by saying that it's only the Controller that needs testing and that Views should be tested by a UI testing tool like Selenium and that models have accessors only so don't worry about them. There is then the realisation that testing your View as an abstract concept is not a bad one since it is faster and most efficient than using the UI tools with their overhead (even headless). It certainly will let us test state more efficiently. As for models, validation is so important that the lack of access to annotation validators has resulted in an excess of JavaScript (beit jquery) in our application and I'm not convinced that is a good thing yet. Maybe that's my C# bias kicking in.

I for one am looking forward to the MVC futures becoming MVC present. Until then, all the positive parts of this new framework like the ease of integration of the Model, View and Controller make up for all the things I still want. It saves me the time I used to spend on implementing MVC in the old world.

This leaves me extremely optimistic about the future of .NET web development. Until then, let's do our best to avoid the fat Controller.

Acknowledge Me

Apple started a user experience trend many iOSes ago when it accepted Settings changes and did not ask for confirmation. Once the chang...