Category Archives: Uncategorized

See more conversion options in preview in OS X 10.8

See more conversion options in preview in OS X 10.8

Lets say you have a file (image.png) and you want to convert it to a BMP for whatever reason. It seems in OS X 10.8 you can still do this, but the options are a bit hidden.

This link gives the hint to do this. Within preview you need to hold the “option” key first so you can choose “save as”. After that you still need to hold the option key when you use the ‘format’ dropdown so you can select the BMP format. If you don’t do this, you will not see the BMP format.

The making of Stefan Hendriks

Do you have facebook? If so, then you are probably familiar with the timeline feature.

I have decided to write up a timeline about myself. It gives a view of who I am, what I did, when and how I got influenced. It also showcases my projects in a chronological order.

If you want to read the timeline, head to the making of Stefan Hendriks!

(Win 7) How to really change your default locale for Java

Since I could not find an easy solution for this problem I have decided to blog about this.

Lets say your machine (running Windows 7) is running in a Dutch locale. If you install the JDK and request the default locale in your application you will get: nl_NL

I’m testing this with the following code:
[sourcecode language=”java”]
import java.util.Locale;

public class DefaultLocaleTester {

public static void main(String[] args) {
Locale defaultLocale = Locale.getDefault();
System.out.println("Default locale is : " + defaultLocale);
}
}
[/sourcecode]

Lets say I want to make this return en_US. The official docs of Oracle say that you should change your system settings:

– go to Control Panel
– go to Region and Language
– go to tab “Administrative”
– click “Change system locale”
– change to locale you want
– restart and you’re done!

So we do this, and we run the test application again.

You will found out, this will not work. When I rerun the test application I still got nl_NL.

On stackoverflow someone had the answer to this problem. You should be changing your Format instead. So:

– go to Control Panel
– go to Region and Language
– go to tab “Formats” (is default selected)
– change language in Formats dropdown to the locale you want

Now re-run the test code, and you’ll see it will be using the locale you want.

Thanks to Martin Bartlett on Stackoverflow for his answer!

The ‘unit’ in unit testing; and kinds of unit tests.

Recently I had the oppertunity to explain some students about what unit testing was. I started off with the question of “What does unit testing mean?”. They gave different types of answers. One of them talked about the smallest piece of code. And even though he is ‘right’. I asked him to apply this knowledge to his current code where he said “But I don’t want to test my get/set methods, that is useless!”. And so, our definition of ‘unit testing’ became unclear again.

So what is a unit test? According to this article on wikipedia “A unit is the smallest testable part of an application”. But what does that mean? What is the ‘smallest testable part’? Do you need to test get/set methods? Do you need to test assigning values? Yes and no.

Even though the smallest testable part is related to lines of code, I believe it also is related to behavior. I think a better description for unit testing would be to test the smallest piece of behavior of an application. Most of the time you probably will be testing very little pieces of code with it. As long as there is some behavior (context) you want to test.

So do get/set methods fall into this category? Depends… Get/Set methods in themselves are, without context, useless. Returning a value or setting a value is not much worth of testing. However, if you test a method that calls a get/set method and does something with it, that is another story. When code is executed within a certain context, it is perfectly valid to unit test it. An example: getTotalPrice that just returns a value “price” is not worth to be testing. A getTotalPrice that does some calculation is a good candidate to test!

With software development, it is the expected behavior of the software that matters. I compare this with designing interfaces (seperating what and how), where you’re busy thinking what you would expect from a certain object when using it. The behavior of the software; how it presents itself and how the user can interact with it (the how), is different from how the software realizes this behavior (the what). When thinking in terms of behavior when writing code, we force ourselves to think of what the software should be doing, and not *how* it should be coded to do that. Test Driven Development is a way of forcing you to write code that has a good design. It clearly a functional (behavior) point of view.

With that said, a unit test should aim to test the smallest possible piece of behavior. When a total price is shown. There are a few steps taken before it is shown on the screen. One of the important behaviors is that the totalprice is calculated somewhere. Testing the calculation of the totalprice is a unit test. This is a State based test. (Does the class give expected output X when using input Y?)

The totalPrice is calculated from certain input. The output is shown on the screen.
A controller class is putting input and output together, making sure the totalPrice is being calculated and pushed to the view. Making sure that the controller uses its collaborators to do that is also a unit test. This is called a collaboration test. (Does my class call the collaborators that I expect, with the parameters I expect?, yes you do that by Mocking)

Even though with these two tests, you still miss an important type of test. You still need to test if your interfaces behave as they say they should. Should you test interfaces of external (3rd party) API’s? Probably not. Unless you have a reason to distrust your supplier of the API. Testing interfaces are called Contract Tests and look a lot like State based tests. These tests are making sure your expectations about the interfaces are validated! If you don’t do that you will get defects, even though you test states and behaviors.

Last but not least. It is useful to test broader pieces of behavior. For example, if you use Spring to bootstrap your webapp. You probably need to make sure everything is autowired correctly. That is an integration test. There are multiple types of integration tests. An often used integration test is to connect to a database, put data in, fire up some methods and test their behavior. All of them are integration tests. Hence, even testing whole pages (end-to-end tests) using Selenium, those are also integration tests, although at a much higher level.

In time I will blog more about the type of unit tests.

2010 in review

The stats helper monkeys at WordPress.com mulled over how this blog did in 2010, and here’s a high level summary of its overall blog health:

Healthy blog!

The Blog-Health-o-Meter™ reads This blog is doing awesome!.

Crunchy numbers

Featured image

A helper monkey made this abstract painting, inspired by your stats.

A Boeing 747-400 passenger jet can hold 416 passengers. This blog was viewed about 4,300 times in 2010. That’s about 10 full 747s.

In 2010, there were 4 new posts, growing the total archive of this blog to 15 posts.

The busiest day of the year was September 1st with 40 views. The most popular post that day was EasyMock Class Extension – IllegalStateException on expect method.

Where did they come from?

The top referring sites in 2010 were d2tm.duneii.com, social.answers.microsoft.com, fundynamic.com, fundynamic.nl, and forum.dune2k.com.

Some visitors came searching, mostly for no last call on a mock available, “no last call on a mock available”, easymock no last call on a mock available, no last call on a mock available easymock, and no last call on mock available.

Attractions in 2010

These are the posts and pages that got the most views in 2010.

1

EasyMock Class Extension – IllegalStateException on expect method June 2009

2

Windows 7 64bit and iTunes 9.02 sync problems November 2009
7 comments

3

Itunes and Windows 7 64 bit hot-fix – Did it work for you? December 2009
4 comments

4

Using Slick to write 2D Java games February 2010

5

A Software Quality Model (Part I) May 2010
1 comment

A Software Quality Model (Part II) – Translating customer language into metrics, scoring quality

In my previous post I have explained the context of my thesis, and the various software quality models that are evaluated.

For my thesis I have extended the Software Quality Model of Willmer. Although it is not an exact implementation of the model, it is inspired by it. Also, the influence of the customer is processed into this model. The goal of this model is to translate customer desires into metrics, in order to calculate the total quality.

When talking about software quality, it is either very concrete (I want a red car!) or very abstract (it has to be reliable!). Customers tend to tell their ‘experiences of quality’ in sentences. This is the first step of the model. Try to get a few (eight at most) of these sentences. They must be distinctive. (Don’t have four sentences preach about security…)

Translating these sentences into concrete, measurable ‘things’ for developers, is another story. But before doing that , ask your customer what the relative importance is of all these sentences you just have written down. Just imagine that there is this situation where you have to go live. But , there is an issue that needs to be tackled, all blocking, one for each aspect (sentence). If you could pick one, which would you pick? Would you tackle the first sentence, the second? etc?

Of course, your customer will would tell  in his own domain language what the most important thing is. Try to map that (and confirm) with these sentences. Score them and try to get an ‘order of importance’. After you have done that, you have your first important goal reached: You know the relative importance of each quality sentence (aspect from now on).

So, what now? The next step is to map these aspects/sentences to Software Quality Attributes (also known as non-functional requirements). You either need a Software Engineer to do that, or even better, try to do it with your team. Before mapping these, try to make a selection of Quality Attributes first that are most relevant to you. Ie, try to use tree of Boehm or ISO9160 as reference. Within my theses I have used 9 Quality Attributes, some Quality Attributes are ‘sub-quality attributes’ of others. Example of Quality Attributes: Understandability, Reliability, Security, Availability, Complexity, etc.

The result of this mapping is that you get for each aspect several quality attributes. Not all quality attributes are applicable to an aspect. Try to figure out how much quality attributes are applicable to an aspect. Do this by asking teammembers and for each member that selects a quality attribute, score it. This way you can calculate relatively how your team thinks the mapping should be. This is important, because the eventual result of your measurement (see below) should be the product of the customer and the team that work on that product.

So, you have a few aspects, and each aspect has a few quality attributes. All that is left is to map metrics to quality attributes. Mapping this is fairly easy, there are quite a bunch of metrics out there. Each metric tries to measure (a piece of) a quality attribute. Some are easy, like complexity (quality attribute) can be measured by (although it is not limited to) the Cyclomatic Complexity metric by McCabe.

So basically you end up with this:

Aspect(n..8) –> Quality Attribute(n) –> Metrics(n)

Where:

  • the total quality of the system, is the combination of all aspects (all aspects relativity make 100%)
  • you should keep eight aspects (believe me, more will only make it harder to distinguish and make decisions)
  • you should attach quality attributes to each aspect, and determine their relative applicability to this aspect
  • you should attach metrics to quality attributes

So in the end, how do you score quality? Is it possible with this model? Yes, certainly it is.

Once you have found metrics, and attached them to quality attributes. You should formulate ‘scoring rules’. This means, you need to write down how you will interpret results of a metric and translate that onto a scale of 1 to 10. A scoring rule could be:

“Lines of Code (LOC) may be 1000 for a file max. Every 100 lines more substracts one point. (Giving 10 points with 1000 or lower and with 2000 lines a 1)”

This means, a LOC of 1000 will score a 10. A LOC of 1500 scores a 5, a LOC of 2000 or higher scores a 1.

Do this for all metrics, and eventually you will be able to calculate the total quality of the system.

In order to make this more concrete, here an example of such a calculation:

Total Quality Score = sum of scores of each aspect

Aspect score = (Sum of all relative scores of all applicable attributes) * relative importance

Attribute score = (Sum of all relative scores of all applicable metrics)

Example (For the sake of this example, attributes are scored already)

Aspect #1

Is for 30% important (relative to Aspect #2)

Attributes:

A -> for 40% applicable

B -> for 60% applicable

Aspect #2

Is for 70% important (relative to Aspect #1)

Attributes:

C -> for 70% applicable

B -> for 30% applicable

Scoring:

Attribute A scores 7 (out of 10)

Attribute B scores 5 (out of 10)

Attribute C scores 8 (out of 10)

Total quality calculation:

Aspect #1

A = 7 * 40% = 2,8

B = 5 * 60% = 3,0

Absolute score is 2,8 + 3,0 = 5,8

Aspect #2

C = 8 * 70% = 5,6

B = 5 * 30% = 1,5

Absolute score is 5,6 + 1,5 = 7,1

Total quality is:

Aspect #1 –> 5,8 * 30% (importance) = 1,74

Aspect #2 –> 7,1 * 70% (importance) = 4,97

Total quality score is 1,74 + 6,71 ==> 6,71

6,71 on a score of 1 to 10 (1 being bad, 10 being best).

Itunes and Windows 7 64 bit hot-fix – Did it work for you?

In my previous post I have mentioned a Windows hot-fix for the synchronisation bug you may encounter using Windows 7 64 bit and iTunes 9.0.2.

I can see in the stats that many people have found this blog post. The big question remains: Did it work for you?

Please let me know (add a comment to this post).

Windows 7 64bit and iTunes 9.02 sync problems

Do you have Windows 7? Perhaps the 64 bits version? Do you have an iPhone, iPod?

Do the following things happen when you try to sinc with iTunes?

– your iphone stops saying it is synchronizing, but iTunes still thinks it is.
– your computer becomes very slow, so slow you actually have to restart it in order to
do your daily things again.
– synchronisation works fine only for Contacts or Calendar items.
“heavier” stuff (ie photo’s or
music) causes the symptoms above.

Don’t worry: You are not alone.

In fact many others have been suffering from the same issue. But, there is hope.

I have tried several ‘solutions’: An XML trick, tweaking your power manager, lowering your max ram or disabling your “standard enhanced pci to usb” device. But I was still not satisfied with the ‘fix’ or ‘workaround’.

The first 2 only work temporarily, or not at all. The 3rd is not desirable, I had installed Win 7 64 bits, so I could use all my 4 GB of RAM.

The last one though works ok, but it disables your USB 2.0 support and thus makes synchronisation very very slow.

I figured that since this seemed to be related to  the USB ports (ie, the last ‘fix’ worked), I dug into Win 7 64 bits USB port related problems. I had found this particular problem. It kind of had the same symptoms, and I found some saying it also infected the iPhone/iPod synchronisation. And, the best news is:

Microsoft have brought up a hot fix to solve this issue

I have tested this fix (just like I did with all the others I have described) and I am glad to say that it works!

If you cannot find it, try this . It has some unofficial download links that may work for you.

I hope it  helps you out, it sure did for me.

Eclipse IDE for C++

I’ve been working with Eclipse for at least 2 years. When I just learned of Eclipse I was mostly programming C / C++ using Visual Studio 6, which I bought zillion years ago.

Eclipse was a whole new world to me, offering all the convenient tools (like finding references, go to class, etc) a Java programmer could need. 

All my hobby projects are mostly written in C / C++ using the old Visual Studio version. It worked well, but after getting used to Eclipse, going back to Visual Studio 6 was like going back to the stone age. Of course, at this time Visual Studi0 7 is already out-dated; If I’m not mistaken, version 9 or 10 is around the corner.

Good news though, there is an Eclipse version where you can develop in C / C++ using the Eclipse IDE. It is available here. You have to use it in combination with a compiler. To get started, I have used MinGW which is easy to set up. Grab that from here

The good thing is, once MinGW was set up correctly, Eclipse automatigically found it (I bet it used the PATH variable) and you could try to compile your first “Hello world” program. 

My first impressions are good, the C++ IDE is actually like the Java variant with all the handy tools.  The performance is good, it works good, It has Doxygen built in for you. All in all I am quite satisfied. Also, I am quite happy that it exists, since Dev-Cpp and Code::Blocks is not being updated. I thought Dev-Cpp had a lot of potential, especially with the built-in packages.

If you ever consider to use an IDE (you don’t need it!) for writing C / C++ programs, you should definately give the Eclipse IDE for C++ a try.