Wednesday, May 17, 2017

Stack Overflow merge

Please merge account https://stackoverflow.com/users/28553/redsolo and https://stackoverflow.com/users/8019481/redsolo

Monday, November 23, 2009

Reply to an "Android vs Windows Mobile" post

This is a response for the "Windows Mobile vs. Android: WinMo Is Better Than You Think" blog post. That blog post might at first look unbiased but it isn't; the author must have skimmed the android #101 class and missed vital parts.

Multi-tasking - Big advantage: Windows Mobile
"Anyone who has run an Android phone for more than a few minutes should fire up a task manager and have a look. You’ll likely see 20 or more tasks running in the background, not unlike WinMo."
Yes, you will see the applications which consists of services and Activities (ie a Form, Dialog or Window), but the big difference is that those activities are NOT running at the same time as your main activity (the one that is on the front). If you want multitasking, then look at the running services. On WinMo they background applications are still RUNNING, they are consuming both memory and CPU, that is one big difference between Android and WinMo.

"WinMo automatically changes memory allocation based on the needs of each app, and if the system memory starts to get stretched thin, the OS shuts down background tasks automatically."
How is the priotization done? For Android it is a clear priority path, first all activities that are not showing is killed, then it starts killing of services and lastly the activity in the front. On WinMo, it is not soo clear. How will WinMo distinguish an application for checking emails from the Chess application you stopped playing 2 days ago?

The post also forgets to mention that the android framework will bring your activities back into memory after they have been swapped out. That way the user will not notice that an application (or actually activity has been swapped out because of the lack of memory. Does WinMo do anything even close to bring an application back up? No! Android has framework support for making it seamless.

About memory, the Windows Mobile 6.5 (and all older versions) has an application memory limit of 32MB. Shared DLLs will eat up that memory if they have been loaded in a bad way. Please read http://msdn.microsoft.com/en-us/library/ms836325.aspx for more info on how one application can reduce the available memory for another application. It is amazing that an OS in 2009 can have this limitation.

Multitasking on android is a more modern approach than WinMo has (or PocketPC as nothing has really changed). It helps the developer of creating a never ceasing, seamless user experience. I have NEVER had the phone freeze so it has to be rebooted because of a faulty application. That happens on WinMo now and then. Why is it even possible for an application to nuke an OS?

Yes, Android has a big problem with the SD card issue, but comparing that to multitasking is like comparing apples and bees.

Available apps - Advantage: Windows Mobile
"Not a lot of apps are in there yet, which is not surprising given how new the store is to the market. "
iPhone had 3,000 applications after the first month. How many does marketplace have today? 400, 500? It is time for MS to put their money where their mouth is. When iPhone started saying that they have so and so many apps in their appstore, MS boasted that there were over 20,000 apps available for WinMo. But where are they? Why don't the developers deliver the applications to the best place to sell and advertise an application? You also forget to mention that the marketplace has a 10mb limit, what does that do to real games?

"Opera Mobile 10 is as good as any mobile browser out there on any platform, and it is free for Windows phone users. It is so exceptional that HTC has been using it as the default browser on its WinMo phones for years, and with good reason. It demonstrates the quality and quantity of apps available for the WinMo platform"
Android has opera as well, AND a web browser based on the webkit engine (google it, if you dont know it). Opera is a great software, but it does not equal that all other apps for WinMo is great. Im not saying that Android applications are of a higher quality as there are a few ones that will crash and burn but thankfully they dont bring the OS down with them.

User interface - Advantage: Windows Mobile
"Spb Mobile Shell has been out for years, and the latest version is for WinMo what Sense is for Android. The difference is that Mobile Shell is user obtainable, where HTC Sense must be installed on a phone as purchased."
I guess you have missed the other Home replacements? There are several ones that allows the user to custom design their front ends, search in the android market for "Home" and you shall find.

"Android phones with the stock interface are pretty plain Jane, as is the WinMo interface."
It is not possible to say, with a straight face, that vanilla WinMo is as good as vanilla android if you have used the two of them next to each other. None of them of course looks as good as the iPhone.

"The end result is that a WinMo phone running Sense is as good as an Android phone running it."
Yes, Touchflo and Sense are great front ends and really responsive, but as soon as you get one or two steps away from it, you see the ugliness of the old WinMo UI. HTC has done a lot to hold WinMo under its arms, as they have been working mainly on the front end that is the only thing the user sees when looking for a new phone.

Then if someone could explain to me why the HTC Sense is more responsive than the WinMo 6.5 start menu when they are run on the same hardware? I have tried the HD2, and when you scroll up and down in the WinMo start menu it will do some strange jumps, which you cant see when using HTC Sense. Also, there is another problem here with a nice front end over the WinMo UI. The user will use fingers gestures to go back and forth from views to other views (which all modern phones should do),but as soon as you go into the WinMo UI you have to bring out the stylus to check a checkbox or something. Unfortunately the next WinMo 6.5.3 will not fix this, as just increasing the size of every control isnt the solution.

Computer desktop integration: Advantage: Tie
This section nails it, it all depends on if you are using exchange or gmail. I am a gmail user and Im quite happy, and I know HTC Hero users that use exchange and are happy with it. Of course using gmail on WinMo is now a viable option thanks to the Google exchange synchronization.

Last
I am a software developer that mostly work with the WinMo platform, and it doesnt go a week without me implementing work arounds for some undocumented change in an API. Especially today as the software is targeting Pocket PC 2003 to Windows Mobile 6.5.3. Add Smartphone to the mix and it is even more fun.

For a nice read on the HD2, check this out this review.

Monday, November 24, 2008

Sending WM_WININICHANGE message on device with HTC TouchFlo 3D will crash the device

Today I finally solved a very strange bug in a Windows Mobile project Im currently working on. The bug would only show up on HTC devices, and not our HTC devices we had at our location. After the application was installed and the user started it, the whole device would freeze and reboot itself after a minute or so.

After some digging around, rebuilding, re-installing for way too many times; we found out that if the HTC TouchFlo 3D today plugin was enabled the device would crash. With that knowledge I was able to pin point the location of the failure which was that the installation DLL sends a
WM_WININICHANGE message to refresh the PocketPc Today plugins.

As many
sites and forum posts states, this is the only way to refresh the Today plugins.

::SendMessage(HWND_BROADCAST, WM_WININICHANGE, 0xF2, 0);

Of course, this is not documented anywhere within MS documentation; and the
documentation that exists states that the wParam isnt used at all (which in fact it is).

It seems that the HTC TouchFlo 3D isnt capable of handling the
WM_WININICHANGE properly, and even just opening the calendar application after that sending that message will crash the device. So if your WindowsMobile application sends that message, I would advise you to look into this. Using the replacement message WM_SETTINGCHANGE does not change anything, the device will still crash.


One solution is to check if the HTC TouchFlo Today plugin is enabled, which can easily be retrived through the regkey
"HKLM\Software\Microsoft\Today\Items\TouchFLO 3D\Enabled". If it is enabled, then do not send the WM_WININICHANGE message.

Tuesday, November 04, 2008

Trying out SimplifyMedia on Debian

I just noticed SimplifyMedia, and wanted to start sharing music from my home media server. The server is running Debian etch (4.0), and there is no debian repository for it (not surprinsgly as it is not open source). Here's a short description on how I got it to work on my Debian machine.

Startup

  1. Download the package from SimplifyMedia Downloads.

  2. Unpack the contents to a folder

    tar zxfv simplifymedia.tar.gz

  3. Install all necessary debian packages to get the SimplifyMedia server running
    aptitude install libavahi-client3 libavahi-common3 libavahi-compat-libdnssd1 libavahi-core5 libc6 libdaemon0 libdbus-1-3 libfreetype6 libgcc1 libidn11 libpng12-0 libssl0.9.8 libstdc++6 libx11-6 libxau6 libxdmcp6 libxext6 zlib1g

  4. First you need to register for an account, start the SimplifyMedia GUI and enter all needed details. After registering close the GUI.

    simplifymedia/SimplifyMedia

  5. Start the simplifymedia server using the newly created credentials

    simplifyserver/simplifyserver.sh -n USER -l HomeTest -p PASSWD -s /home/media/Music/

  6. Now the server will start scanning your folders, and soon publish the location.




Gotchas/Problems

  • I'm using the Winamp plugin on my Windows XP laptop, and many of the files does not played when selected. This is a major issue, but I'm hoping it will be fixed soon.

  • The server did not find all my mp3's, it's currently missing 15% of my files.

  • Even though I'm almost sitting next to the server (using Wlan) the playback stutters sometimes.

  • There is no daemon support, so I need to fix something.

  • The password is shown in clear text when doing a ps aux



Impression
I was more impressed when reading about it than now after I've used it. The problems that it can not find all files, not able to play all files on a client; are a little too much for me to accept. But hopefully it will improve and become something great!

Tuesday, July 15, 2008

Hudson now supports Team Foundation Server

Today I released a plugin that adds support for Microsoft's source control manager Team Foundation Server to Hudson (a continuous integration server). The plugin makes it possible to retrieve files and poll the server to detect changes on a project. If Hudson detects a change, a new build can be started automatically. Hudson will also display the changes that occurred in each build.


Configuring the plugin is easy as it is only requires the server URL and the path to the project. Hudson will take care of the rest, such as creating a workspace and work folder to store the files in.


The plugin supports both the command line client in the Team Explorer package from Microsoft and the command line client from Teamprise. An upcoming version of the plugin will add support for the opentf command line client.

So if you wanted to give Hudson a whirl but couldn't use it because you were using TFS, now is the chance to try it out! For more information about this plugin, check out the wiki. There are also several other .NET plugins for MSBuild, NAnt, NUnit, FxCop, StyleCop and compile warnings. I'm currently working on a plugin that integrates CodePlex into Hudson.

Update: The plugin can be downloaded here, or through the update manager in Hudson.

Wednesday, May 28, 2008

Hudson adds support for StyleCop

Last week Microsoft released StyleCop (aka Microsoft Source Analysis for C#), a tool that analyzes C# code and enforces a certain code style (similar to Checkstyle). The tool will go through all C# source files and mark the code style violations. Now Hudson (a Continuous Integration server) together with the Violations plugin has added support for parsing the StyleCop XML report and display the results for every build.

The Violations plugin displays a trend graph over builds so it is real easy to see that your project is progressing in the right direction (decreasing the number of violations). As you can see the plugin also supports FxCop reports.


Each build will display a listing of the files that are violating the code style, and it is also possible to see the number of fixed (or introduced) violations for every build.


Clicking on a file will display excerpts from the C# code showing the violations.


Setup
Follow the guideline here after downloading StyleCop. Add the <Import Project="$(ProgramFiles)\MSBuild\Microsoft\SourceAnalysis\v4.2\Microsoft.SourceAnalysis.targets" /> to every csproj file that you are building within Hudson. When the VS project is built, StyleCop will store a file named StyleCopViolations.xml [Update, if you are using StyleCop 4.2 enter SourceAnalysisViolations.xml in the project folder. As of now, there is no way to store it elsewhere. The XML file contains all violations that were found in the Visual Studio project.

Hudson Configuration
To configure the violations plugin, enable the "Report violations" check box. If there are several VS projects in the build, you should use **/*/SourceAnalysisViolations.xml as it will find XML files in all sub folders.


After configuration, start a new build to analyze and display the StyleCop results in Hudson. To see a trend graph you need at least two successful builds.

Tips
  • Do not enable all rules, choose those that are valid for your organization and make sense for you.
  • Do not activate too many rules at first, as it probably will generate too many violations. Too many violations may be ignored by your co-workers, as it seems to be too much work to fix them all. When the most critical code style violations has been fixed, increase the number of rules.

Wednesday, May 21, 2008

Advance to the next Eclipse level by using the MouseFeed plugin

MouseFeed is the best eclipse plugin that I have tested/used in a while. The plugin will make you learn the eclipse keyboard shortcuts and thus be quicker when using Eclipse. If you are using the mouse or the menu bar to select an action, and there is a shortcut for the action, the shortcut will be displayed in a big message box.


The message box is not too big, but enough annoying so in order to never see it you are forced to learn the shortcuts. So you learn even if you don't want to!

Wednesday, May 14, 2008

Guide to building .NET projects using Hudson

In this guide I'm going to show how to set up a C# project on the Continuous integration server Hudson. I've been using Hudson on .NET projects since september and it works really well. I'm going to use Media Portal as the example project.

The below goals will be solved in this guide:

  • Get the source code from the Subversion repository
    • Link change logs to the repository browser using ViewVC
  • Build the project using MBuild

  • Run the tests using NUnit and display the results together with a trend graph

  • Publish artifacts from the build (nightly builds)

  • Run FxCop on an assembly and display warnings (linked with source code) and a trend graph

  • Search the source code for TODO, FIXME comments and display the open tasks with links to the source code

Initial downloads
The following files are needed besides Java (at least 1.5). Get the latest version of all files and notice that the Hudson file has the extension .war and plugins .hpi. This guide assumes that MSBuild, NUnit and FxCop are already installed and working.

Installation steps
I'm going to install Hudson into c:\Program Files\Hudson.

  1. Copy the hudson.war file to c:\Program Files\Hudson

  2. Start Hudson through "java -DHUDSON_HOME=data -jar hudson.war". Verify that you can access Hudson through http://localhost:8080

  3. Copy the plugins to c:\Program Files\Hudson\data\plugins

  4. Stop Hudson by pressing Ctrl+C in the command prompt where you started Hudson.

  5. Start Hudson again and you should be set to go.

Hudson system configuration
Follow the following steps to configure the tools that Hudson will use in building MediaPortal.

  1. Go to the System configuration at http://localhost:8080/configure.

  2. MSBuild Builder - Set the path to the MSBuild tool to C:\Windows\Microsoft.NET\Framework\v2.0.50727\msbuild.exe


MediaPortal job configuration

  1. Click the "New job" link at the home page.

  2. Enter the name "MediaPortal", check the "Build a free-style software project" and press OK.


Source code management
MediaPortal uses a Subversion SCM. Hudson supports CVS and SVN out of the box, but there are many plugins for other SCMs. After checking out the files from the repository Hudson will show the new change sets since the previous build in the Build page. A detailed view of change sets can be seen in the Changes page as the name of the developer, files that were changed and the comment for the change. Each change set is linked to the MediaPortal subversion repository browser, so it is easy to browse the actual file that changed.

  1. Press the Subversion radio button to configure the SCM.
  2. Repository URL=https://mediaportal.svn.sourceforge.net/svnroot/mediaportal/trunk/mediaportal

  3. Local module directory=.

  4. Press the Advanced button

  5. Repository Browser=ViewSVN, URL=http://mediaportal.svn.sourceforge.net/viewvc/mediaportal/

To test the configuration, press Save and then Build. The source code will be downloaded from the repository and put into the Workspace. If there were any changes in the SCM repository they can be viewed in the Changes page.


When the build is completed verify that it has checked out the code by going to the Workspace page. Using the Workspace page you can browse and view the files that has been checked out and it doesn't matter if the files are on the master or on a distributed slave!

Building the project
Im going to build a Release version of MediaPortal using MSBuild and the mediaportal.sln solution file. Hudson also supports NAnt and many other build tools through plugins.

  1. Click the "Add build step" and select "Build a Visual Studio project or solution using MSBuild."

  2. MsBuild Build File=mediaportal.sln

  3. Command Line Arguments=/p:Configuration=Release

To test the configuration, press Save and then Build. Now the source code should be updated if there any changes and then built using MSBuild. While the build is running you can check the Console log that is updated as the build continues.


Running unit tests and showing the result
Hudson can read NUnit XML reports and display the results of them for each build. If a test fails, then it will be displayed in the Status page. Hudson will also show how many builds ago a test failed (it's age); that way it is simple to see if a test failed in the current build. If a build has at least one failing unit tests then the build will become Unstable (yellow); otherwise it is marked as Successful (blue). After two builds you will get a trend graph showing the test results over time. To run the NUnit tests, I'm running nunit-console from Hudson after the MSBuild has compiled all files.

  1. Click the "Add build step" and select "Execute Windows batch command"

  2. Command=
    "c:\program files\nunit\bin\nunit-console.exe" MediaPortal.Tests\bin\RELEASE\MediaPortal.Tests.dll /xml=nunit-result.xml /config=test.config
    exit 0

  3. Check the "Publish NUnit test result report" and enter "nunit-result.xml"

Start a new build, now the unit tests will be run and their results are collected at the end of the build. When the build is completed, you can see how many tests there were, and how many failed, in the build in the Status page.

More information on namespace detail can be shown in the Test result page.

The test results are then displayed as a trend report. (This trend graph is copied from my python project, as it shows a variation over time)


Archiving build artifacts
It is good to archive the outputs (artifacts) from the build, so they can be retrieved later. This way it is possible to get a version of MediaPortal that was built a week ago, and compare the functionality to one built today. Hudson can be configured to store any number of files for each build, it can also be configured so only the latest successful build's artifacts are stored. As I'm not really sure what the output from MediaPortal is, I'm going to show how to archive the files for the MPInstaller.

  1. Click the "Archive the artifacts".

  2. Files to archive = MPInstaller\bin\Release\*

In the next build, Hudson will store all files in the MPInstaller release folder so it can be retrieved later even if there are newer builds available.


Analyzing code with FxCop
Hudson can collect output from several quality metric tools and show them for each build. Similar to the unit tests, they will be displayed in a trend graph. For .NET projects, it is good to use FxCop. FxCop analyzes managed code assemblies and can be very good to use but it may also generate too many warnings at start, in this example I will only use the security rules and analyze the Core.dll assembly.

  1. Click the "Add build step" and select "Execute Windows batch command"

  2. Command =

    "c:\Program Files\Microsoft FxCop 1.35\fxcopcmd.exe" /file:Core\bin\Release\Core.dll /rule:SecurityRules.dll /out:fxcop-result.xml
    exit 0

  3. Check the "Violations" check box, and set fxcop=fxcop-result.xml

Next build will take considerate longer time, as FxCop goes through the assembly and analyzes it to find potential problems. When the build finishes, you will see a nice summary on how many violations there are in the current build.

Finding source code comments
A nice plugin is the Tasks plugin as it will go through the sources, and find specific comments that should be watched. In this example I'm going to search for TODO or FIXME comments,

  1. Click the "Scan workspace for open tasks".

  2. Files to scan = **/*.cs

  3. High priority=FIXME

  4. Normal priority=TODO

If the plugin finds any comments in the source they will be displayed in the build page.

There will also be a trend graph so it is possible to monitor that the tasks are decreasing over time. Together with the summary on what comments were found, the full source code can be viewed.





Summary
I hope this was a useful guide to start building .NET projects with Hudson, one of the many CI servers. As shown above it does not take much configuration to start building a project using Hudson. The best way to start using continuous integration is to start building the project. Then focus on running unit tests and other quality metrics so you can monitor the quality progress on your project.

Currently there are some plugins in the pipeline that could be interesting for .NET developers:
  • A SCM implementation for Microsofts Team System

  • Support for CodePlex issues and Wiki words in change set comment. And a very simple configuration to check out code from a CodePlex project

  • Support for displaying coverage stats using NCover and MS own coverage tool

Tuesday, April 08, 2008

Start playing the Continuous Integration game for real

I read "The Continuous Integration Build Game" 6 months ago, just when I had found Hudson. The idea behind the game seemed so simple and at that time we had problems with people comitting code that broke the build and failed the (very few) unit tests. I thought that the game could help out, as people like competitions and they would try to "win" the game. To win the game the developers have to commit code that is compiling and add unit tests.

The rules of the game are:
* -10 for breaking a build
* +1 for doing a build with no failures
* -1 for each new test failures
* +1 for each new test that passes

The plugin is more a proof of concept than a real full fledged plugin that will suit everyone. Thus the points for each rule are hard coded and can not be changed in this release. So if you are finding this plugin useful let me know.

For each build you will get a summary stating how many points the build was worth, and if you want you can see what rules that were involved.

The plugin installs a leader board on the front page, which shows who are on top.

Monday, April 07, 2008

Use Mylyn and you will be happy in two months

I must say that I really like Mylyn. Besides all the issue tracker integration, the task context features are great. Today I got a "ahh, this is to good to be true" moment.

I was working on my clear case plugin for Hudson, and was going to fix a feature request I entered two months ago. So I activated the task, and suddenly two files was opened in the editor. The caret was moved to the method that was going to be involved in fixing the feature. Apparently Eclipse has improved recently and it knew how to fix the feature before I knew.

Then it dawned on me that I had started looking into fixing the feature two months ago, and thats why the task context already contained the two files. I just picked up where I left two months ago, and could continue working on the feature request within minutes. That is great functionality that doesn't intrude on the user, it just works!

So if you are using Eclipse and haven't tested mylyn, start using it today and you will be happy in two months! (and the time in between!)

Saturday, November 24, 2007

RFC: A mock too far?

I love using mocks as it makes it possible to write unit tests for small parts of a bigger system without depending on it. Using mocks is very simple, just create a mock of an interface (or class, schhhh) , set up the expectations on it, and then execute the test. When using mocks it is easy to get 100% coverage without relying on others. But I have come to the conclusion that this can be taken too far, way too far.

I have tests that do more setting up the mock expectations than actually testing the code. This makes the tests much harder to read, and I'm having problems going back to 6 months old code and understand what a test actually tests. And in my eyes this is a big problem because unit test code should be as simple as possible.

So what I'm interested in is how should I do mock testing, without drowning in mocking expectations. Does anyone have any ideas on how to do it? Have I gone a mock too far?

As a simple example I will show my unit tests of my Clear case implementation for the Hudson CI server. (But my production code looks very similar unfortunately).

I've selected to mock out the clear tool command execution in the test, ie I dont want to issue real commands using the clear case command line tool (and I don't have a Clear case server or client at home). In the below example I want to verify that when the plugin polls the CC server for changes, then it should issue a "lshistory" method call. But to get it to the point where I can run the tests I have to mock out the Hudson dependencies, ie get the latest build, check the time stamp of it, mock a list of changes that the "lshistory" should return.


@Test
public void testPollChanges() throws Exception {
final ArrayList list = new ArrayList();
list.add(new String[] { "A" });
final Calendar mockedCalendar = Calendar.getInstance();
mockedCalendar.setTimeInMillis(400000);

context.checking(new Expectations() {
{
one(clearTool).lshistory(with(any(ClearToolLauncher.class)),
with(equal(mockedCalendar.getTime())),
with(equal("viewname")), with(equal("branch")));
will(returnValue(list));
one(clearTool).setVobPaths(with(equal("vob")));
}
});
classContext.checking(new Expectations() {
{
one(build).getTimestamp();
will(returnValue(mockedCalendar));
one(project).getLastBuild();
will(returnValue(build));
}
});

ClearCaseSCM scm = new ClearCaseSCM(clearTool, "branch",
"configspec", "viewname", true, "vob", false, "");
boolean hasChanges = scm.pollChanges(project, launcher,
workspace, taskListener);
assertTrue("The first time should always return true", hasChanges);

classContext.assertIsSatisfied();
context.assertIsSatisfied();
}
As you can see the mock expectations take up at least two thirds of the test. Of course I can refactor the tests by adding helper methods that will set up the expections, but many times the expectations are similar but not equal.

Tuesday, November 20, 2007

Hudson embraces Python

A few months ago I started using Hudson for my XBMC TV.com scripts that are written in Python. The Hudson continuous integration server will retrieve the latest sources from subversion, package the sources into a zip file, run a few unit tests, analyze the source using pylint and then display the outcome in a easy navigated web-ui. You can see the result at http://hudson.ramfelt.se where the latest build is always accessible.

Python unit tests
Hudson supports JUnit report files, but unfortunately the py-unit framework does not support outputting the unit test results to an XML file. But thanks to
Sebastian Rittau, there is a unit test runner that will write the result into an XML file that can be parsed as a JUnit file. Using the xmlrunner.py when running my tests I can produce XML files that can be read by Hudson. So now for every commit or forced build the tests are executed and shown in a nice graph.


The python code looks like this:
suite = unittest.TestSuite([
unittest.TestLoader().loadTestsFromTestCase(ShowTestCase),
unittest.TestLoader().loadTestsFromTestCase(VideoTestCase),
])
if __name__ == '__main__':
runner = xmlrunner.XmlTestRunner(sys.stdout)
runner.run(suite)


In Hudson you must enable JUnit report files by checking the
"Publish JUnit test result report" and enter the path to the XML reports.


Python code analysis
Hudson supports the common Java analyzers such as PMD, FindBugs, CPD, checkstyle, etc. It didn't have any support for pylint, but thanks to a great plugin it was very easy to write a parser for pylint reports. Using this plugin, Hudson can now analyze my python files and show a nice trend graph on how many issues there are and for long. It will also produce a report for each file with code snippets to show where the issue is.



Ant target to create the pylint file (important that the pylint output is parseable)
<target name="report-pylint" depends="report-prepare">
<exec dir="${src.python}" executable="${pylint.binary}" output="${report.pylint}">
<env key="PYTHONPATH" path="${build.bin}:${build.bin}/lib/"/>
<arg line="-f parseable -i y TVcom.py tvguicontroller.py tvweb.py tv.py settingsmanager.py --output-format=parseable --ignore-comments=y --min-similarity-lines=4 --disable-msg=R0903 --disable-msg=C0301"/>
</exec>
</target>


Configuring the Violation plugin in Hudson looks like this:



Verification tests
I've also set up Hudson to run the verification tests when ever a build has been completed for the main XBMC TV Script job. This verification job will crawl through the www.tv.com web using the crawling sources to verify that there is no crashes because www.tv.com have changed the html format. This job takes a long time, up too 3-5 hours, and the result will be displayed in a nice trend graph as other unit tests. At the same time I can continue develop the next version and even build a new version while Hudson is running the verification job.


I must say that Hudson is a great CI tool, which works with Java, Python and C#. My favorite languages.

Friday, July 20, 2007

Continuous integration made easy

Yesterday I found a great continuous integration server. Its called Hudson and is written in Java and can do loads of stuff with no complex setup. Right out of the box it supports Ant, Maven, Cvs, and Subversion. In 10 minutes I was up and running periodical builds of my XBMC python scripts from my Trac/Subversion site.

At my previous job at large american hand held manufacturer, they had a really nice build system that was integrated with sharepoint. With it, they could schedule builds through a web page on their separate products. I was pretty amazed by it and it seemed so complex. But now I have a tool that can do the same thing for free.

Hudson has some nice features:
  • Builds trends - How often does the build break? Does the build time increase for every build?
  • Periodical builds Or when someone commits
  • Test trends - Is the number of failed test increasing or decreasing over time? Does the test cover more and more code? (Clover plugin)
  • Emails when a build fails - An email can be sent out when someone checks in code that breaks. Apparently it can even email those responsible for breaking the build (that I havent tested yet)
  • Multiple jobs that can be shared one or several machines.
  • Shell access, you can run any batch file or shell script from the builds; so it is very easy to integrate into your current build situation
  • Plugins - To integrate with Trac and other bug reports; Jabber and IRC support, etc.
So far I have used it for a Java, a Python and a .NET project; and all that just in one day!

Take a test drive of it (check out the webstart) and you will be pleasantry surprised.

Friday, January 19, 2007

Continued inconsistencies in .NET

Everyone complains that Java has their inconsistencies and then points in .NET direction and says that it is so much greater, and less inconsistencies. Somehow I can understand that java has a few of those as it has evolved since the middle of the 90's to what we have today. But I can not understand how .NET can have those as it has only evolved in the last few years.

But today, I found one inconsistency that I thought was very strange. This is a very minor inconsistency, but as the two events has been developed at the same time it makes it much worse. These two events must been under development at the same time and it has probably been developed by the same team or perhaps the same people (imaging the horror).

On the Form class there are two events, to notify listeners that a Form/Window has received focus/lost focus. There are two events which can be subscribed upon:

Form.Activated
Form.Deactivate

Notice the difference, one is past tense and the other one isn't. C'mon these two events must have been developed at the same time, but somehow they screwed up anyhow. The more I look at the Windows.Forms API, the lesser I think of it. There are so many bad decisions in it, so many rushed things. But of course it is only a small API on top of the windows API, and they can only do so much with it.

Strange, that Sun managed to a dynamic, layout managed GUI like Swing with the same APIs. It makes you think on who hired the right guys....

Thursday, December 21, 2006

I need a better "Go to definition" in VS2005 (similar to Eclipse)

I wish MS could implement a little smarter/better "Go to definition" feature. Today it almost works as it should. The "Go to definition" feature is used to go to the row where something is defined (a method, a variable, etc). Which is very handy if you are maintaining a project without any code documentation at all. But unfortunately the function will be confused if there are two methods that are named the same, but have different arguments. (It is called method overloading) Visual Studio 2005 is an "ok" IDE, but it is no way near Eclipse.

With VS2005, it will instead of moving the cursor to the method, it will move focus to a "Find symbol results" view where it displays those methods that have the same name. VS2005 could very easily look into the code and find out the type of method arguments and move focus to the method I wanted to see. But apparently it can not distinguish between an int and an ArrayList.

Try the below code in Eclipse and VS2005, and try to go the correct method that is used in "anotherMethod". (In Eclipse use "Open declaration"). Eclipse will move you directly to the correct method (method(int,ArrayList)), while VS2005 will just show a simple search result.
public void method(int i, int j)
{
}

public void method(int i, ArrayList list)
{
}

public void otherMethod()
{
int i = 2;
int j = 2;
method(i, j);
}

public void anotherMethod()
{
int i = 2;
ArrayList list = new ArrayList();
method(i, list);
}
To me it feels like Eclipse is developed by developers for developers. VS2005 is developed by someone for developers. If they had used the IDE on a daily basis they would understand that the current "Go to definition" is not properly implemented. They should be able to do a better implementation than this semi solution.
Another good example of that VS2005 is not developed by developers, is the lack of unit testing understanding in VS2005,
which I already blogged about.

OO Parenting by MS

I really love object orientation (OO), because it is so easy to build software using it; and it is so easy to totally screw up using it. Today I was surprised when I was trying to find out some information about the Select method in System.Windows.Forms.Control. The documentation for the Select method states what the method does and doesn't do, but it also informs what inheriting classes that does not support it. Of course, every parent class should know everything about the inheriting classes; and have documentation on everything

Excerpt from the documentation:
The Windows Forms controls in the following list are not selectable. Controls derived from controls in the list will also not be selectable.
* Label
* Panel
* GroupBox
* PictureBox
* ProgressBar
* Splitter
* LinkLabel (when there is no link present in the control)

C'mon, why put the Select method in the Control class if they know that many inheriting classes will not implement it at all. This solution/idea reeks of bad design! If a Control does not support a certain functionality, then that class should not have a method pretending to support the functionality. But this is not the first time I found a similar problem with the "design" of Windows Forms, so I will stop whining here....

Thursday, November 30, 2006

Frustration grows when unit testing with VS2005

I've always liked unit testing as it makes my job as a software developer much easier. But the unit testing features of Visual Studio 2005 makes me very frustrated and tired of writing unit tests.

There are two big key issues when using unit testing in VS2005.
  • When I have executed a test and it fails; it will show up in a list with a red icon. When I double click on the failing row/test it will show a report stating what went wrong. Tell me something I don't know, and move the focus to the failed assertion.
  • When I have fixed a bug in the project under test, I would like to re-run the test. In the "Test results" window I can choose "Rerun original test". When I click on it, it will re-run the test with the old code; and the test will fail again even if I fixed the bug. What happened, didn't I fix the code??
  • What the h**l is "Assert.Fail failed."?
Visual Studio 2005:


Eclipse:


Issue 1

Since the test report window has already displayed that the test fail, I'm not interested in a report stating that the test failed, I know already that the test failed and (hopefully) the reason for it. What I am interested in is which assertion failed and where it is.

In VS2005 I have to do the following to get to the assertion:
  1. Double click the failure in the "Test results" window.
  2. Find the row number by reading the text in the stack trace section. Add row number to memory.
  3. Open the unit testing code file.
  4. Go to the row found in step 2
  5. Fix the assertion
In Eclipse it is so much easier:
  1. Click on the failure in the "Junit" window.
  2. Double click on the "AssertionFailed" in the "Failure trace"
  3. Fix the assertion
C'mon; 4 steps and many user interactions involving remembering trivial values to show the failed assertion. It is really frustrating to do it whenever something fails. If something is frustrating and takes time, the developer will stop doing it; thus stop unit testing the software. There is no context menu item to go to the failed assertion, only to go to the begining of the test method. With test cases that can be long, it is not so easy to find the failed assertion. Below is the test report that is shown when the user double clicks on the failure.


Issue 2
I have one project that contains the production code, and one test project next to it as I don't want to mix production code with test code. I've created a test project, added a reference to the production project, and verified that the test project depended on the main project. The test project can access the production classes, so far everything is fine.

But the problem comes when one of the tests fails because of a bug in a production class. When I update the code in the production project, and want to debug the last failed test I click on the "Debug original test". Sure the debugger starts, but the problem is that VS2005 forgot to build the whole solution including the production project. Instead of rebuilding the production project it will only rerun the test. The test will of course fail again, and I will be sitting there wondering if my fix didn't do anything. This has happen to many times, and I've wasted numerous minutes before realising that I must manually build the solution.

Perhaps I'm not using the features correctly, and MS has another view on old test results. Maybe test results should be saved every time a test is run. But for me test results has a very limited lifetime, as soon as I've fixed an error; I don't care about the results prior to the fix.


This does not happen in Eclipse, the minute that I've updated the code I can re-run the test by clicking on "Re-run Last Test - Failures first". No rebuild needed, no time spent wondering why a fix doesn't work.

Issue 3 (Minor)
I just saw this when writing this blog. How can an Assert.Fail() fail? The failure text states that the Assert.Fail() itself failed, to me that is not correct. The test failed itself, and should perhaps say "Failed due to an Assert.Fail() call". Unfortunately Eclipse is not much better as it states "AssertionFailedError" for a fail() call, but still that is better than VS2005.

Opinion
The VS2005 unit testing features are not user friendly, they don't help the user as good as they could. Sometimes a tool with a bad feature implementation is worse than a tool without the feature. Perhaps MS can improve the usability in VS2005, and make it easier for us developer that wants to utilise unit testing. It seems that the above design misstakes must be developed by people who doesn't practice unit testing.

Thursday, November 23, 2006

Why no Equals() and GetHashCode() in System.Collection?

Today I had another brain freeze when I was trying to understand why two array lists would generate two different hash codes even if they contained the same data. But when I started my investigation in MSDN, I see that the ArrayList does not override the GetHashCode() nor the Equals() method. Ehhhhh?

So my question is how can I check if two lists are equal? NO, I don't want to go through all items. This should be handled by the framework classes and I don't want to do any unnecessary implementation.

If I look in Java, the ArrayList implements equals(), hashCode() as all good objects should. They have also a good explanation on how it is done here.

If I look through the other classes in System.Collection I see that no implements GetHashCode() or Equals(). If none of them do, then it must be a design choice. But what design choice would that be? If anyone have any explanation, please make a comment to this blog. I really want to know.

There is an interface in System.Collections.Generic that is named IEqualityComparer, which has two methods, Equals() and GetHashCode(). Why make an interface when every class implements those methods? And why doesn't the default list/collection classes implement this interface?

I did a little test application to test this out, because I can not believe it. Full listing here.
Pseudo code:

string a = "A";
string b = "B";
ArrayList list1 = new ArrayList();
list1.Add(a);
list1.Add(b);
ArrayList list2 = new ArrayList();
list2.Add(a);
list2.Add(b);

Console.WriteLine("list1.equals(list2) ? " + (list1.Equals(list2)));
Console.WriteLine("list1.equals(list1.clone) ? " + (list1.Equals(list1.Clone())));
Console.WriteLine("list1.hash == list2.hash ? " + (list1.GetHashCode() == list2.GetHashCode()));

This program would show:
list1.Equals(list2) ? False
list1.Equals(list1.Clone()) ? False
list1.hash == list2.hash ? False


If I create two array lists that contains the same items, the Equals() method will return FALSE. If I clone an array list and checks if they are equal the Equals() method returns FALSE. How can a CLONE not be an exact copy of the object, or how can two exact copies not be equal to each other?

The best part is that Hashtable doesn't implement GetHashCode() either. And that class require all other objects to implement that method in order to be used, but they refuse to do it themselves. "Do what I tell you, not what I do."

Is it because they know people will not implement those methods since developers are lazy? But why have they put them into the Object class if they can't be trusted? Or was it a copy-paste mistake from Java?
To me this is so wrong.

Monday, November 20, 2006

Localisation with VS2005 will slow you down

In my previous blog about a localisation that went sour, I mentioned that the time for building a localised application takes longer and longer for every language that is added. I have now quantified my feeling and found out that adding a language adds 15-20 seconds for each language. Now that doesn't sound that bad right? Wrong, If you develop an application that takes one minute to build and adding languages almost triples that time, then it becomes tedious very quickly.

This is what I found out (table and graph):

  • Default language took 69 seconds to build
  • With two languages it took 85 seconds to build (16 extra seconds)
  • With four languages it took 118 seconds to build (49 extra seconds)
  • With six languages it took 144 seconds to build (75 extra seconds)
If a normal developer compiles 10 times an hour to test something, he/she will waste 12 minutes, just sitting to wait for VS2005 to build. I meanthat is an outrageous extra time, and I wonder if we can send a invoice to Microsoft for those hours that we just wait for the build complete? And I guess we have to make the work day longer as we get much less done.

For this project, the solution was to remove all language resource files from the project file. This means that the only language that is supported in mid-development is "default" and nothing else. So fixing those too narrow labels for localised texts has to wait for another day. The tool do add/remove all those languages to/from the project file is developed in house and can not be shared unfortunately. The tool is very simple to create, but in my view unnecessary.

Here we have a grave problem with the localisation in Visual Studio 2005. If it is done as MS wants, the build time to a project can (and probably will) go up for every language added. What is the outcome of that? Either the developer will stop adding localisations, constrain the development by only showing the default or sit and do nothing while the project builds. This is not a good solution. I would rather have a one-file seperate from the GUI, which reads on the fly when the application is started. That way the language files does not affect the build at all, and it will be a minor load time added for the user which probably will not be noticed.

Measurement notes:
  • This is an observation of an application that has been under development for 3-4 years.
  • They have tried to follow MS design guidelines.
  • Clear case is used with dynamic views, which could have an impact on the result as it needs to access 200 new files for every added language.
  • The application is not divided up into more than 2 GUI projects. Perhaps adding more sub projects could make the build quicker?
  • I used a C# application to measure the time it took to execute a bat file containing "devenv app.sln /build debug"
  • I measured each language addition at least 4 times

Monday, November 13, 2006

Localisation gone bad in C#

I'm doing maintenance on a huge C# application that was developed for a swedish customer. A while ago it was decided that the application should be sold outside Sweden, and therefore it had to be localised in english, romanian, chinese, etc. The application consists of roughly 200 controls/panels and forms. It was a huge task to translate everything, and from what I now can see MS Visual Studio 2005 did not help very much (as I'm maintaining it right now).

Apparently one new thing in VS, is that you can localise each and every control/form in the designer. That is nice when you have a few forms and controls that do not use the same words all the time. The developer creates a form, changes the language property and inserts all the translated texts. It is very easy to change a word in swedish to english, and it is all GUI based. But what happens if you have 200 controls/forms that share many texts? I have not figured out how to do that in VS2005 and GUI elements.

Developers are lazy (and they should be), so they will use the easiest way out. In this case it meant that nobody cared that the same words were used in many forms. Sometimes, people missed a label here and there. And for me maintaining it, it isn't nice.

I demand these things out of a localisation framework
  • One file for each language. - VS2005 brings you one file for each language and GUI control. In the project it means 1,000 new XML files to handle. That is not good.
  • One method call to get the texts for a language. - Yes, .NET helps partly with this (I will blog another rant about this later)
  • Ability to change locale during runtime. - Yes, it is possible in .NET.
I need the following tools:
  • Tool to find duplicates so they can be erased, and defined in one place. (Think OO but with languages) - VS2005 does not help you at all.
  • Tool to spell check localisation files. Apparently there is no such tool out there. - I have not seen anything in VS2005.
  • Tool to show missing translations for a language. - Nope, the company had to build their own software to extract missing translations and merging.
So what I got was to "translate" around 200 "missing" translation in an XML file, out of them there were 50 "OK", 5 "Cancel", 10 "Index", 15 "Close", etc. I can sure tell you that it could have been very tedious, but I built a very simple tool that would go through the file, so I didn't have to bother with copying/pasting. But once again, I have to develop tools to do stuff that the IDE should have helped me with.

Side note:
They discovered a side effect of adding new languages to the project files, for every new language you had to add 200 files, this made the project bigger and bigger. Now it takes eons to compile, and one of the core developers came up with the idea to remove all localisation files from the project files. When that was done, the time to compile was drastically cut which was good. Unfortunately we we're in integration testing and could not test any of the localisation bug fixes (D'oh).

So what did they end up with when using Visual Studio and .NET?
  • Duplicated texts all over the resource files.
  • 200 new files for each language
  • Compilation time sky rocketed (I will bring stats for this later this week)
  • Developed their own tools to handle the resource files (RESX) which require maintenance, etc.
  • Forms that were not properly translated, which wasn't found out until the system test phase (or even later).
  • And lets not forget the need to update the size of every button/label to cater for romanian texts. That is also tedious and really unnecessary work.
What is the proper way to do localisation in .NET and Visual Studio? What did they do wrong? What is the easier way out?