# Thursday, February 21, 2008

Imagine a project, part II

Part I was a description of a crazy project where requirements' changes were on a daily basis.

How do you handle such a component?

The most important thing would be to make sure that after every change, every completed task, the project's code is consistent, there is no left-out code, and all tests run.

Automation, daily builds and good code coverage (in terms of unit tests) become your best friend.

Imagine a project

    Imagine you're in a project whose sole purpose is to mediate between a handful of really large systems. Even worse, the application is a front-end for the user, handling his money - so if something goes wrong, guess who gets blamed. In the beginning you investigate and develop a plan how to implement such system. You write an architecture, detailed design, do estimations.
    After a campaign for gathering capital, you start the project.
    Imagine that most systems you depend on, have different rules on how to connect with you - some require you to install systems on-site and these systems to be active, some expect you to implement an interface, and just wait for a call :)
    Imagine you neglected the legal part of the thing and you have to compensate that mistake by going through the user interface with a lawyer who changes a significant part of it, which on it's turn changes the business logic.
    Imagine you have a marketing office that says that in order to profit more you again have to change how user interacts with the system.
    Imagine that you're in the middle of development and have to meet a deadline with version one just in few months.

    Imagine there's a component in that system that handles communication between other components in the project. This component is affected by every single change in the whole project - requirements change daily, not to mention the domain model that this component serves.


    ...now imagine you're the team leader of that component...

Firefox's spell checker

Recently (it took me quite a while) I found firefox's spell checker - it's a great thing, but it's not enabled by default

Maybe it's not a bad idea to say a few words for guys that still do not use it (like me).

How to enable it:




Also by default, there are no dictionaries, how to install a few:



then:




I installed Eng and BG, the bulgarian one works well enough:



Oddly enough, I had quite a lot of errors on the blog, by average 2 per blog entry. All fixed now.

Transformations between Domain Models, OOP fails, no such Design Pattern

The issue:
There are 3 (three) Domain Models (Object hierarchies, groups of objects). They are parts of different tiers of an application. Their hierarchy trees are nearly the same.
Why we have three DM is another issue, but is not in the focus of the following discussion.

The task is to convert objects from one Domain Model to another. As I said, the objects are nearly the same, data objects, no logic.

Until now there were static methods that do that. It's ugly - there's another class, inheritance is impossible - logic has to be extracted like this

public static M2Object convertM1toM2(M1Object) { /* logic */ }


becomes

public static M2Object convertM1toM2(M1Object m1) { convertM1toM2(m1, result); }

private static void convertM1toM2(M1Object m1, M2Object m2) { /* logic */ }


because the result is now an inheriting class and cannot reuse M2Object convertM1toM2(M1Object), but can reuse void convertM1toM2(M1Object m1, M2Object m2).


What I proposed was to put converters in one of the Domain Models, M2 was chosen.
so now M2 has

new M2Object(M1Object)
new M2Object(M3Object)

M1Object toM1()
M3Object toM3()


Inheritance with constructors is working smoothly. The problem comes from the toXXX() methods. Inheritance is difficult because the super toXXX() creates the result (base M1/M3 class), but the result in inheriting toXXX() method should be inherited M1/M3 class.


So now I'm thinking of (M2InheritedObject):
protected final void convertTo(M1InheritedObject m1) {
   super.convertTo(m1);   // convert base class properties (reuse happens here)
   /* +extra logic */     // convert inherited class properties
}
public M1InheritedObject toM1() {
       
M1InheritedObject result = new M1InheritedObject();
        this.convertTo(result);
        return result;
}

This method is gonna be reused, inheritance is weird  - this is actually kinda unclean, but the best I can think of.


I'm thinking of some design pattern, (Adapter for example), but that good for objects, not object hierarchies.

If somebody thinks of something, I'd appreciate it.
# Wednesday, February 20, 2008

Me, the florist

Here are some pictures of my reborn (I had neglected it for a while) passion:
 

            

Comparing source code on check-in and check-out

A great practice I follow is to do compare when checking in and out some source code.

When in a new project (my current situation) it's really fast to find out what code is hot - heavily changed, and how it is changed. Even when into the project, the new guy can follow what others are doing, can find out if someone accidentally overrides something (it happens more often than you think), and generally keep track of what everybody's doing.

There's an overhead involved - the whole procedure needs some time. I try to commit (check-in) relatively often, and on every sync I do compare. This way the committed code by others could not pile up.

There are also tricks to optimize the process - if the comparator highlights horizontally changed code (most of them do comparison only vertically - line by line) you can ignore code formatting changes faster, because no code is highlighted. If some refactoring takes place, you could ignore the changes in subsequent files after you've seen them in the first one. Example (only spaces and quotes changed):


A good reason for frequent commits is that a frequent update would be easier - when you update a file you see a single change.


Comparing code on commit (check-in) makes some bugs obvious and helps avoid typos. Frankly I don't do it always.


Two additional things I would recommend: when committing, write a description (it helps others understand what's going on) and do atomic commits - commit a single task as one thing (select all changed files and commit them together with an understandable description - it's really helpful for the guy after you.
Note: not all repositories support atomic commits, but still it's a good habit.

The second thing is always to update before commit - avoid partial commits and breaking the build accidentally.

Don't make me think

Today I was on a lecture - http://www.devbg.org/seminars/seminar-Software-Engineering-20-February-2008/

Mihail Mihailov had a great lecture on rapid development (based Steve McConnell's book).

It seems I'm gonna have to check out Steve's less popular books - Rapid Development, and something about estimations.

Because of participation I won a copy of "Don't make me think":


It seems like a book I would enjoy reading and that would have the same way of thinking as I do.

It was signed by Mihail, and funny enough Mihail's signature is something like M2:
Cool, I like it.
# Monday, February 11, 2008

Laptop overheating comes out to be a Vista Search issue

My laptop started heating more and more until at some point I had to start forcing it to "Sleep". (it has Vista on it)

At some point I got really aggravated by that fact and started investigating. Forums revealed that the issue could be linked to heavy processor usage.

Process Explorer showed that I had some wierd behavior even when the machine was idle (Indexing service is disabled - dummest thing ever) - explorer.exe taking 100% for 5-10 seconds.

Repeatedly.

There was a wierd dll doing that (SHLWAPI.DLL):



At some forum I found out that this was related to the start menu search. WTF?

It comes out that the start menu search (which I find one of the few useful things that come with Vista) does a search in the index first and then goes the the hard drive.

We don't want that.

There is an option in the start menu settings which stops that - problem solved.


The good thing is that while searching at the forums I found a pretty useful tool - Dell fan control - one can see everything and EVEN control fans:



dell fan control.png (78.88 KB)
# Sunday, February 10, 2008

DNS Configuration issue - partly solved

A while ago I had an issue with accessing gateway machine by its external network address as discussed here: DNS Configuration issue

The solution with the local DNS server kinda worked - now there is a local DNS server with local names (machine1, machine2...) and mapping the domain names (stoynov.com) with the local addresses. It works pretty well.

The only problem is synchronizing the sub-domains (msdnaa.stoynov.com) with the local DNS server - now they should be added by hand. Kinda sucks. The good thing is that there aren't too many of them.

# Wednesday, November 28, 2007

DNS Configuration issue

There's this problem I've been having for some time.

I have a small server (http, mstsc, file-, ...) at home. It has a real IP address. It also acts as a gateway (AP, lan, bluetooth lan) and shares it's internet connectivity. For that reason that machine acts as a DNS and a DHCP server and has an internal IP address.

There's a domain name resolving to the external (real) IP address.

The problem is seeing the the stuff that should be seen from the outside world from the internal network. All that stuff works when using the internal IP to access that machine, so it's not a firewall issue.

What works and what not: pinging the external address works, telnetting to external IP:80 fails as with any other port.

A simple site wouldn't mind internal or external address.
My blogging application on the contrary would fail because the resources (pictures) are with FQN URLs.
And I would like to make this work in a pretty way.

One solution - local DNS server supplying the internal IP address for that domain name.
This works now, but my local DNS has to have an entry for every single domain/sub-domain - this approach sucks. I also have different services exported on the two different IPs and this local DNS approach break that.

I have seen this problem with the networks of midsize companies. Example with deploying a product inside that network (have to supply internal names).

I'm looking for a better solution.

Anyone?

# Tuesday, November 27, 2007

Car accidents' day, part II

Look here for part one.
I had promised myself until the end of the day to use only first and second gear - I didn't do it.

So what happened until that notorious day was over.
It was snowing all day and after work I decided to go to a nearby mountain (Vitosha) and test my driving skills on an empty road. At some point I parked outside the cleared road to see the view to night Sofia. ...and I couldn't get out of there - the car was stuck in high snow. Digging was necessary. To dig I used a thing I bought for cleaning my windshield - it did an amazing job and I got out.

Few turns and a lot of drifting after that I lost control and got stuck (again!) in ditch stopping just a few inches from a tree. The car was inarguably unable to get out of there on it's own. I was just imaging how now I should start calling friends (it was around 12 o'clock already) which would arrive at least an hour after I called them, when I saw some lights. I got out and raised my thumb and these guys stopped. I had a rope and a Subaru 4x4 got me out in no time. And the car wasn't damaged at all. What a day.

I definitely believe in god now.

Unfortunately there isn't a single picture of all the stuff that happened.

# Monday, November 26, 2007

Car accidents' day

Today for a while I started believing in god.

I had to get up really early to take a friend to a car repair shop. It was (and still is) a rainy day and I was really sleepy. On the way there (driving kinda fast) I missed a right turn and went in the left lane (missing two cars and a van, whose driver lost control and stalled the thing missing me only for half a meter - fortunately he didn't hit anything). I stopped, apologized and continued on my to the shop without even my heart rate going any faster - I guess I was too sleepy (but not too much - as to avoid the accident).

Few hours later getting out of a parking lot I hit a car - quite a limousine with some mafia guys in it. Only a scratch on it and nothing on my car. After hearing the regular threats on my life, we (me and one of them) decided to call the police. Now is the time to mention that driver had parked on a bad place causing a jam and a lot of horns. He then moved the car to a different place but still causing a jam and a lot of angry drivers. At some point he decided to leave without even telling me. After a few minutes I called the cops to tell them not to come. I didn't even get a ticket.

What a day.

Until the end of the day I'll use only first and second gear.

# Friday, November 23, 2007

[Phun] Bank Robbery

I couldn't stop myself from sharing this one. It's amazing...

Bank Robbery in Downtown Los Angeles!

(it doesn't look so real)

# Monday, November 19, 2007

First day without a car

It sucks. It sucks big time :(