Monthly Archives: December 2010

Daily Stand-up Variations

During the last few years I did different kinds of stand-up meetings in Scrum and in Kanban teams. In this post, I’m going summarize the pros and cons I found in them.

The most common stand-up meeting style is the daily scrum. In this meeting, the ball or a stick goes around round-robin style. The participant holding the token tells the team what she did yesterday, what she will do today and what blocks her from continuing her work.

  • Pros:
    • Well documented methodology
    • Works fine for beginner teams
    • Works fine for small teams (4-6 people)
  • Cons:
    • Gets boring after a while, people may pay less attention after a couple of months
    • The information content of the tiny monologues decreases over time
    • The blocking issues are usually forgotten, or handled with less priority
    • Usually, the scrum master has to ask about blocking issues directly in order for them to be discussed
    • The three questions give the possibility to talk about activities outside of the team, which aren’t relevant in 4 cases out of 5

A less common variant is when people talk about the tasks, not about themselves. Go task by task from right to left, top to bottom – this is the priority order. First, talk very shortly about finished the items, then about the ongoing ones, and if there is some time left, talk about the upcoming items.

  • Pros:
    • More focused discussions
    • People pay more attention to the task details
    • Less unnecessary discussion
    • Works fine for large teams (7-10 people) as well as for small teams
    • No more round-robin style
    • If someone has nothing to say, that means that she did work outside the team, which is a waste from the team’s respective. If this happens regularly, it must be handled.
  • Cons:
    • The blocking items still get less focus
    • If someone from the team has lots of duties outside of the team, she will feel frustrated because she cannot tell the others what she is doing
    • Needs more time to learn and adapt to

Kanban teams tend to talk about only those tasks which are blocking the flow of the value stream.

  • Pros:
    • Real focus on the blocking items
    • Works with very large team setups (10-40 people)
  • Cons:
    • Does not favour team work. If one does not talk about the ongoing tasks no one can join in on that particular task
    • Requires a lot of experience, not recommended for beginner teams

Based on the pros and cons, I finally found the setup which works quite well for one of my current teams and for me:

  • Start with the blocking tasks from the parking lot, tasks with stop signs and tasks from the impediments column
  • The team should try to solve them on their own, and immediately escalate when the issue has gone out of the team’s reach
  • Continue with the tasks from right to left, top to bottom
  • Talk about activities outside the team, and about general issues
  • Optional design or task related discussion after the stand-up meeting

This kind of setup needs a one or two week long learning curve, because although most of the blocking issues can be solved by the team, the discussion takes some time and, by the book, we have 15 minutes for the whole thing. This method works well for middle sized teams with 7-11 people, too.

VN:F [1.9.17_1161]
Rating: 6.7/10 (3 votes cast)

Testing the Stack Implementation

I’ve created my own version of the exercise used during my first agile job interview in order to compare it to the result of the pair programming session of the job interview. The exercise was quite simple: implement a stack, and store the values in an array. The implementation is pretty straightforward, the code is available on github. One can ask: why an array, why not using the collection framework? The answer is simple: just for fun, and just for the exercise :-)

In order to store the necessary amount of values, the internal array needs to be enlarged from time to time. There is nothing wrong with this so far. But in order to avoid unnecessary memory loss, that internal array needs to be shrunk as well. The first version of my Stack implementation lacked this functionality. The user stories of the functionality request can be:

  • As a developer, I don’t want to reserve more memory for my stack implementation than necessary
  • As a customer, I don’t want to lose values after shrinking the internal container

The second user story is very straightforward, so let’s focus on the first one. User stories and previous test cases are available, so far so good, but how to test the user story? An even better question: how to write a test case first? I consider my Stack implementation as an end product, and as such, I believe that it should follow the encapsulation object oriented programming principle, and it shouldn’t be difficult to use. An obvious choice would be a reflection-based solution, but since I’m not a great fan of reflection, I started to test the code from different angles.

For better understanding, here comes the code being tested:

    private void shrinkContainerCapacity() {
        int[] extentedContainer = new int[container.length - 10];
        System.arraycopy(container, 0, extentedContainer, 0, container.length - 10);
        container = extentedContainer;
    }

The first user story suggests memory handling, so first let’s try out this angle. Memory usage can be checked with the following methods:

Using those methods I wrote this test case sketch:

    @Test
    public void shouldUseLessMemoryAfterShrinkingInternalContainer() {
 
        for (int attempts = 0; attempts < 15; attempts++) {
            for (int i = 0; i < 10000; i++) {
                stack.push(i);
            }
 
            long availableMemoryBefore = getAvailableMemory();
            for (int i = 0; i < 10000; i++) {
                stack.pop();
            }
 
            long availableMemoryAfter = getAvailableMemory();
            assertTrue(availableMemoryBefore < availableMemoryAfter);
        }
    }
 
    private long getAvailableMemory() {
        System.gc();
        System.runFinalization();
        System.gc();
        System.runFinalization();
        long totalMemory = Runtime.getRuntime().totalMemory();
        long freeMemory = Runtime.getRuntime().freeMemory();
        return totalMemory - freeMemory;
    }

I’ve executed the test case several times and it never turned red. I was curious why, because it supposed to be work, isn’t it?

The javaDoc of System.gc() and System.runFinalization() states that: “…the Java Virtual Machine has made a best effort…“. Additionally Java Virtual Machine implementations may differ on operation system level: “…The aim is binary compatibility. Each particular host operating system needs its own implementation of the JVM and runtime. These JVMs interpret the bytecode semantically the same way, but the actual implementation may be different.” (source: Wikipedia).

Adding these statements up makes me nervous. The whole situation – using memory measurements for testing – starts looking black for me, so I did some measurements using the test code from above with different Java Virtual Machine implementations on different operating systems:

  • Running with eclipse 1.6 jre on Ubuntu Linux
  • Running with oracle’s 1.6 jre on Ubuntu Linux
  • Running with jrockit 1.6 jre on Ubuntu Linux
  • Running with oracle’s 1.6 jre on Windows XP

I’m interested how the assertTrue(availableMemoryBefore < availableMemoryAfter) will turn out in the different scenarios, so I’m measuring the availableMemoryBefore and availableMemoryAfter values, and calculate the SIGN of their difference: if the availableMemoryAfter is greater than availableMemoryBefore the SIGN will return 1, which is equal to a true test case and a green bar. In other words, after shrinking the array, the Stack uses less memory. Mission accomplished sort of say.

Before evaluating the results I have to note two things.  I’ve executed the test cases several times and I didn’t find any difference in their outputs, that’s the reason why I have only one measurement sheet for each case. Additionally I sometimes have the feeling that there is a slight difference when I’m running a java application/test case from eclipse and from command line using oracle’s jre, therefore I did the measurements with both of them separately. The detailed measurement values are available in this spreadsheet. Now the result:

Now my red bar is understandable. I’m using eclipse under Ubuntu Linux (and oracle’s jre), and according to the diagram above, there is less available memory after the first execution of the shrinking (again, I executed this particular measurement more than twenty times, and I always got the same result). If I had used jrockit, the problem above never would have turned out (the orange bars are always at 1, meaning that there is more available memory after shrinking in every case).

I would have stopped with the measurements here, unless my friend had asked me this: “Why did you have to call the System.gc() and System.runFinalization() twice?” It is a very good question. The more I call the System.gc() the more feasible is that the Java Virtual Machine will do garbage collection, which means that my application will use less memory, at least on paper.

Unfortunately experience shows otherwise. Have a look again at the javaDoc of System.gc(). In layman’s terms the System.gc() call is just a request to the Java Virtual Machine, and there is no guarantee that it will consider the call at all. According to my measurements below, the Java Virtual Machine considered it, but I had participated in a project several years ago, in which we had memory issues and no matter how often we called the System.gc() nothing really happened. The Java Virtual Machine felt that the time for garbage collection had not come yet, so it ignored our request.

So SIGN (before – after) looks this, when I’m calling the System.gc() and System.runFinalization() only once:

 

In this case I would still see a red bar with my setup, in several cases (7, 9, 11, 13 and 15) the SIGN is 0, meaning that the amount of available memory is the same before and after the shrinking. After having a close look there isn’t any option, which would make my bar green. I feel like I’m getting somewhere: checking memory usage as validation is not that promising as it was before I started measuring it. Let’s see the result without any System.gc() and System.runFinalization() calls in order to finish my measurements and provide more data for evaluation:

 

The result is not deterministic at all. Now I’m 100% sure that checking the memory is a dead end for me. I cannot garantee that my shouldUseLessMemoryAfterShrinkingInternalContainer() test case will produce the same output every time. Someone can use a different kind of machine for test case execution – for example Solaris, on which I didn’t do any measurement at all -, or can change my getAvailableMemory() helper method and execute less or more System.gc() calls. Unfortunately I need a different approach.

The next thing worth having a look at is injecting the array copy functionality. Unfortunately, the System.arraycopy() method is static, so I have to wrap it up, and inject the wrapper class into my Stack. The Stack is considered an end product, I cannot let the user take care of the dependency injection by herself, so I need a factory to do that:

public class StackFactory {
	public Stack create() {
		return new Stack(new ArrayCopyWrapper());
	}
}
// ...
public class ArrayCopyWrapper {
    public void arraycopy(Object src, int srcPos, Object dest, int destPos, int length) {
        System.arraycopy(src, srcPos, dest, destPos, length);
    }
}

First let’s see the effect of this modification on the test code:

    @Test
    public void shouldShrinkInternalCapacity() {
        FakeArrayCopyWrapper arrayCopyWrapper = new FakeArrayCopyWrapper();
        stack = new Stack(arrayCopyWrapper);
 
        arrayCopyWrapper.setExpectations(0, 0, 10);
        for (int i = 0; i &lt; 20; i++) {
             stack.push(i);
        } 
 
        // Had to cut the for() loop in half
        // In order to be able to set two expectations
        arrayCopyWrapper.setExpectations(0, 0, 20);
        stack.push(20);
 
        // The same reason here
        arrayCopyWrapper.setExpectations(20, 10, 1);
        stack.pop();
 
        arrayCopyWrapper.setExpectations(20, 10, 15);
        for (int i = 20; i &gt;= 5; i--) {
           stack.pop();
        }
    }

I didn’t want to spend too much time on setting up and using mock libraries. I had the strange feeling that I didn’t have to put too much effort into this angle. A simple fake object will be just fine:

public class FakeArrayCopyWrapper extends ArrayCopyWrapper {
    private int srcPos;
    private int destPos;
    private int length;
 
    public void setExpectations(int srcPos, int destPos, int length) {
        this.srcPos = srcPos;
        this.destPos = destPos;
        this.length = length;
    }
 
    public void arraycopy(int srcPos, Object dest, int destPos, int length) {
        assertEquals(this.srcPos, srcPos);
        assertEquals(this.destPos, destPos);
        assertEquals(this.length, length);
    }
}

Although I wrote the shouldShrinkInternalCapacity() and FakeArrayCopyWrapper class, I don’t like them too much. The test case is complicated and the Fake is strange.

Additionally, when someone wants to instantiate my Stack she must do this:

Stack stack = new StackFactory().create()

But, this version seems to be more user friendly:

Stack stack = new Stack()

The first version is good for internal classes, but personally I don’t want my users to do complicated things like using wrapper factories for creating an object, when there is an easier way.

However there is one more thing. The ArrayCopyWrapper wraps only the System.arraycopy() call. If I executed a code coverage measurement using the shouldShrinkInternalCapacity() test case, the measurement would indicate that the shrinkContainerCapacity() method is 100% covered with shouldShrinkInternalCapacity() test case. This is not true. The current version of shouldShrinkInternalCapacity() does not test the command below, because it focuses only on the arraycopy:

    private void shrinkContainerCapacity() {
        //...
        //...
        container = extentedContainer;
    }

One can argue that the line above is indirectly tested by the other test cases.  This is true, but I would like to have focused test cases and correct coverage data.

This solution is not user friendly and I had to do things in testing which I don’t really like. This approach is another dead end for me, at least.

The last thing I can think of is checking the size of the internal container. I have the following options:

  • make it protected
  • create a protected method for getting its size
  • use reflection

The first two options harm encapsulation, which I have no intention to do, so another dead end.

I had no other option but to do the testing with reflection. I don’t like the current state of the test cases, but I have no other ideas. So I’m going to leave this post open, feel free to submit other ideas on how this feature can be tested. The code is available on github, and any suggestions and comments are welcome.

VN:F [1.9.17_1161]
Rating: 0.0/10 (0 votes cast)

The First Agile Job Interview

In one of my previous posts I was writing about a different kind of job interview. Today, I had the possibility to perform my first agile job interview, and although I only got twenty minutes, it was very well spent.

For this twenty minutes, I planned a pair programming session with the candidate. I planned the following exercises. TDD was optional in this case:

  • Implement a stack which stores the values in an array. This particular stack shall have the pop, push and size features (for more about this exercise, refer to this page)
  • Implement a small application which consists of two classes; an emitter and a consumer. The emitter pushes elements into the stack, and when the consumer can access the stack, it pops the whole content, calculates an average and prints it out. The emitter shall push random numbers on the stack, and sleep for a random number of seconds. The consumer shall constantly poll the stack for items by popping all available elements, sleeping for a random number of seconds in between. When the emitter pushes a -1 onto the stack, it shall finish, and so shall the consumer. The average calculated by the consumer shall not contain the -1 value.

A possible implementation of the exercises is available on github. For more, on the examples above, refer to this post.

The first exercise is designed to check the team work and agile abilities, and the second one is designed to check how the candidate can solve a programming problem: in this case, race condition and Java threading.

During the twenty minutes we did the first exercise, and afterwards discussed the design of the second one. The goal was not to check how well the candidate knew the Java language, and how many details she could tell me. I just wanted to know easy or difficult it would be for me to work with her. As I said, the technical details can be learnt, but companies shall look for people who can work in teams and who can work with others. Pair programming is one of the most difficult XP techniques and if someone can do it with a stranger – that would be me -, then she can do it with others as well.

Here are the things I paid attention to during the session:

  • How are the design discussions going during the session?
  • Does she have the courage to be a partner in the discussion, or does she just follow my lead?
  • If I show something new for the candidate, can she use it later?
  • How long does it take for her to realize that a certain design decision is good or bad?
  • How does she test the code?
  • How often does she execute the test cases?
  • Does she care about clean code?
  • What kind of coding conventions does she follow?
  • Are the answers given by the candidate during the regular sessions still relevant?

My colleague and I learnt more from the discussions during the pair programming than from the discussion we had to perform based on a checklist. There is a huge advantage here. If people are focusing on the exercise, they are more likely to behave as they do during the working days. They will leave the stress and preparation for the regular interview behind. Due to confidential reasons I cannot quote the exact situation, but I can give you a similar example. During the regular discussion the candidate mentioned that she lacks a certain skill. During the pair programming session, I made a situation in order to see if indeed this was the case, or the candidate had just been modest. It turned out that there was no lack of it that skill at all, it was just stress that made her say that there was.

Being agile is not equivalent to be good at pair programming. There are other areas worth talking about:

  • Previous work/study experiences, focusing on the team work and the candidate’s situation in it
  • Ask about the recent events of the technologies or tools the candidate mentions in her CV. If she follows them, you can be sure that she takes the craftsmanship seriously

An interview scheme example:

  • Have a warm-up discussion with the candidate
  • Give a short introduction to the candidate about what will happen during the interview, because this is something new, and you can learn a lot from their reaction
  • Talk about previous team work and recent events
  • Have an at least one our long pair programming session. If possible, use a projector so that the other interviewer can also see it
  • Talk about administrative and HR-related matters, like working time, salary etc, at the end of the interview not before

The last step may require some explanation. During this particular part you may talk to the candidate about administrative details, which may consume some time unnecessarily. The salary is a different kind of animal, but I recommend to talk about it at the end with one exception, but let’s talk about it a bit later.

The salary is a sensitive question. If it is discussed at the beginning the candidate will tell a salary without knowing what is the position about. For example she tells a number, but afterwards she realizes that she would like to get more for that kind of job. In this case she has no possibility to change her mind, and she may continue look for other opportunities at other companies. If you – the questioner – provides the number in advance, the candidate may have that number in her head during the whole time, and her focus might be lost. Possibly every answer may be provided knowing that number. I found one exception. We had a heavy weight candidate, and my partner realized that she may have different kind of salary in her mind than us. He changed the steps, discussed the salary details, and the interview was finished in half an hour. My partner saved the candidate and us some time. This requires experience, but it will come with time.

If you have the possibility, try it out, and share your experiences using the comment section.

VN:F [1.9.17_1161]
Rating: 10.0/10 (1 vote cast)