Tuesday, November 30, 2010

I want Layar on my WP7

Just browsed back a bit and found this post from when I had just gotten my Samsung Omnia Qwerty phone. I guess as soon as the camera access API - that LG is already using in their Look n Type and ScanSearch WP7 apps - gets official for general public use, there is no reason for Layar to not bring out a port of their client for Windows Phone 7. I'll be waiting...

Quick update after MWC: like I wrote in Barcelona, I expect this to be unveiled at MIX in Las Vegas, april 12-14. So it can't be long now.

Some handy extension methods for argument checking

After a quick Twitter interaction with Marc Jacobi I thought I'd post a small set of extension methods I like to use for argument checking:
using System;
using System.Collections.Generic;
using System.Text;

namespace peSHIr.Utilities
{
    public static class Guards
    {
        public static void GuardNull
            (this object argument, string argumentName)
        {
            if (argument == null)
            {
                throw new ArgumentNullException(
                          argumentName,
                          "No object supplied");
            }
        }

        public static void GuardNull
            (this string argument, string argumentName)
        {
            if (String.IsNullOrEmpty(argument))
            {
                throw new ArgumentNullException(
                          argumentName,
                          "No text supplied (or text is empty)");
            }
        }

        public static void GuardZero
            (this int argument, string argumentName)
        {
            if (argument == 0)
            {
                throw new ArgumentNullException(
                          argumentName,
                          "The number zero is not allowed here");
            }
        }

        public static void GuardNull<T>
            (this Nullable<T> argument, string argumentName)
            where T:struct
        {
            if (argument.HasValue == false)
            {
                throw new ArgumentNullException(
                          argumentName,
                          "Empty nullable type not allowed here");
            }
        }

        public static void GuardMinimum<T>
            (this T argument, T lower, string argumentName)
            where T : IComparable<T>
        {
            if (argument.CompareTo(lower) < 0)
            {
                throw new ArgumentOutOfRangeException(
                          argumentName, argument,
                          string.Format("Minimum allowed: {0}", lower));
            }
        }

        public static void GuardMaximum<T>
            (this T argument, T upper, string argumentName)
            where T : IComparable<T>
        {
            if (argument.CompareTo(upper) > 0)
            {
                throw new ArgumentOutOfRangeException(
                          argumentName, argument,
                          string.Format("Maximum allowed: {0}", upper));
            }
        }

        public static void GuardRange<T>
            (this T argument, T lower, T upper, string argumentName)
            where T : IComparable<T>
        {
            if (argument.CompareTo(lower) < 0 || argument.CompareTo(upper) > 0)
            {
                throw new ArgumentOutOfRangeException(
                          argumentName, argument,
                          string.Format("Allowed: [{0},{1}]", lower, upper));
            }
        }
    }
}
When you can use code contracts this is probably preferable. Otherwise, these little extension methods can come in really handy for some general cases.

Saturday, November 6, 2010

First WP7 app should be published!

This morning I found out that my first Windows Phone 7 application had passed testing. It's status is now "Published to Marketplace", but I have not been able to see it appear on my phone yet. Hope it does so soon.

In the meantime, here are a couple of screenshots of the application in English; it supports English, German, Spanish and, even though not supported yet, Dutch. All the content that is shown (RSS feed items from my companies website and its tweets) is in Dutch only, however.

Wednesday, November 3, 2010

Is WP7 getting another theme in its next version?

When playing with the example code solution of the November 2010 version of the Silverlight for Windows Phone Toolkit, I noticed the following:

Since this screen seems to do its best to mimick the Theme page from WP7 phone settings to show off one of the places where WP7 itself uses the ListPicker control (with appointment status being another one), I would not be surprised if we would see a new "dazzle" theme in a next version of the Windows Phone OS.

This piece of example code could mean nothing of course, but I'm still curious what a "dazzle" theme might look like...

Annoyed by swamped App Hub

Yes, I really am.

I admit that a launch of the magnitude of Windows Phone 7 is no easy thing. And that I didn't really get active in WP7 application writing until the LG developer prototype device from Microsoft arrived two weeks ago. But still.

I have been wanting to publish at least one WP7 app to the marketplace for almost those two weeks now. Thanks to Microsoft NL (way to go, Matthijs!) I should have been white-listed for WP7 app publishing already, but so far this has not materialized. The App Hub forum seems awash with developers in a similar predicament. Without a real solution in sight.

The relevant forum threads all started mentioning the magical date of november the 3rd as a solution: by then everyone registered as a marketplace developer (no matter the platform) would be able to publish WP7 apps. Too bad no time (and timezone) was mentioned for this...

Because right now here in the Netherlands 10am on november the 3rd has come and gone, but I still cannot publish. Combining the 'timezone' and the 'no specific time mentioned' issues I'm waiting for tomorrow morning, roughly assuming after 11pm on the 3rd on LA time. However, I do not assume publishing will have commenced normally (=in force) by then...

I would definately not want to be on the WP7 App Hub team right now. Good luck the coming weeks, guys!

Wednesday, October 20, 2010

A small tip to .NET bloggers...

I have a small tip for .NET bloggers out there:

Will you please include full namespaces in your example code?

For people not yet well versed in the .NET API that you describe or use in your code, nothing is more frustrating than copying a couple of lines of code from a blog and then finding out that it doesn't compile because they have not referenced the right assembly and/or included the needed using statement for the namespace.

What would you prefer to find as an example in a post that describes how you can let Windows open a website in the default browser by simply starting a new process with the URL as the commandline?

  1. System.Diagnostics.Process.Start("http://blog.peshir.nl/");
  2. using System.Diagnostics
    ...
    Process.Start("http://blog.peshir.nl/");
  3. Process.Start("http://blog.peshir.nl/");
    You find the Process class in the System.Diagnostics namespace.
  4. Process.Start("http://blog.peshir.nl/");

To me any option is fine, except the last one.

Google Maps should (no: must) come to WP7

With my personal interest in maps and mapping I read the blog post about Google Maps on WP7 (using the Bing Maps Silverlight control) by LocalJoost with great interest.

He mentioned a lot of pageviews to this post shortly after posting it, and I just saw him tweet about his post being picked up on by wpcentral.com.

I think it's great that wpcentral.com did pick up on this. However, I do not agree at all with the first part of the possibly meant to be funny footnote by Daniel Rubino:

Yeah, I know. Who would want to use Google Maps when Bing kicks so much butt? [...]

I suspect that Daniel is both Microsoft biased (not really a problem for me) and not based in the Netherlands, because even though I hear a lot of positive things about Bing Search and Bing Maps, I keep comparing it to Google Search and Google Maps and have not switched yet.

To be frank and rather blunt about it: Bing can't stand in the shadow of Google. Or at least it cannot in the Netherlands, which happens to be where I live and use these services almost exclusively.

Before anyone starts comparing actual mobile client features I want to point out that this is mainly related to (probably) legal and data issues and not to the technology. I just have the feeling Google in general "finds more" for me, gives me more useful results. Also, I like the visual style of Google Maps more than that of Bing Maps at the moment, but that could just take some getting used too.

So for now I'll take Google over Bing any way I can get it. And that includes a Google Maps client for WP7, preferably written by Google itself and including all the official Google Maps features.

Google, are you listening...?

Friday, June 11, 2010

Some RC helicopter flight simulator resources

If you follow me on Twitter you probably know that I am in the process of learning how to fly RC helicopters.

I have done quite a lot of hours in a simulator already and own a coaxial chopper I use for indoor hover training, which you can see here as it was before the flimsy bodywork got slightly damaged (and here after a second recent crash)...

At the time of writing this I was thinking about getting myself a Nano Arrow, as it is smaller/lighter (=less easily damaged), has a "normal" configuration with single rotor blades and a powered tail rotor and is cute as hell. I have now bought one of these and use it for training. ;-)

Simulator resources

Recently I got a question about simulators, specifically if there were any open source/free ones around.

As I really didn't know (only having used RealFlight 4.5 myself), I did a quick Google. This is what I found:

If you know of anything that should be in this list that I missed (didn't put that much time into compiling it), please let me know in the comments.

Get the right controller

One last comment: if you are (or become) serious about flying RC helicopters, I think it will be imperative to have simulator software that has a physical USB transmitter available or at least the means to attach and use one.

What you have in your hands while simulator flying should really be as close as you can get to what you will be flying your actually helicopter with. This helps to train muscle memory and make you a pilot instead of "just" a gamer trying to fly an actual helicopter model.

Small update

If you want to know more about my helicopter adventure, please check out my personal blog (which is in Dutch).

Wednesday, March 17, 2010

Is Microsoft insane?

You're probably guessing this blog post has something to do with Windows Phone 7 Series (or WP7). Also, many of you will agree the answer to the above question must still be "no", especially given the qualities of the iphone and the numbers this device sells. However, unless the locked down nature of WP7 changes Microsoft clearly does not want me as a WP7 customer. Their loss. ;-)

Thursday, February 11, 2010

Cultural barbarism in .NET

If you follow me on Twitter, you will have seen me rant about an alpha version of some piece of software on my phone. While I will not be naming it here, because that is just not the point, it is clearly the reason for this blog post.

The application - lets call it FizzBuzz just to have a generic name - looks good, and seems to work okay (great, if you consider that it's an alpha version) except for one thing that for me made it totally useless. FizzBuzz contacts an internet service through (I think) a REST API. And at least one of the parameters involved is a decimal number. When I used the version of the FizzBuzz application that sparked this post, all I got was a fatal exception message box after which the applications was killed, which in itself was fine.

So some application crashed. What gives?

What's not fine however is the fact that the problem that caused the crash was a FizzBuzzException with a message a bit like "Invalid attribute 52,0987654321". The original FizzBuzz API no doubt accepts its decimal values with a dot. I live in the Netherlands however, so my phone is set to the (for me) correct local settings, which include a decimal comma. So, what went wrong?

Simple: the creator of the FizzBuzz phone application seems to have been working from a faulty assumption: in the .NET framework decimal.ToString() always creates its results "the same way I'm used to getting them". And that is plainly wrong. The whole question of globalization is just completely ignored then!

Globalization? Oh no, not that!

Don't get me wrong here. Globalization is a royal pain in the ass. So, I'm not saying that, just because the current .NET framework seems to be able cope just fine with globalization in almost every way, each and every application written using it should pass the complete Turkey test. Which by the way is in no particular way meant to be negative about Turkey in particular. ;-)

Also, this post is not about the FizzBuzz phone application showing times in 12-hour time (without AM/PM indication even) and dates in M/DD numerical format. I sure would like it very much if it would show this to me in 24-hour time and D-M format (either by making use of the current Culture settings, or by letting the user choose among a number of options in its Settings), but that is again not my point here.

What are you saying, then?

I just think there are minimum levels of "cultural awareness" for each and every .NET programmer. And knowing that ToString() (and anything directly or indirectly using it) is dependent on the current culture is part of that. Not just getting an "aha" feeling when someone (like me) tells you about this, but using this in your daily work every day.

What really helps with this is static code analysis: if you turn on rules CA1304 and CA1305 it almost becomes impossible to forget about these things. Especially if you turn on the Treat warnings as errors option, which might be a bit much for most.

Another basic that every .NET developer should be aware of is the invariant culture and when to use it.

Every time you are converting a value to a string for the purpose of showing it to the human user of your application, the assumption above is usually fine. Normally the .NET Framework will silently use the current culture which will be related to the local settings made on the device and everything should be peachy.

However, when you are creating a string for the specific use in an API to other software - like in the situation the FizzBuzz application was converting decimal values to strings - you normally need a specific format. Or to be correct: the API you use expects a specific format. And since most software development has historically been English based, you'd better use dots in your text-formatted decimal numbers, unless specified otherwise. For this, the invariant culture is perfect.

For some small bits of code then. When dealing with API use (not GUI to human user use) I often put the following in string related classes:

using System.Globalization;

// ...

class SomeApiStringHandling {

   private static CultureInfo invariant = CultureInfo.InvariantCulture; 

   // ...

   void SomeMethodUsingStringFormat() {
      string.Format(invariant, "Format", data);
      // instead of the usual
      string.Format("Format", data);
   }   

   // ...
}

Also, don't forget about string.ToLowerInvariant() as opposed to the much more well known string.ToLower() (and the same for the variants for upper case) in situations where use of the invariant culture matters.

Conclusion

  • Please adjust your basic assumptions (if you haven't already): assume the current culture comes into play when converting to/from strings at all times.
  • When working with strings in relation to software based protocols and your "old assumptions" should hold, simply explicitly specify the use of the invariant culture.
  • Only if you have a compelling need to (or when it interests you) should you actually read up further on the whole globalization situation, including the Turkey test, date/time/currency formats, multiple resource files for different cultures, etc.

Oh, and if any one of you still thinks that one char equals one byte, let me know. Perhaps I can then start talking about Unicode and other character encodings a bit, alright? Whole different can of worms entirely... ;-)

P.S. To be fair, by the time this blog post is actually published, the FizzBuzz application that was a reason for me to write this post corrected the problem and is now working fine. Just wanted to have this mentioned explicitly.

Wednesday, February 3, 2010

My old (make that ancient) website is going down...

If you read this blog and generally follow me online or have been doing some time ago, chances are http://www.jarno.demon.nl/ has come up on your screen at some time.

This is the website I started working on when I was at university. This was somewhere in 1996 I think, judging from the copyright message. I wrote an MS-DOS console application myself in some compilable BASIC dialect to create and maintain the site. This application, called JHS2HTML, would take *.jhs files and some general header/footer type information and create a an HTML file for each, in essence giving me the website to then go FTP somewhere. The tool had dynamic placemarkers for things like the current date or year, easy linking to other *.jhs files (creating mouseover links) and macros for things like the UPDATED images that were all in fashion at the time. Oh yes, this 'sophisticated CMS' included style sheets and master pages and all that. Sort of. <grin>

Let's face it, this website is old, outdated and frankly a bit (lot?) embarrassing even. But still, I never took it down or moved it and I'm still paying the ISP I had the time just so it remains. That, and because I'm a lazy administrator, and never actually canceled. This is now going to change.

I think I keep getting some job offer calls from the CV on the site. And there are also still things on there that are difficult or impossible to find elsewhere on the web, like: the ghost website of RUN Flagazine, information on the HP82240B printer (although I think this is also mirrored in the HP48 FAQ) and my masters thesis.

So, after reading about HTTrack on POKE 53280,0 I am now dragging all the content down so I can stored it in my Jungledisk account somewhere so it isn't lost completely. And afterwards I will be taking my Demon account down. So expect my ancient website to soon vanish, at least from the current URL...