Statistics

Total Posts: 34
This Year: 0
This Month: 0
This Week: 0
Comments: 160


RSS 2.0

Recent Posts


On this page....

An idea of how to get a common view of Clean Code amongs developers
The truth vs. the truth
Recap from Øredev 2008
A very unpleasant awakening...
The Running Mate - The geometry calculations
The Running Mate - Code available at Codeplex
Performance Talk at Swenug in Göteborg
The Running Mate – What is it and why?
The Running Mate - An Introduction
File based vs. wiki based documentation. part 2

Archives

 Full Archives By Category
 2007 Calendar View

Categories


Admin

Sign In

Acknowledgments

DasBlog Theme Design by: Tom Watts
E-mail: Send mail to the author(s)
Theme Image by: dreamLogic

Disclaimer

The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

 Saturday, January 31, 2009

At Øredev in November 2008, I got the opportunity to listen to Robert C. Martin, also known as Uncle Bob. I have been a fan of his work for many years ever since I read his book Agile Software Development Principles, Patterns, and Practices. A few years later when the C# version came out I took the opportunity to reread many of the chapters. To me, that book became a eye opener to a new way of working with code. And I think I am not alone. For instance, it seems to me like much of the ALT.NET movement gets a lot of inspiration from topics found in this book. Like for instance the excellent description of the 6 design principles, now commonly referred to as S.O.L.I.D.

Anyways, in 2008, Robert Martin came out with a completly new book called Clean Code: A Handbook of Agile Software Craftsmanship. Naturally, Clean code was his chosen topic at Øredev for both his keynote and the session on Functions (chapter 3). Robert Martin proved to be a passionate speaker so I was not disappointed. Neither have I been disappointed in this new book so far. Since Øredev I have read about half the book and I truly feel that it is a gold mine to read for any professional developer.

But I kind of stopped reading a couple of weeks ago since I had this great idea. But before I tell you what, I’ll tell you why. That’s usually a good start.

The big WHY

The concept of “Clean” is often defined per developer

This is a bit unfortunate but my experience is that we developers all have different opinion as to what clean code really is. We all get our little habits and our own way to keep our code clean and readable to ourselves. It happens that we shun the sight of other people’s code since it simply is not clean. As in our definition of clean that is.

If only, we could keep our noses glued solemnly into our own written code. Unfortunatly, this is not so.

The common code base

Professional programmers usually don’t work isolated from other professional programmers (although it happens). Most often you share a code base with others and you will have to dig into and work with other peoples code. This is usually where a developers' nose start sneering since, "no way, that code is clean!"

Imagine this sneering nose developers name being Robert. So what does Robert do when confronted with such ugly code? Well, he would probably sneak in a bit of refactoring of the code with the sole purpose of making it clean. That’s ok and quite normal for any programmer to do. So it should be ok.

The only problem is that when Joe, who originally wrote the code, wants to work again with the submitted, now clean, code, he finds the code to be … unclean.

What does Joe do? Well, you guessed right: refactor a bit back to “clean” state. With a big grin of proudness, Joe will resubmit the now clean code into the code repository.

Later when Robert comes back to this code, what does she do? Well perhaps refact............

Verbal Communication

Naturally, we developers aren’t idiots (although it may perhaps seem so occasionally to non-devs.) and we do have a mouth for other purposes than to shovel food and drinks into it. So in the end, Robert, or Joe, will walk over and talk to eachother. This is where the "big discussion" may start. What is clean and what is not clean code.

It may sound like it would be a heated and most dreadful debate. But I think most developers actually like discussing these things. As long as you are able to convince the other guy of how beautiful and logical your clean code is. However, most of the time, this agreement does not occur and the constant battle of Clean Code carries on.

In the end, developers may stay away from other peoples code since it is tainted by uncleanness.

The Contract

Naturally, the previous description is not a successful situation to have at a company. The code base must be shared for lots of reasons; work scalability and fresh influences to name a few. So many companies bring out code policies, written in a document for all developers to see and sign on. In blood. Code inspection tools, like FxCop, will run at night and report to everyone in the morning if someone has violated the signed contract of Clean Code.

Naturally, the contract has got to come from somewhere. There are a couple of different ways

A)     The company chief architect(s) brings forth the document for all developers to follow.

B)      All developers join in big battle lasting for days and come up with a final agreement.  

C)      The company borrows someone else’s contract.

Naturally, C) is the most common option. But there will always be room for B) and A) since there are domain specific stuff that still can be agreed upon.

The idea – the WHAT

At Admeta, where I work, we are using the Scrum project methodology and we are fairly agile in the way we work. We are using model C) as in the Microsoft conventions and guidelines and we also have a wiki page with further conventions agreed upon, i.e. B). We do not believe in the A) alternative.

So naturally when I began reading the book, it became clear to me that I would be doing an awful lot of referencing to the book when discussing clean code with my collegues. Very soon I thought, my colleagues would get very tired of both me and Uncle Bobs opinions (although they all heard him speak at Öredev) and tell me to put a sock into my mouth... What a dreadful scenario!!! So naturally, I was forced to get an idea. And thus it came to me one beautiful day:

The idea: So why not try to make everyone read the book and we will have a discussion for each chapter? I have previously been participating in a group doing exactly this at Dotway with the GOF Design Pattern book. To me Clean Code seems like a perfect topic and we could probably gain a lot as a company and individuals if we spend some time doing this together.    

The idea – the HOW

Said and done. I talked to my colleagues and every developer on the company has now joined. Everyone has got an own copy of the book (it’s actually very inexpensive) and we get an hour once a week on company time to do discussions. Reading is done on spare time, but hey: it is fun reading! Besides, each chapter is quite small and would take little time to read.

So this Thursday, we’ll have our first Clean Code discussion meeting. As a preparation, the meeting attendees will have to read Chapter 1 of the Clean Code book. I have also given them the following questions to reflect upon:

  1. Before reading, take a moment to reflect what the concept of Clean Code means to you.
    • Is there anyone of the different "guru's" description of Clean Code (p7-12 + forword) that do you think lies closest to your own definition of Clean Code?
    • After having read the chapter, has the reading changed your conception?
  2. What is your experience / opinion of code generation tools or any other higher abstraction level of programming (4GL)?
    • Do you have any good or bad experience of building your own code generator (in some way)?
    • Where do you think we are heading when it comes to abstraction levels in languages and tools?
    • Do you consider this to be a bright future for us developers?
    • extra: What do you think of Joel Spolskys described "Law of Leaky Abstractions"?
  3. Have you experienced something like "the Grand Redesign in the Sky" and how did that end?
  4. What is / has been your explanation to having written bad code (as we all have done!) in the past?
  5. Do you think it is suitable for us as a team to align to a "School Of Thoughts" (p12) or do you see any better path to having a more uniform clean code conception?
  6. What do you think of "the Boy Scout Rule" (p.14) applied to code?
  7. Are you familiar with any or all following Principles of Design (S.O.L.I.D.) (p15):
    • SRP - The Single Responsibility Principle
    • OCP - The Open / Closed Principle
    • LSP - The Liskov Substitution Principle
    • ISP - The Interface Segration Principle
    • DIP - The Dependency-Inversion Principle
  8. What do you think is the status of Clean Code at our company?

I think these questions will be more than enough to discuss for our meeting so we will probably end up choosing the most interesting ones to discuss. I am truly looking forward to it.

Btw, I'll be continuously posting my questions for each chapter on this blog. So stay tuned if you are interested.

Saturday, January 31, 2009 7:35:37 PM (GMT Standard Time, UTC+00:00)
 Saturday, January 17, 2009

Some 20-25 years ago as a teenager in School, a teacher once told me and the rest of the class the following metaphor.

Two persons look at a roof top and distinguish a bird sitting at top of the roof. The distance is far so it is difficult to see the details, but one of the persons suddenly says: "what a beautiful peacock!" The other one looks at him bemused and says "that's not a peacock. It's a rooster!"  Then the two persons burst into an argument on this matter which lasts for quite some time.  

What my teacher then told us is something important I think: Sometimes the truth is different for different people, but each version is still a truth. It is important to remember, and respect, that there may be different versions of the truth which are correct in their own way.

I have come to reflect upon the essence of this very often over the years and I feel I would like to write some fine grained aspects of it:

The truth is context dependent and it is not always absolute.

Both persons actually believe themself to be right, and in a fundamental way, they are therefore both correct. In order to understand this perspective it is vital to consider the context. The context in this example is quite complex since you must take into account things like eye sight capability and what the actual conception of what a rooster and a peacock are. Nevertheless, the person with poorer eye sight or perhaps lesser bird knowledge, still perceive his belief according to his own context. That makes it a truth. Valid in a specific context.

Most likely, you are thinking the same thing as I have been thinking for so many years: There is always an actual correct truth to be found. Take mathematics which should be as a good example. There is always a correct answer to a calculation, right? I mean, 1+1 will always be equal 2, don't you think? However: If the context is Boolean logical mathematics, 1+1 is actually equal to … 1. So whatever truth you think you have, someone may pull a rabbit from a habit bringing a completely different context into the picture which will make your established truth completely wrong.

If the two persons go closer to the building they probably will discover that another truth exists. This is actually where the story continues:

The two men found they could not reach an agreement so they decided to walk closer to get a better look. Soon they realized that it was not actually a real bird, but a statue of a bird. More than that, once they got to see the details neither of them could really tell what kind of bird it was the artist had meant to depict. 

Ah! Now we are getting closer to reality I think. Certainly there are better truths that can be found when digging deeper. But very often we find ourselves in a situation where we have to accept a good enough truth. A truth that works for the applicable context. This is a practical truth.

Let us turn our attention in another direction for a while.

Always choose the most important topic in a discussion.

Have you ever found yourself having several discussions going at the same time with someone? Well, unfortunately it occasionally happens to me. Before having reached a consensus from an initial disagreement of opinions, the next disagreement comes up. To make things even worse, the knot to untie the first disagreement depends upon the second disagreement to be settled first. This can continue in an evil spiral of disagreements until you find yourself arguing over 5-6 very different things at the same time. I always hate when I find myself in these discussions since there are too many variables to categorise and sort out. I beilieve that this is one of the obstacles that make discussions such a difficult art. When this happens, there is ususally a call for a time-out in the discussion I think.

But let us turn our focus back to the two persons again. The first person said that it was a beautiful peacock. A bit speculative perhaps, but his main point was probably that it was beautiful, not necessarily that it was a peacock. This would be the main sensation he had and most likely the feeling he wanted to communicate. But by doing so he found himself ending up in a discussion that probably had nothing to do with his original sensation. If the two persons enjoyed the bird discussion and considered it as meaningful, perhaps it was a fruiteful one. However, I think they hit a a side-track and discussed a less prioritised issue. If this is so I think both persons could have given in earlier by saying something like “oh, perhaps you are right”. Then they could have focused on the original and probably more important message: beautiful or not…

Although the story is a vague example on this, I think we often do tend to discuss less meaningful things just because of curiousity or a sheer willingness to be right. Instead, we should focus on the stuff that matters within the important context!

I’ve met some people who loves throwing arguments in a heated discussion and who might even provoke a person in order to get it. I’ve also come across some people who have even lied about their true opinions in a discussion since they wanted to test the opponents’ arguments. This discussion tactic may be a dangerous road to walk. In the end the person often end up confessing that he had not really been arguing with his true mind. If these types of discussions keep reoccuring with the same person, unfortunately my trust fades away. Do you want to spend your time discussing something with someone in whom you have no trust?

So let us get back to a final aspect of truths in a discussion.

Considering someone elses truth is about showing respect and having patience.

With this aspect in mind it becomes a whole lot easier to actually listen to people in a discussion/argument. Quite clearly, the more confident of an opinion we become, the more difficult it is to be open and appreciate different ways or slightly different truths.

I think that listening and appreciating other peoples truths is the most important ingredient in a discussion. You will never truly "win" a discussion if you don't pay the other person respect by giving him proper feedback showing him that you are actually listening and understanding his truth. And by saying paying respect, I dont mean shoveling a line like "yes, perhaps you are right, but..." and then quickly head on to your main point. That's nothing!

I would dare to say that showing that you listen to someone is a very physical thing. People who are good at this highlight this attention using their whole body. We normal mortals mostly have to stick to the use of our eyes. Your interest and intention should very clearly be shown when you meet the other persons eyes. A bit of a magic trick to that wordless communication phenomena, but eye contact communication does actually work in this sense. That is how you are showing your interest in his version of his truth. Not by opening your mouth quickly and say something stupid like "yes, but"...

I also think it is best if this effort is sincere and not just a plan to get your own point across. Be open to that you both have a version of the truth (or even that you can be wrong) and you will both probably gain a better understanding of a deeper truth in the end.

I firmly believe this is the key to successful communication and I am constantly trying to become better at it myself. It is not easy in the heat of the moment in a discussion. And I must admit I sometimes fail due to lack of patience... But, hey, the road to perfection is a long and fun one to walk! :-)

Saturday, January 17, 2009 2:44:25 PM (GMT Standard Time, UTC+00:00)
 Tuesday, November 25, 2008

Oredev200px.png

Last week, I visited the Øredev conference. I had a gread time and since this is the forth time I attend the conference, I can see how much it has grown from the first year in 2005. Back at this first conference in 2005 I presented myself together with Magnus on the topic of AJAX which was a bit of a hype at the time. I don't know why I did not even blog about this then but sometimes I am a lazy blog writer... :( Anyways, seeing all these great speaker it does trigger an enthusiasm to get back into the game. We'll see, maybe next year I'll make a shot at present something at some conference. Certainly Øredev would be my first choice. If they would let me in again... :-)

This year the conference was for a whole week. Two days with workshops and courses and three days with regular conference sessions. I visited the 3 days only this time. Although I probably did not manage to always pick the topic that suited me the best from those available, I think I still got a little something out of everything.

The topic of the conference was "Share Knowledge" and I think this is certainly true and a well chosen phrase. But most of all, for me, it is about getting the inspiration to dig into new fields of interest. Most, if not all speakers are very dedicated about their own topics of interest and I believe all of them spend a share amount of their own spare time to become as knowledgeable as they are within theses areas. This is the essence of passion I think. That you volunteer to walk the extra mile in order to stay on top of things and in control. Naturally this brings with a certain amount of enthusiasm in the air that is easy to grasp and feel. So, to me, the importance of this visit boils down to this important sentence: 

It becomes easier to remember that it is fun and rewarding to stay passionate about your work after a visit to Øredev.

This is a simple statement but in essence it often means that you will pick up a work related book after work or sit down in front of the computer once again after an already finished 8 hour session during the regular work day. An easy thing to say, but less simple to achieve. But if you are passionate about something it definitly becomes a lot easier. Essentially:

Passion is what drives us to become better at what we do.

Another nice thing about Øredev is that it there are many cross-discipline tracks. So it is easy to slip into the Java track, or the Testing track for instance when you feel the curiousity of a topic. There were 12 different tracks to choose from this year so I think it was quite easy to find something interesting somewhere. Naturally, there were sessions that collided making me bring out the dice, but video recordings of sessions are coming up I hear. So this parapgrah basically brings on the next important punch liner:

Øredev makes it possible to think a bit more outside the box you tend to place yourself in after weeks and weeks of regular work.

I find it a bit hard to retell which sessions I attended and what I thought about them. Basically since it would be a book writing that I never would finish. But I do say that the absolute highlight for me this conference was to see and hear Robert C. Martin speak. His book Agile Software Development, Principles, Patterns and Practices has meant a lot to me as a software developer. It has completely revised the way I think about code and the importance of making a good design. There were a lot of quite famous people on the conference so I'll just skip the remaining name dropping here and instead urge you to view the excellent program selector (as already linked to above).

Oh, one more thing definitely worth mentioning:  Øredev did support this year builing schools in Africa via UNICEF which I think was an honorable thing to do. I bought a brick at the conference and I encourage you to do the same. It is probably never too late to be a hero. :-) 

Last but not least:
Mucho thanks to the Øredev team that pulled this togheter once again this year! Looking forward to next years conference already!

 

Tuesday, November 25, 2008 6:20:47 PM (GMT Standard Time, UTC+00:00)
 Tuesday, November 18, 2008

This morning I woke up to a real nightmare. Yesterday I had set the alarm on my mobile phone to wake me up at 6.30 in the morning as usual. I knew when doing this that I probably would suffer a bit waking up since I went to bed way too late. But what the heck, it is only sleep, my last train of thought went before going to sleep. Oh, did I pay for this a couple of hours later!

Since my girlfriend wasn't getting up as early as me I had been particularly careful to set the alarm to use an increasing volume. Also I turned off the phone battery vibrator since this tends to make the whole room vibrate when the alarm rings, which even wakes up our cat Disa who usually sleeps at my feet.

Before I go on and tell you about my nightmarish wake up, I'll tell you about a previous experience with another brand from this particular mobile phone manufacturer. That mobile phone screamed out with a terrible melody whenever the battery was getting low. In most cases, this is probably a good thing since you really want to make sure this never happens. But with this particular mobile phone, it was not configurable to turn this feature off. So naturally, the alarm woke us up in the middle of the night on a number of occasions.

Eventually I managed to learn that phones' user pattern to take the battery out before going to sleep. Or even better, plug in the electric charger... Anyways, I think most people would value sleep over the mobile phone not running out of battery.

So, back to my devilish wake-up this morning. At 6.30 this morning the mobile phone alarm started ringing at a low volume as should be. Unfortunately the alarm went off during the wrong time of my sleep cycle so I was really dead tired with most of my brain neurons still sound asleep. I also woke up finding that my left arm was missing. I could not find it anywhere.

As the sound of the alarm screamed louder and louder, I slowly realised that my arm was gone because I could not move it. It was completely lame. I did not feel it anymore.

This can happen if you sleep with the arm in a weird position for a long time. It will wake up again and becoming fully functional after a couple of minutes of free dangling time. So I actually did not panic. Yet.

So that leaves me with one arm and a tenth of my normal brain power to turn off the phone. Piece of cake you would think?

A regular alarm clock usually has one big “turn-off-alarm button” that is easy to find. This morning I realized that there is a reason for this. In my delirious dreamy state, I started pushing all the buttons all at once on the phone with my functional hand. But nothing happened. Instead the alarm started to ring louder and louder. With a steady arising panic I begun to realize that the alarm would never ever again be turned off. I would have to live the rest of my days with this noise ringing louder and louder in my ears.

So I fumbled on in my quest to turn the damn thing off rushing out of the room, stumbling over poor Disa who for a second managed to scream louder than the phone. Perhaps if I poured water on top? (on phone, not cat!) The electronics probably doesn't like this so that would probably work.

Fortunately, my brain power was slowly booting up again so I never fulfilled my idea. Instead my one hand remembered the old trick and after lots of struggling (one hand!), I managed to pull the plug out of the sound by removing the battery.

Phew! Silence! Finally!

But the screaming alarm was still reverberating in my head with anguishing anxiety. And I knew that my girlfriend was probably lying in her bed cursing me and only me for this! Well I curse the phone in turn!

Ok, so having woken up a bit and sitting here at breakfast with my beloved cop of coffee, again being able to hold it with two hands, I think I realized what went so terribly wrong this morning. Firstly, I now grasp that I sometimes never will learn how to turn the alarm off the ordinary way. Especially not so with one tenth of my brain power and one arm at my disposal. Secondly, for some reason the phone key lock is sometimes not lifted when the alarm goes off. This is clearly a software bug since normally, one only has to puch any button to turn the alarm off. Devastating bug I would say... And if it is not a bug and if there is a logical explanation to it, well even worse. If I find this to be the case, I might even reveal what brand of mobile phone it is in this blog post.

Some thoughts on the future of mobile phones

Mobile phone companies have started to talk a lot lately about turning the mobile phone into a generic all-in-one toolkit; kind of like a Swiss army knife. Keys, credit cards, you name it. I would love for this to happen. But I also would love the phone software developers to think in turns of how these devices are actually used in each scenario. Why is there a big button on the alarm clock and how can this be simulated better and always work on a mobile phone?

These type of questions, I think is always extra important to ask for product manufacturers. And particularly so when they are to support a new functionality that it originally was not designed to support. As in simulating an alarm clock when you are in fact a mobile phone.

Naturally, looking back at this morning I laugh about my desperate attempts to turn the alarm off. But I also think that I never will buy a mobile phone from this particular manufactorer again. But then again. Perhaps I will. I am usually less cranky after I have finished my morning cop of coffee.

Tuesday, November 18, 2008 6:58:41 AM (GMT Standard Time, UTC+00:00)
 Sunday, November 02, 2008

This blog post is part of a series that start here.

I have already descrived what the Running Mate is and why I would like to build such a thing. Now, it’s time to get my hands a bit dirty with the mathematical theory that’s needed for this. I would not say that it is an advanced mathematics, but it is definitly a fun applicability since it is really easy to see and understand the purpose and need for the mathematic formulas.

So here’s my 10 km run again. Let us focus on small area of this run: the square that the red arrow points at:

If we enlarge this square area, it would look something like this:

As you can see, I’ve painted some blue stars on the map and high-lighted the road with a black line. The blue stars signify the GPS points that my running mate is picking up with the help of the satellite(s). I don’t know how often these coordinates actually come, but naturally, I will not be able to get the exact track of my run. By drawing a line between the coordinates we will se how the running path looks like according to the PGS system. Here is another image high lighting the coordinates with their straight lines between them in an X-Y graph instead:

 

Calculating the distance between these stars in this graph is simply a matter of utilizing the Pythagorean Theorem. I honestly think that no matter how rusty your math knowledge becomes, this formula will forever stick in your head:

z2 = x2+y2,

z is evidently being the sought distance between two of the stars in my graph. So in order to withdraw the distance between the second and the third coordinate, the formula becomes:

z2 = (x3-x2)2+(y3-y2)2

Calculating all distances between all coordinates on the map gives us the total distance which is exactly what shapelink.com did for me when I utilised their service to draw my run on a map. Basically, I gave them the coordinates by clicking on the map and they drew the lines in between these coordinates and calculated the total distance of the run.

But we are still not at where I want to be: getting the current time comparison of each spot to a previous run. And this is where the fun begins.

The difficult part here would be to compare different coordinates from different races with each other. Naturally, the coordinates will not be on the exact same place as the previous coordinate. This image will illustrate this:

Here I have high-lighted a second race coordinate with red stars. As you can see I did not run the exact same spots as I did the last time I ran the race. The deviation shown is most likely larger than what would be in reality considering that the track I run on is quite narrow. But nevertheless, I obviously have to take this into account when comparing the coordinates.

Naturally each coordinate also has an associated timestamp. As I see it, finding the coordinates that are closest to each other in order to calculate the difference between the two timestamps can be done in at least two different ways. Let us start with the easiest one.

Algorithm: Finding the closest coordinate

So, as this image shows, we have to calculate the distance (d1, d2, and d3) for each red coordinate to all blue coordinate and pick the one that is the closest to the red coordinate. The needed calculation is basically just a matter of using the Pythagorean Theorem again a number of times, so it is a piece of cake really.  

In the example in this image, the d3 distance is obviosly the shortest one so this coorrelating blue coordinate is selected as the one to compare against the red coordinate. The difference in timestamp between these two coordinates would give you the desired result for the Running Mate application. If we don't need  a more accuracy result, this is where we would stop.

However, of course we want more accuracy, so let us move on to the more interesting algorithm.

Algorithm: Interpolating the time

As you might have gathered, the previous algorithm is not particularly accurate when the number of coordinates is low for a run. If the number of coordinates approaches infinity (as mathematicians do love to state) the result would indeed be good. But if merely a few coordinates would have been used for the whole track, naturally this first algorithm just doesn’t cut it. This is when time interpolation is needed.

In this image we are focusing on two of the blue coordinates, B1 and B2, that lies closest to one of the red coordinate, R1. Basically, we want to find the V (as in Virtual) coordinate in order to find the time interpolation between the B1 and B2 coordinate. All we have to do is to calculate the ratio of the distances between the coordinate V and the B1 and B2 coordinates. This ratio will give us the needed number in order to calculate a new blue time stamp at which the virtual V coordinate is located.

So in theory, this algorithm seem to boil down to the following steps:

  1. Find the two blue stars that are closest to the red star.
  2. Find the coordinates of the virtual coordinate V.  
  3. Calculate the ratio of the distances between coordinate V and the two closest blue coordinate.
  4. Calculate the virtual timestamp of coordinate V using the ratio found in step 3.
  5. Compare the timestamp for the red coordinate with the new virtual timestamp for the coordinate V.

The only difficulty here really lies in the second step of this algorithm, i.e. finding coordinate V. So let us concentrate on the information we do know, i.e. the known variables. Consider the following image:

Here, d1 is the distance between B1 and R1, d2 similarly between R1 and B2, and finally d3 being the distance between B1 and B2. Ok, these distances are not known, but we do know that if we have the coordinates, we can easily calculate the distances using … yes you guessed it: the Pythagorean Theorem. So we can consider these distances as known.

Ok, next would be to calculate the angle α at the B1 coordinate. Knowing all distances d1, d2, and d3 in this triangle we can utilize the Law of cosines:

d22  = d12 + d32  - 2d1d3cos(α)

The only unknown variable here is the α angle which a bit of algebra magic solves for us.

So when we have α, we can calculate the distance dv, i.e. the distance between B1 and V coordinates with the following basic trigonometry formula:

Cos(α) = dv  / d1.

Again, a bit of algebra gives us dv and you know what? We are actually home safe now with this knowledge. Basically we now know the ratio in distance V between B1 and B2. Now all we have to do is to apply that ratio to the timestamp of B1 to get V coordinates virtual timestamp.

I have not yet had the time to implement the second “interpolating the time” algorithm in my Running Mate code demo as available at Codeplex, but when I have I will delete this sentence and add a comment about it.

Sunday, November 02, 2008 1:54:50 PM (GMT Standard Time, UTC+00:00)
 Friday, October 31, 2008

This blog post is part of a series of blog post that starts here.

Well, to be honest, it has been available all since this Monday before the Swenugpresentation. But I just added some missing files too so now it actually compiles too... Sorry about this if someone chose to download the code right after the presentation.

As perviously stated in this blog post series, I initiated the creation of the Running Mate mostly because I needed a demo application for a performance talk. It served its purpose well I think, and I think I can make use of this applications in upcoming presentations. However, being a demo application, it is far from complete in functionality:

  • There is no PDA based version of this code built yet. I.e. the device that tracks and sends the GPS ticks as you run to the server. Obviously without this, there is no purpose of the Running Mate. So I hope that I or someone else will have the time to build this eventually.
  • There is no real Graphical User Interface built yet. I built a test load client for simulating the load and I also built a windows client application for inserting the test data into the database which both are available. But the real GUI is not built yet. I have some ideas for this and hopefully someone will help out with this GUI eventually since GUI is not my cop of tea...

As for all the source code it is available here: http://www.codeplex.com/runningmate. It is published under the GNU GPL v2 license model.  You can quite easily use Subversion (TuroiseSvn client) URL at https://runningmate.svn.codeplex.com/svn or the TFS Server URL at https://tfs05.codeplex.com.

I am usnig SVN myself and unfortunately, the throughput is very low. I suspect Microsoft is actually to blame here since Codeplex is a very popular open source repository these days. Microsoft don't seem to have scaled codeplex to meet the demand. If it does not improve or if I see it is a problem I might move to another availble code repository. We'll see.

The current file folder structure in the repository looke like this:

TheRunningMate_filestructure.JPG

Although this most likely will change in the future, the idea is that a working, non-demo version of the code will be available in parallell with the DemoVersion folder. Eventually..

In the VisualStudio folder, all the C# 3.0 code is placed. I am using Visual Studio.NET 2008. Currently, I am running MySql as the data persistance provider, but I might make more options available too. After all, MySql requires a MySql server to be installed in some way or another (there are quick ways to install it) so it is a bit too much of a hassle to get the application up and running if you are not using MySql. The DB folder has everything you need here though for the application script wise, but please let me know if something is missing.

Hmm, that's it for know I think. I'll back on the topic of design and architecture in an upcoming blog post.  

Friday, October 31, 2008 4:37:03 PM (GMT Standard Time, UTC+00:00)
 Sunday, October 26, 2008

Ok, so this is my third blog post today. Gotta be a record for me I think. :-)

On Tuesday I will be presenting on the topic of performance optimization at Swenug in Göteborg. This last year I have been working quite a lot with this focus at Admeta. The topic of this talk is: 1 billion web request - response time 50 milliseconds. This is actually not a lie since we have these types of requirements at Admeta. One billion request is quite a high number so I do understand if there is a mild hesitation if it really can be true. But asynchronous requests from multiple high load pressure web sites can stimulate this type of requirements, trust me.

I believe the presentation will be approximately 2 hours, but there will be room for some discussions. I've been at a number of Swenug presentations by now here in Göteborg and I think the atmosphere is very relaxed and nice. I hope for the same nice athmosphere on Tuesday with lots of interesting questions and discussions. So this is what I planed and prepared for my presentation:

1. Load testing process and demonstration

Load testing is of vital importance in order to understand how the load pressure will affect your web site. Scaling with more machines is not always something that you can do hastily if the need arises and it sure does cost a lot of money to do it. So it's good to know a little of what you application could behave in production before you launch it. In this part I will go through the load testing procedure, what to look out for, what data to collect, and give various other hints based upon my experience in the area.

2. Performance Profiling with the Running Mate application

For profiling och optimising, I will demo with a new hobby application that I just recently built: The Running Mate. The special thing about this application is that I have built the domain very loosely coupled with regards to the application layer making it possible to switch the domain layer at runtime. I am basically providing these different types of implementations:

a) The Super Hack: this was the running mate application as easy as I could possibly implement it. Not much design work. But fast?

b) The Overkill Design: This application is a bit overkill since the domain model is interchangeable in runtime. I would say that in most cases, this is not how you would normally decouple the domain layer since the need for it often just isn't there. However, it is very useful if you would like to profile performance with regards to different types of domain model implementations. The architecture pattern is that one of the Domain Driven Design (as described by Eric Evans) which gives the system a very nice Separation of Concern I think. One of the provided domain models is using a traditional Data Access Layer implemented in DDD repositories. The other provided domain model is using the Mindscape LightSpeed O/R mapper which we have used at Admeta for quite some time. As you can see in the link it is providing a bunch of nice features and it is very nicely DDD oriented.

So, I think there is enough substance here for a two hour session with discussion. All code demonstrated during the evening will be provided at CodePlex at http://www.codeplex.com/runningmate very soon.

Sunday, October 26, 2008 10:24:03 PM (GMT Standard Time, UTC+00:00)

     This blog post is part of a series that starts here.

I have long distance running as a small interest of mine. It is far from a passion, but I try to get out in the forest and run a distance of approximately 10 km every weekend. I usually run in a park called Hisingsparken here in Göteborg which is a beautiful and peaceful forest to run in. With the courtesy of shapelink.com , here is a map of the 10 km lap that I usually run.

hisingsparken.jpg

Well, beautiful and peaceful isn’t all, is it? The current condition and health situation surely makes running a lot more enjoyable. And in order to get in fit which makes running a great sensation, you have to run faster and push yourself a bit.  So this blog post is basically about finding this motivation with something called the Running Mate.

In order to motivate myself to run a bit faster, I clock the time it takes to run the distance. But unfortunately I seem to be stuck at about 55 minutes for 10 km run which is a bit too long time I think... I know. There are various good ways to improve the time: run more often, vary with shorter distances etc. If lowering the time would have been of really strong importance to me, these ways of doing would probably suffice for me. But as it, my level of interest makes me look in the direction of technical tools to help me out…                          

My problem when I run is probably motivation and focus at the running process itself. I let my mind wonder and I think of everything except keeping the correct pace. Running is great for problem solving by the way. Anyway, the clock does not give me this feedback since I have no idea of what time I am supposed to have when I am looking at the clock during the run. Naturally, this can be solved by having a number of part times at specific distances. And I do, but I don’t really want to keep track of too many of these part times since it disturbs my thoughts on other things. I would like to be able to know instantly, at the time of interest, what my pace is compared with a previous run at that exact spot of the run.

So the answer is obvious: The running mate application. It has been possible for quite some time now to buy a GPS equipped watch with this type of applications. The main idea is that it should be possible to run against yourself, i.e. being able to compare your current running time against a previous time you have had in a previous run at each and every spot of the run.

So I could have gone ahead and bought this GPS device. But something has stopped me so far. Of course it would be cool and exciting to fabricate this tool myself with the help of a mobile phone and a GPS device. Not that I know if I will ever get around constructing the whole thing, but I intend to build something in code and blog about it. I do this partly because it is a fun thing to do, but also since I think this application could be the basis for future examples both on the blog as for presentation I do.

So next blog post, coming up soon I hope, will be about the mathematical geometry needed complete such an application. Fun stuff I think.

Sunday, October 26, 2008 9:39:54 PM (GMT Standard Time, UTC+00:00)

For quite some time now, I’ve been thinking of the design of a so-called Running Mate application. I decided that it was time to implement it and the trigger that set me of was to have a fun example to use at a performance tuning presentation. So beneath is what I have in mind as blog topics although it can change somewhat as I go ahead:

  1. The Running Mate – What is it and why?
    This is a personal touched blog post with the background story as to why on earth I think the Running Mate application is a nice thing. Off course, this blog post also lets you know what the application is actually doing
  2. The Running Mate – Code available at Codeplex
    Source code available and some words about what is provided and what is not provided in the repository as well as some file structure information.
  3. The Running Mate – The geometry calculations
    In order to implement this application some interesting geometric calculation is needed. This blog describes these calculations.
  4. The Running Mate – The Super Hack implementation
    Sometimes I start off by doing a rather quick and dirty implementation of the application and then refactor my way into a more nice design. I didn't actually do this for this one, but I needed super hack implememntation for my presentation. So this is breif presentation of a quick and dirty implementation.
  5. The Running Mate – The Domain Driven Design approach
    In this blog post I transform the application into a design that is closer to a Domain Driven Design.
  6. The Running Mate – The O/R Mapper Repository
    The repositories built in the previous blog post uses a classical database access layer wrapped in repositories with inline (ad hoc) SQL. Here’s an alternative approach with the MindScape LightSpeed O/R mapper.
  7. The Running Mate – The loosely coupled Domain Layer
    Most O/R mappers integrate into the Domain Model rather tightly and make it a bit more difficult to switch from one O/R mapper to another one. This is a bit strange since O/R mappers themselves make the choice of underlying database very flexible. In this blog post I describe how you can decouple a domain model from the application so that you can have several different versions of domain layers that the application can utilize. The loosely coupled domain model is not always that useful in reality, but it is a nice experiment.   

I may change the topic names slightly as I go ahead and write about them, but I hope you can live with this. There are actually many more blog posts that I can write based on this application. For instance I would like to write some more about the LightSpeed O/R mapper and how you can wrap the basic CRUD stuff to make these methods really easy to access with a simple API. Also, there is a lot of stuff on performance tuning this application that I would like to write about eventually. But I better not promise too many blog topics in advance since you never know what lies round the corner.

So. Basically, I am back in the blogosphere for another round.

Sunday, October 26, 2008 9:12:12 PM (GMT Standard Time, UTC+00:00)
 Sunday, February 03, 2008

In a previous blog post, I covered the following topics:

·         Published, not stored which basically allows for more people to read the document.

·         Refactoring structure allowing for documentation to stay agile and up to date with a current content and structure.

·         No special roles, instead accountability for taken actions!

·         WYSIWYG vs. wiki syntax basically stressing that simple editing markup is good enough for most types of documentation.

In this post I will instead dig into the following two topics:

·         Local feedback which allows for history of decisions to be associated to the source of the information.

·         High cohesion and low coupling is a well known programming principle. I think this principle can be applied to documentation as well which is better supported with wikis than in file based documents.

We sure do communicate with each other a lot at our job. This is mostly done in a synchronous way with verbal communication. Most often agile methodologies favor verbal communication over written communication since it is considered as the most effective way.

However, there are other ways of communication which are of an asynchronous nature. Such communication allows us to write information or questions to other people and do other things while waiting for the response to come back.

Asynchronous communication also allows for us to take the time to formulate a good text that correctly describes the important part of the message. Sometimes this is a great strength over verbal communication since in an intense moment we do tend to talk past each other, not understanding what the other person is trying to say.  Of course it can also be a weakness since we don't get an immediate feedback of what we are stating. But this is a completely different blog topic which I probably will write eventually.

However, an example of such asynchronous communication is of course mail, which probably still is our most commonly used communication tool at companies. Yet another example is some kind of chat messenger like MSN Messenger or ICQ which also is of an asynchronous nature. In fact you can find yourself having a multithreaded dialog with someone on a chat application with several topics being discussed at the same time. At least, I know that we programmers often do this. Very effective indeed! :-)

So what about wikis? Let’s look into this now:

Local Feedback

I would say that we often use mail to communicate with each other at work since the asynchronous nature is convenient. However, one disadvantage is that important information as to why we reached a certain decision is persisted in our mail box only. Unless you are extremely organized with a myriad of mail folders, it will become difficult for you to find this mail conversation later on.

 I find that even searching for mails, as gmail states as a big strength of functionality, many times this does not work because I can’t remember the exact words to use in the search... In this case I am left with my structured mail folder hierarchy in order to find the message. After a couple of years there may be thousands of emails in each folder… But then again, perhaps this is only a problem that I have… :-)

Another issue is that information is not published for others to read apart from those in the recipient list. At least for some topics, the information has to be brought out and written somewhere else where more people can read about it. I think that some ”non-secret” topics instead could be published and discussed directly on a wiki omitting the mail dialog. Many wikis offers comments or some kind of discussion board to be associated with the wiki page that can be used for this.

One wiki that successfully uses this approach is Wikipedia. Since everyone is allowed to enter information in Wikipedia, naturally, conflicts of opinion occur frequently. Take a look at this page for instance and please notice that it is the discussion tab. The page contains the discussion of what Inversion of Control is and how it could be explained etc. Unfortunately the meaning of the term is very different from programmer to programmer as you can see. But with discussion, eventually a mature and natural consensus can be reached as to the meaning of the term (ubiquitous language established, see this blog post). Unfortunately not yet so for IoC.

However, the essence here is that the information as of how the meaning of a term was concluded is stored locally and connected to the information itself. I.e. effective metadata! I think this is a great strength.

Naturally, there is always a decision to be made what discussions are to be held in public on a wiki and what discussions are to be held in mailing lists. I am not arguing for abandoning mail here!  :-)

High Cohesion and Low Coupling

I would dare to say that all programmers have heard this statement (and if they haven’t, it would be time to do a little bit of studying. :-)) However easily stated it is not as easily achieved. I also dare to say that it takes years of programming before getting skilled enough to realize the importance of the statement as well as knowing how to apply it well. 

I have often reflected upon lately that successful communication should apply to the same principle. When explaining something to someone, we have to stay focus on the topic. Otherwise, we confuse the audience with too much information (information overload). Sometimes we need to explain a side track in the discussion before we get to our main point. Recognize this scenario? Well, it certainly is the difficult art of pedagogic and it is the importance of having common reference knowledge.

Perhaps being a little bit daring, I think the interpretation as to the meaning of high cohesion and low coupling is quite similar when it comes to communication. Looking at a story to be communicated to someone else, the main focus lies in the main message you want to get across. This information could be compact, i.e. high cohesiveness, which will make it easier to understand.  But it often relies on other information, I.e. it is coupled to the other information. Naturally you would like high cohesion and low coupling to get the main point across quickly. But this coupled information is often what makes the story complete in its context and it gives the story its nuanced and interesting flavors; although making it more difficult to understand.

Having established this interesting parallelism, let us turn an eye in the wiki direction. I have already established in the part 1 wiki blog post that refactoring of the wiki structure is an easy thing to do. This is important since it allows for us to provide pages that have a high cohesion. High cohesion in wikis is pretty straight-forward to achieve since the page refactoring support is there.

However, the thing to look out for is strong coupling. Although a good wiki should be able to update linking between pages when you change them, you may run into many fragmented pages with too many links (high coupling) to other pages. This is where your sense of structure and judgment comes into the game. I dare to say that there is no tool that can do this structuring automatically for you since no tool can predict exactly what you will write.

This is nothing new really and I believe that every good communicator has come to realize this and applies to this principle whether it is in writing documentation or merely speaking to people.

In my next, and perhaps final blog post about wikis, I will have a more practical approach as to how to choose which wiki to use (there are lots of them out there). I can’t say I am an expert of all those wikis, but at least I’ve learned some aspects to look for. So until then, stay tuned.

PS. I probably should admit that my interest in blogging on other topics recently has gained which I might prioritize writing (as well as time spent not blogging…  :( ;-). So if you are interested in number 3 in this series, please let me know and I’ll try to speed up the persistence of that story.

Sunday, February 03, 2008 10:15:27 PM (GMT Standard Time, UTC+00:00)