First developer meeting in Bern

January 21st, 2010 Patrick No comments

Today at the Fachhochschule happened the first developer meeting in Bern. The first tasks were the presentation of each participant and to collect the interests to discuss.

entwicklertreffen

After that Florian Kammermann presented his thoughts about software development. He’s highly interested in business oriented software developing. That means for him, that you have to be agile and follow the principles like DRY, separation of concerns, etc.

At the end of his presentation he showed his favoured design patterns strategy pattern and state pattern. He showed the patterns by java examples.

  • Share/Bookmark

WordPress and SyntaxHighlighter

January 8th, 2010 Patrick No comments

I often post code in my blog posts, so the SyntaxHighlighter by is very useful. But there are several plug-ins for WordPress, the question is which one is the most comfortable and has the most configuration options:

Offline blogging tool support

When I post technical blog posts with code in it, then I prefer the way over an offline blogging tool. Currently I use for this use case Windows Live Writer, also because it is free. But when you use a such tool, you should have good support for writing code and support for the SyntaxHighlighter. For Windows Live Writer there exists several plug-ins for the SyntaxHighlighter:

Unfortunately some of those plug-ins aren’t very well tested, but to add code to a blog posts they do their job.

Conclusion

After testing the several plug-ins for Wordpress and Windows Live Writer, I prefer currently the following plug-ins:

  • Share/Bookmark
Categories: Best practices, Private Tags:

Useful Firefox Add-ons

January 1st, 2010 Patrick 3 comments

After several years of using Firefox, I’ve got my favourites under the available Add-ons for my preferred Browser Firefox:

Tabs

Links

Language

Downloads

Development

I try to keep the number of the installed Add-ons small to avoid an “Add-ons-hell”. Are there any other indispensable useful Add-ons for Firefox?

  • Share/Bookmark
Categories: Best practices, Private Tags:

Favoured podcasts

November 1st, 2009 Patrick 2 comments

I migrated my desktop PC to Windows 7 Professional. I didn’t choose the upgrade path, I install Windows 7 from scratch. So, after installing iTunes I had to register my favoured podcasts again:

.Net

Java

Currently I work in a .Net environment, so the list of .Net podcasts is a bit longer. If you are interested in more Java podcasts, there is a question about that topic on Stackoverflow. The following three podcasts are definitely interesting:

Do you have other interesting podcasts?

  • Share/Bookmark
Categories: .Net, Java, Private, Software engineering Tags:

Kaizen and Software Engineering

October 27th, 2009 Patrick 3 comments

Kaizen is a very interesting approach, also in the software industry. On Wikipedia you’ll find the following description of Kaizen:

Kaizen is a Japanese word adopted into English referring to a philosophy or practices focusing on continuous improvement in manufacturing activities, business activities in general, and even life in general, depending on interpretation and usage.

Kaizen aims to eliminate waste, to improve the process or activities (techniques). I heard about Kaizen the first time at an economic course, and I found the Muda (seven wastes) very interesting. I tried to find locations or situations where you can detect such wastes:

Overproduction

Overproduction happens each time you engage more resources than needed to deliver to your customer. For instance, large batch production, because of long change over time, exceeds the strict quantity ordered by the customer. For productivity improvement, operators are required to produce more than the customer needs. Extra parts will be stored and not sold. Overproduction is the worst Muda because it hides or generates all others, especially inventory. Overproduction increases the amount of space needed for storing raw material as well as finished goods. It also requires a preservation system.

Overproduction happens then, when you don’t follow the YAGNI principle. Don’t try to make assumptions about the future or the customers. Just produce the things as simple as possible.

Unnecessary transportation

Each time a product is moved it stands the risk of being damaged, lost, delayed, etc. as well as being a cost for no added value. Transportation does not make any transformation to the product that the consumer is supposed to pay for.

Don’t build chatty interfaces, make use of the coarse-grained interface pattern.

Inventory

Inventory, be it in the form of raw materials, work-in-progress (WIP), or finished goods, represents a capital outlay that has not yet produced an income either by the producer or for the consumer. Any of these three items not being actively processed to add value is waste.

Deliver early and often. Don’t wait at the end of the project to deliver the whole software at once. If you deliver your software earlier and often, you will receive more feedback and so the costs to fix bugs will reduce. Also the customer will be happier because he could use much earlier important parts of your software and he could observe better the progress of the software project.

Motion

As compared to Transportation, Motion refers to the producer or worker or equipment. This has significance to damage, wear, safety. It also includes the fixed assets, and expenses incurred in the production process.

Good hardware and a good chair is very important to be productive. Slow computers are just horrible to work with and a bad or cheap chair is not very good for the health of the software engineers. If the software engineer feels comfortable, he’s much more able to be concentrated or work longer.

Defects

Whenever defects occur, extra costs are incurred reworking the part, rescheduling production, etc.

Reduce Defects. Unfortunately there doesn’t exists a programming language where it isn’t possible to make no errors. So testing is absolutely necessary. Do unit testing with or without TDD, but a modern software project should have tests (unit tests, integration tests or acceptance tests, etc.). Without tests you don’t have a safety net (regression tests) if you change something in your project. One of the worst error a customer could find is one which he already found and was fixed.

Over-Processing

Over-processing occurs any time more work is done on a piece than what is required by the customer. This also includes using tools that are more precise, complex, or expensive than absolutely required.

Overengineering and Patternoholics are a danger to do more than it is necessary.

Waiting

Whenever goods are not in transport or being processed, they are waiting. In traditional processes, a large part of an individual product’s life is spent waiting to be worked on.

Slow computers where you have to wait for a build step or just for the compiler are an unnecessary waste. Also if you wait for an answer from your customer or an other teammate. Don’t wait, make a follow-up, make a phone call or write an other mail. Also don’t let the others wait. If you receive an email, answer it or write a short email to say that you will response later, so that the other knows, that you saw his mail and you planed to response him.

Conclusion

One important question is: “Do you add value to your solution, product or service which the customer is ready to pay for?” This question or view isn’t new. It focus all the actions in software engineering on business value, the value which the customer pays for. To reduce the waste you have to improve (Kaizen) your code, methods and communication with others. The seven wastes are a help to find locations or situations where waste could happen.

  • Share/Bookmark

Fail Fast principle

September 22nd, 2009 Patrick 5 comments

Recently I received a NullReference-Exception when I called another method from a foreign component. Fortunately I had the source code of this component and I found the following code:

public class AgeValidator
{
	public Dictionary<string, int> Config { get; set; }

	public bool Validate(int nAge)
	{
		int nMinAge = FindValue("MinAge");

		return nAge > nMinAge;
	}

	private int FindValue(string strParameter)
	{
		int nValue = -1;

		if(this.Config.ContainsKey(strParameter)) nValue = this.Config[strParameter];

		return nValue;
	}
}

There are several problems with this code. First, there are no preconditions which checks if the object is in a valid state or the parameters are valid. This cause to behaviour which isn’t intended. The problem with a not available configuration could already detect in the Validate method. The Find method could check if the parameter is valid, if not it doesn’t make any sense to continue. The FindValue method doesn’t follow the Fail Fast principle. Jim Shore wrote an excellent article about the Fail Fast principle. After a refactoring the code looks like that:

public class AgeValidator
{
	public Dictionary<string, int> Config { get; set; }

	public bool Validate(int nAge)
	{
		if(this.Config == null || this.Config.Keys.Count == 0) throw new InvalidOperationException("No valid configuration available.");

		int nMinAge = FindValue("MinAge");

		return nAge > nMinAge;
	}

	private int FindValue(string strParameter)
	{
		if(string.IsNullOrEmpty(strParameter)) throw new ArgumentNullException("strParameter");
		if(!this.Config.ContainsKey(strParameter)) throw new ArgumentException(string.Format("No configuration for the key '{0}' found.", strParameter));

		return this.Config[strParameter];
	}
}

What I advise junior software developers is to follow the Fail Fast principle, disciplined use of preconditions and if it adequate the use of postconditions. But all these advices don’t replacing unit testing.

  • Share/Bookmark

To be a model

September 9th, 2009 Patrick No comments

Currently I study for a MAS-IT. Last semester came a photograph and asked if he could take some pictures. So I thought nothing of it and I continued discussing with my colleagues about a topic.
Today I saw on the page of the Berner Fachhochschule, Technik und Informatik two images with me:
bfh1
And here:
bfh2
That’s funny. Normally I describe models, but now I’m the model.

  • Share/Bookmark
Categories: Private, Software engineering Tags:

NHibernate mapping possibilities

August 24th, 2009 Patrick 1 comment

I prepare currently a new talk about NHibernate. In this talk I’ll show the different mapping possibilities with NHibernate. To demonstrate the three possibilities (and a fourth one) I chose a quite simple model: I implement three classes Cat, Dog and Bird an for each one I chose a different mapping approach. For my little sample application I used NHibernate 2.1.0, NHibernate.Mapping.Attributes 2.1.0 and Fluent NHibernate 1.0.0.545.

NHibernate classic style – XML-Files
For the class Cat I chose to use the classic way to map the class.

public class Cat
{
	private string id;
	private string name;
	private char sex;
	private float weight;

	public virtual string Id
	{
		get { return id; }
		set { id = value; }
	}

	public virtual string Name
	{
		get { return name; }
		set { name = value; }
	}

	public virtual char Sex
	{
		get { return sex; }
		set { sex = value; }
	}

	public virtual float Weight
	{
		get { return weight; }
		set { weight = value; }
	}
}

And the XML-File Cat.hbm.xml looks like:

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" namespace="NHibernateTest.Domain" assembly="NHibernateTest">
	<class name="Cat" table="Cat">
		<id name="Id">
			<column name="CatId" sql-type="char(32)"/>
			<generator class="uuid.hex" />
		</id>
		<property name="Name">
			<column name="Name" length="16" not-null="true" />
		</property>
		<property name="Sex" />
		<property name="Weight" />
	</class>
</hibernate-mapping>

This approach has different problems: You couldn’t easily refactor your POCOs, you have to adapt the hbm.xml files too. Another problem is that you write your entity twice: in C# and in XML, so there is a lot of noise. This is the entry point for code generation, but it isn’t a real solution, it is just a workaround to handle the necessary XML file correctly and to reduce errors by manual writing.

NHibernate.Mapping.Attributes
For the class Dog I prefer the attributes to map the class. In JPA it is my preferred way for simple and small projects, so I was very interested how they ported this approach to .Net.

[Class(NameType = typeof(Dog))]
public class Dog
{
	private Guid id;
	private string strName;

	[Id(0,
	Column = "ID",
	Name = "ID",
	TypeType = typeof(Guid),
	UnsavedValue = "(00000000-0000-0000-0000-000000000000)"
	)]
	[Generator(1, Class = "guid.comb")]
	public virtual Guid ID
	{
		get { return id; }
		private set { id = value; }
	}

	[Property(0, Column = "Name",
	Name = "Name",
	TypeType = typeof(string),
	Length = 50,
	NotNull = false
	)]
	public virtual string Name
	{
		get { return strName; }
		set { strName = value; }
	}
}

Without the property NameType in the Class-attribute the sample doesn’t run. Another thing which disturbs me is the noise in the code by the attributes. It isn’t a clean POCO approach, also because the needed specific using statements.

Fluent NHibernate
Finally there is a third approach how to map a class. To demonstrate this possibility a use the Bird class:

public class Bird
{
	private Guid id;
	private string strName;

	public virtual Guid ID
	{
		get { return id; }
		private set { id = value; }
	}

	public virtual string Name
	{
		get { return strName; }
		set { strName = value; }
	}
}

For the mapping you have to use an additional class, which looks like that:

public class BirdMapping : ClassMap<Bird>
{
	public BirdMapping()
	{
		Id(x => x.ID);
		Map(x => x.Name);
	}
}

This approach is really interesting. You separate your mapping from your entity, but the mapping is written in the same language like the entity itself. So you can profit of the refactor features of your IDE or of an additional tool like Resharper.

Use all together in the same project
I tried to run all the three possibilities in one project and I used a factory method to create the NHibernate configuration instance. This method looks like that:

public static Configuration CreateConfiguration()
{
	Configuration config = new Configuration();
	config.Configure();

	// XML-Files
	config.AddAssembly(Assembly.GetExecutingAssembly());

	// Attributes
	HbmSerializer.Default.Validate = true; // Enable validation (optional)
	HbmSerializer.Default.Serialize(System.Environment.CurrentDirectory, Assembly.GetExecutingAssembly());
	config.AddDirectory(new DirectoryInfo(System.Environment.CurrentDirectory));

	// Fluent
	config = Fluently.Configure(config).Mappings(m => m.FluentMappings.AddFromAssemblyOf<Program>()).BuildConfiguration();

	return config;
}

In a real world application I wouldn’t recommend a such configuration. An architect should decide which mapping approach is adequate. But this code snippet demonstrate that it is possible to use all three mapping possibilities at the same time.

The secret fourth possibility
When I study NHibernate Fluent I saw on their wiki the possibility to use their Auto Mapping.

private static Configuration CreateAutoConfiguration()
{
	var config = Fluently.Configure()
				.Database(MsSqlConfiguration.MsSql2005.ConnectionString(@"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Test.mdf;Integrated Security=True;User Instance=True")
							.ShowSql())
				.Mappings(m => m.AutoMappings.Add(AutoMap
								.Assembly(Assembly.GetExecutingAssembly())
								.Where(t => t.Namespace == "NHibernateTest.Domain")))
				.ExposeConfiguration(cfg => new SchemaExport(cfg).Create(false, true))
				.BuildConfiguration();

	return config;
}

The other three possibilities are a little bit different: there you define the mapping for each entity, which is more or less the opposite. You map by default all your entities by convention over configuration and only the exceptions have to be declared explicitly. Note that it is even possible to generate the DB schema with the ExposeConfiguration method.
For greenfield applications or prototypes it is a great way to map your entities, but for brownfield applications it is much harder to use. This is the case when you couldn’t discover a pattern in the database or in the entities, which you want to map. In a such scenario I would prefer one of the three other possibilities.

  • Share/Bookmark
Categories: .Net, Software engineering Tags:

Reason of silence

August 13th, 2009 Patrick 3 comments

Why is there no blog entry for the July and for the half of august? Well, the answer is, that my current project where I’m the project manager and and also the leader of a team of software engineers, comes to an end.
Currently we implement the last features like reports (reports are very important for transparency and let the customer gain trust in your/his application) or a batch process. Also the data migration and the reports about the migrated data are in progress.
So, I hope I could summarize my experiences here in September and blog a bit more about interesting technologies.

When you follow me on twitter, then you maybe know that I practice my Groovy/Grails knowledge with a sample application which I publish on kenai.

  • Share/Bookmark
Categories: Private, Software engineering Tags:

From NUnit to MSTest

June 30th, 2009 Patrick 6 comments

Last week I migrated several projects from NUnit to MSTest. The developers use the Developer version of Microsoft Visual Studio Team System, so they have integrated unit-test support for MSTest. In this post I show you all the problems and work I had to migrate the tests from NUnit to MSTest.

Less assert-methods in MSTest
In NUnit you have comparison assert methods, exception asserts, more type asserts, more utility asserts and so on (you see what I mean). There already exist little projects to add more assert methods for MSTest.
The problem with less assert method is the following:

Assert.Greater(nCount, 5);

This snippet is much more readable and maintainable than the following:

Assert.IsTrue(nCount > 5);

But that’s just my opinion. There are for sure people who like the second snippet more than the first one.

Attribute mappings
When you planning to migrate your NUnit Tests to MSTest you will need a mapping between the attributes of NUnit and MSTest. You’ll find on the internet mostly the following configuration:
[TestFixture] -> [TestClass]
[Test] -> [TestMethod]
[SetUp] -> [TestInitialize]
[TearDown] -> [TestCleanup]
[TestFixtureSetUp] -> [ClassInitialize]
[TestFixtureTearDown] -> [ClassCleanup]
That’s fine, but wait a minute! For two of those mappings you couldn’t just use find and replace. TestFixtureSetUp and TestFixtureTearDown aren’t static methods in NUnit. Methods with the attribute ClassInitialize or ClassCleanup has to be static. The method with the attribute ClassInitialize has even a parameter Testcontext. For those two methods you have to do a little bit more work.

TestFixtureSetup vs. ClassInitialize
As I mention above the difference between the attributes TestFixtureSetup and ClassInitialize (or TestFixtureTearDown and ClassCleanup), there’s still the question which one is conceptionally correct. Or why Microsoft did it different in comparison to NUnit.
I found the interesting answer in the book xUnit Test Patterns of Gerard Meszaros (on p. 384). Microsoft implements the JUnit approach, what means there will be for each test method a new instance of the test class. James Newkirk (one of the authors of NUnit) regret the decision in NUnit to us the same instance for all the test methods.

Ignore-attribute, no comment
The developers used a lot the attribute ignore in NUnit to deactivate unit tests for explorating testing. In NUnit you could add a comment to justify why the test should be ignored.
In MSTest the ignore attribute does also exists, but you couldn’t add a comment.

Resharper & MSTest
Since Resharper 4.5 you could also use this amazing tool with MSTest. Before the version 4.5 it was also possible to use it with MSTest, but you have to install a plug-in to do that.
From my perspective the Resharper unit test runner is much more better than the Visual Studio test runner.

ExpectedException and Visual Studio
In Visual Studio Professional and above you have an integrated unit-test runner (similar to eclipse, netbeans, etc.). There were a lot of unit-tests which expected an exception with the type Exception. That’s works fine in Resharper, on the build server (TFS) but not in the test runner of Visual Studio. Here you’ll receive the following warning:
UTA017: MyUnitTest has invalid ExpectedException attribute. The type must inherit from Exception.
This is a bug of the test runner, as others already described.

Execute several assemblies
One of the projects which I migrated from NUnit to MSTest runs unit tests of different assembles. So it had a nunit-file like that:

<NUnitProject>
    <Settings activeconfig="Web">
    <Config name="Web" appbase="Web" configfile="web.config" binpathtype="Auto">
        <assembly path="bin\Product.NUnit.ComponentA.dll"/>
        <assembly path="bin\Product.NUnit.ComponentB.dll"/>
        <assembly path="bin\Product.NUnit.ComponentC.dll"/>
    </Config>
</NUnitProject>

I didn’t found a way to do that in MSTest. So I asked this question on stackoverflow. Unfortunately there aren’t a lot of answers until now.

Conclusion
With the migration the developers gain code coverage and the integration of unit-testing in Visual Studio (for those who hadn’t Resharper). On the other hand they lost readability, because they have to express an assertion with code with a primitive assert method.
If I could give you an advice, it’s the following: Migrate, if you have at least one of the Visual Studio Team System Editions (Developer, Test or Suite). With Visual Studio Professional (integrates a unit-test runner) and without Resharper, it is also an option to migrate to MSTest.

  • Share/Bookmark
Categories: .Net, Testing Tags: