Development

This category is for all things relating to scripting or programming languages, as well as software construction, design and development.

String Hashing in F#

I recently wrote a small program to convert some strings into a ‘unique enough‘ hash which could be used as a short reference.

Whenever I’m trying to come up with an idea of how to handle these kinds of functions, I tend to turn to my favourite language, F#. This allows me to do rapid prototyping in a very functional way.

Below is the prototype version of this hashing program:

open System
open System.Text
open System.Security.Cryptography

let encode (alpha:string, number:int) =

    let b = alpha.Length

    let rec enc (s:string, n:int) =
        match n with
        | x when x <= 0 -> s
        | _ -> enc (s + alpha.[n % b].ToString(), n / b)

    match number with
    | 0 -> alpha.[0].ToString()
    | _ -> enc ("", number)

let md5Int (input:string) =

    let clean (str:string) =
        str.ToLowerInvariant()
           .Trim()

    let computeHash (str:string) =
        let bytes = Encoding.Unicode.GetBytes(str)
        use crypto = new MD5CryptoServiceProvider()
        crypto.ComputeHash(bytes)

    let convert (bytes:byte[]) =
        let i = BitConverter.ToInt32(bytes, 0)
        Math.Abs(i)

    convert (computeHash (clean input))

let hash (input:string) =

    let a = "ABCDFGHJKLMNPQRSTVWXYZ0123456789"
    let i = md5Int input

    encode(a, i)

Once I have this program created, it’s very easy to use in F# Interactive like so:

> hash "Here is a test string!";;
val it : string = "1W2ALLB"
> hash "The hash is much smaller, which is great.";;
val it : string = "5DAF5T"
>

Running JAR applications on Windows without installing the Java Virtual Machine

As part of my Open University course, I’m required to use a piece of open source software called Aladin Sky Atlas. This is maintained by Centre de données astronomiques de Strasbourg.

The program itself is actually pretty cool – it’s an interactive sky atlas, which allows you to view astronomical images along with information from the SIMBAD database and other sources.

The only problem with this program is that it uses Java, something I tend to avoid whenever possible. Installing Java on my Surface Pro 2 would mean I’d have more critical patches to install than I already do, and would open me up to a whole new attack vector. It’s not something I’d want to run on a tablet computer either.

(ノಠ益ಠ)ノ “Eww, Java!”

I originally tried using Hyper-V with a virtual machine running CentOS. This is a nice clean way of having ‘nothing running’ until it’s actually needed, but it’s quite an overhead to run a whole Linux operating system just to host a single app. Especially when battery life is a concern.

When searching around for a solution, I stumbled upon a really cool project that I’d never seen before. The IKVM.NET project includes a number of components for Java & .NET interoperability, but for this task I’m mostly interested in the Java Virtual Machine implementation.

By downloading the Windows binary of IKVM.NET, I’ve been able to run the application on my Windows 8.1 machine without requiring the JVM (or any other software) to be installed at all. This is a pretty fantastic achievement.

First I put the binaries into my apps folder (similar to my Vim setup), then I set up an alias to the executable using PowerShell.

# There's usually much more than this in my profile!
$SCRIPTSPATH  =  "C:\Users\Julian\Scripts"

Set-Alias ikvm   "$SCRIPTSPATH\Apps\ikvm\ikvm.exe"
Set-Alias ikvmc  "$SCRIPTSPATH\Apps\ikvm\ikvmc.exe"

# ikvmc.exe is cool too! have a look

After creating an alias in PowerShell I can just run it whenever I need.

PS> ikvm -jar aladin.jar

Obviously you could always set up a Windows Shortcut that does a similar thing, but that’s boring. Using PowerShell really suites me, as I often run applications this way.

Aladin Sky Atlas running on Windows without Java installed

The software doesn’t exactly look pretty, but these open source projects rarely do. Sometimes it looks like text hasn’t rendered as expected, but overall I’m really impressed.

If you’re looking to run JAR applications on Windows, without the Java Virtual Machine, then have a look at The IKVM.NET – it might work for your apps too.

Will Neovim rock on Windows?

Gvim on Windows 8

I have been using Vim on Windows since I switched to 64-bit and edit.com stopped working. Originally I just used the console version inside of PowerShell or the standard command line. In the last three years I’ve been favouring Gvim as my go-to text editor for smaller scripts and utilities.

I know for a fact I’m not using everything Gvim or Vim has to offer, but I’m quite happy with the way it works. For example, I have line numbers turned off, but I can turn them on very easily using a quick :set nu.

Very powerful, very fast.

There are some things I absolutely hate though. For starters, what’s this horrible border on the inside of the window, and how can I make it disappear without hacking the whole application and recompiling it? This isn’t Windows 95.

Ugly Border

I’ve looked for some time but I haven’t found a solution. But hey, I found out that people can make it look pretty on Ubuntu (handy!)

Enter Neovim

Neovim promises to be a refactoring (and reimagining) of the Vim text editor using more modern techniques. The plan is to have the core Vim functionality moved into a new library, which will allow the interfaces to be separated out in a modular way.

The thing that got me really interested? When they mentioned Windows:

Modern GUIs written in high-level programming languages that integrate better with the operating system. We can have GUIs written using C#/WPF on Windows or Ruby/Cocoa on OS X, for example.

True they’re not saying they will write a GUI using C# & WPF, but someone can. And I like the sound of that. Of course, it’ll be open source – and I’ll be able to edit the XAML to have no borders at all, if I like.

Also, here’s hoping we get better PowerShell integration out of this too.

It could be huge.

So, will Neovim rock on Windows? I sure hope so.

It’s a great time to be a Microsoft-focused software developer

The Build 2014 conference took place in San Francisco last week, where thousands of developers and designers came together to learn all the latest information about what it means to use Microsoft development tools, and build solutions that run on Microsoft platforms.

I have over 137 GB of videos yet to watch, but I can already say that it has been one of the best Microsoft developer conferences to date.

Here are my thoughts so far, with a few links to some of my highlights.

.NET is alive and well – and becoming more open

build-2014-4

There was a general feeling that .NET developers had been left behind in recent years. A strong push to using HTML and JavaScript really got some people worried when Windows 8 was announced – but at Build 2014 the message was loud and clear. The .NET platform is alive and well.

It’s almost as if they asked .NET developers what would make them really happy, and set about doing all those things. For me, personally, I was most excited by the promise of open-sourcing even more of the framework, including the brand-new compiler platform (Roslyn) that has been years in the making.

Initiatives like .NET Native will allow applications built with C# and Visual Basic to get much closer performance to applications created with C++. Starting first with Windows Store apps, these architecture specific binaries will increase performance at runtime without losing the productivity of developing with the architecture-agnostic .NET Framework.

Roslyn and .NET Native are in preview, and won’t be completed until the next version of Visual Studio. But there have also been a wide range of updates to the ASP.NET web platform, MVC, Entity Framework and way more – most of which are either available now with Visual Studio 2013 Update 2, or can be downloaded using packages from NuGet.

You can tell Windows is under new leadership

build-2014-1

Cortana – the new assistant built into Windows Phone 8.1 – was the highlight of the show. There had been rumours of Microsoft’s answer to Siri and Google Now for quite some time, so a lot of the information had already come out. But still, it was great to see Joe Belfiore talking to her publicly for the first time, confirming what Halo fans were waiting for: yes she is called Cortana, and yes, she sounds like Cortana.

As Cortana is such a huge step for Microsoft, I’ll be going in depth on what I think over the next few weeks.

Cortana wasn’t the only addition to Windows Phone 8.1, there were hundreds of new features and tweaks to the UI that will take weeks to be documented – the new calendar is just one of these. I’ve tried it in the emulator and it’s really great. The developer preview is due this month.

As a developer, the news of Universal Apps was very welcome. This allows high amounts of code sharing between applications designed for both Windows and Windows Phone. I can’t wait to try this stuff out, especially with the new JavaScript support.

Windows 8.1 has some new features too. The much-leaked Windows 8.1 Update includes changes to how the operating system behaves with a keyboard and mouse – though these changes are only the start of the improvements that are coming.

Azure is the future, and already here

build-2014-3

Microsoft’s cloud platform has improved tremendously over the last few years and this year was no exception – in fact, there were so many new features I can’t even begin to go through them all. Some I probably won’t even use (Java? No thanks.) but I know the option is there, which will inform my decisions for cloud hosting in the future.

Scott Guthrie and his team talked at great length about new features that will improve productivity for ‘DevOps’ tasks significantly. For example, the new Azure Portal includes the ability to view statistics, create new infrastructure, build new virtual machines, deploy websites and even do code changes with Git source control – all from one UI.

I already use Azure as part for my personal projects, as well as Visual Studio online as my source code repository. I plan on using it even more in the future – so I’m pleased to see Microsoft lead in this area. And they really are leading.

It doesn’t have to be Windows & .NET

build-2014-2

Times have certainly changed, and PCs that run Windows are no longer the most popular computing devices. As a predominantly Microsoft developer, this makes me wonder about the future. This year’s Build has continued the recent trend of Microsoft supporting other platforms in new ways – plus with partnerships with like likes of Xamarin, I see no reason to even contemplate switching over to Android (the most popular platform) in the foreseeable future.

While I was hoping that there would be the announcement of a Xamarin acquisition, they didn’t disappoint. It was great to see Maguel even joining Anders on stage during the keynote. Both of these guys are very smart, and I look forward to what else the partnership can bring. Being able to develop universal apps that also target iOS and Android is not very far away at all.

Surface Pro 2: Development Workstation

Surface Pro 2

After five years of faithful service, I have finally replaced my old MacBook with a new computer. I got myself the Surface Pro 2 with 256 gigabytes of storage, and 8 gigabytes of memory.

Frankly this small computer is the fastest one I have ever owned, and performs better than my higher spec work laptop. This is especially noticeable when using Visual Studio and other development tools, but it’s also faster doing every day things like Mail and OneNote.

Development Workstation

The purpose of this computer is to be my development workstation, and to run all my x86 applications. Due to the tiny size of the tablet it will probably spend a good deal of its time attached to external devices. A full size monitor, keyboard and mouse combination will allow me to be as productive as possible at home, while still being able to take everything to other locations in even the smallest of bags.

While thicker than my original Surface RT, the Surface Pro 2 shares the same design language, and I find that it looks almost indistinguishable when I’m facing the screen itself. Picking it up it certainly feels thicker, heavier, and warmer. But it’s still a Surface, and feels extremely well made and very sturdy.

So far, I’m very impressed. I’ll be writing up some of my experiences of using the Surface Pro 2 as a development workstation as I spend more time with it.

Surface

So if this device is meant to replace my MacBook, what does it mean for my Surface RT?

Having two 10.6 inch tablets is not ideal, I know. But I’m going to continue to use the Surface RT for things like Skype, Netflix and general carrying around in my backpack until there’s a 7 or 8 inch Windows RT based tablet that catches my eye.

Windows RT devices tend to have much better battery life, and the operating system itself certainly better suited to mobile devices. For example, Connected Standby allows Windows RT to collect email and other notifications over Wi-Fi even when ‘off’. A feature that is sorely missed on Windows 8.1 Pro x64.

I’m also not convinced that the 10.6 inch screen size of the Surface RT is what I want from a Windows RT tablet anyway. The relatively large screen is great for using with the Type Cover and being productive – but I’d rather have something smaller for using mostly with touch.

Windows 8.1 on the 2008 MacBook

Windows 8.1 on 2008 MacBook

For a while now I’ve been wanting to get myself a new PC, but I haven’t found one that really captures my attention. I tried looking at Vizio, Apple and Samsung – but nothing seemed worthy of the investment. Plus I must admit I have been holding out to see if Microsoft brings an Ultrabook to the Surface family.

Most of the time I actually use my Surface RT for doing every day stuff, but there are some things that are much faster using a larger keyboard, a proper track pad and the ability to be used on the lap. I have been using my 2008 MacBook running Windows 7 for these tasks, as well as pretty much all of the development I do for my personal projects.

Last week – when trying to get the MacBook to boot from a VHD file – I managed to mess up the boot configuration, and two of the three operating systems (OSX, Windows 7 and Windows 8.1) didn’t work at all – the only one that worked didn’t really provide me any way to fix the issue.

So for the first time in what seems like forever, I actually burnt a DVD and got a copy of the Windows 8.1 Preview installed fresh on the NTFS partition. This worked much better than the Windows 8 Preview I had previously tried, and I decided to try and get things up and running properly by following a guide (slightly modified to get the new version of Boot Camp) and lots of hacking around.

To my amazement, not only did all the Apple specific drivers (the backlit keyboard, multi-touch track pad etc.) all work for the x64 version of Windows, but the operating system itself felt a lot faster than Windows 7. It also seemed the Apple’s Boot Camp software wasn’t hammering the CPU as much as it used it.

Thanks to some of the changes in Windows 8.1 – like being able to use Snap view on lower resolutions – I’m actually able to complete most of the tasks I wanted a new computer for. Sure there are a few down points:

  • No hypervisor – meaning I can’t run the Windows Phone Emulator.
  • No touch screen – yes I have tried to swipe content on the screen by mistake!
  • Not very speedy – hey it’s a 2008 machine, it’s not going to be fast.
  • Hacky configurationthe third party drivers sometimes feel like they’re held together with luck. And they are.

But these negatives aside, I’m actually able to get most of my development tasks complete on the new operating system, and I’m going to upgrade to the final version of Windows 8.1 when it comes out in the fall. This means I don’t need to buy a new computer right away, and I’m going to try to get at least another year out of this one.

Windows 8.1 on 2008 MacBook

I still hope that Microsoft will enter the Ultrabook market, and if they do I’m sure I’ll be glad that I waited. But for now I’m going to try to continue to use this 2008 MacBook as long as I can.

My hat goes off to Apple – this has definitely been the best machine I have ever owned.

Update

I no longer own this MacBook anymore as I’ve upgraded to a Surface. It’s a little difficult for me to answer further questions around running Windows on it.

Good luck!

Installing Windows RT 8.1 Preview on Surface RT in the UK

Like many Surface RT owners in the UK, I was extremely excited to install the Windows RT 8.1 Preview that was announced today. Unfortunately, the update provided doesn’t seem to support English (UK) as a language option on my Surface RT.

First I attempted to add English (US) and replace my existing language, however that did not work and I still got the error.

So, hacking away like I usually do, I decided to try forcing the installation of KB2849636 from the Command Prompt:

expand -f:* Windows8-RT-KB2849636-arm.msu .
pkgmgr Windows8-RT-KB2849636-arm.xml

After a reboot my tablet sat on ‘Preparing to configure Windows’ for a long time, and after the jump I was able to see the preview from the Windows Store.

Windows RT 8.1 on Surface RT in the UK

Unfortunately I haven’t been able to install it yet, and I’m told to try again later. It seems to sit in this state and doesn’t progress any further…

Please try again later...

Update 1

Still no joy in getting the preview installed, but there are a few other people looking into the problem.

Check this question on the Microsoft Community for more information.

Update 2

It looks more and more like there is an issue around the installation that can only be fixed by installing an English (US) operating system. I have decided to wait and see what happens. I’ve heard that Microsoft will be releasing a fix for this in July.

In my opinion, this has been extremely poorly handled by Microsoft.

Update 3

There is another question on the Microsoft Community which has some replies from the moderators:


Windows RT users

Please do not change your base language just to install the Preview. If you do this and then update to the preview version, you will permanently change your base language on these devices. This happens because we create a new restore image based on your selected 8.1 base language during install.

Also, as we noted on the download page, if you’ve installed a language pack on Windows RT, we ask you not to install Windows RT 8.1 Preview at this time. A fix will be available soon for updating through the store with a language pack installed, so please check back.

Charles [MSFT]

Goodbye, Pokéject

When Windows Phone 7 first came out, I immediately started looking to use the new development tools to create an application. Pokémon Black and White were out around the same time, so I figured creating a Pokédex-like application would be a good idea.

pokeject

Unfortunately, not much over a year later The Pokémon Company International went after a number of the Pokémon apps for iOS, Android and Windows Phone. They asked Apple, Google and Microsoft to remove the offending applications from their respective stores. My app was included*.

Eventually, The Pokémon Company International released their official Pokédex applications for both the Nintendo 3DS and iOS. (at time of writing, there is no official app for Windows.)

pokedex-ios

The Pokédex app for iOS has a different focus from my app, aiming directly at listing out all the information rather than focusing on checking off the list (though you can use it this way using tagging). This is great, as the information contained in the application far outweighs the data I managed to collect for use in Pokéject. Including some rather cool 3D models.

pokedex-3ds

Personally, I believe the 3DS version to be a lot weaker – the user interface is pretty horrible looking, and I found it a lot harder to navigate. The biggest complaint is the lack of ‘multi-tasking’ on the 3DS. I would like to be able to check off my Pokédex as I play my game. This isn’t possible when both are applications on the same machine.

I thought about reviving Pokéject as web application, going as far as porting a large amount of the source code over to ASP.NET – however I recently started using the iOS version – which contains much more data – and decided it would not be worth the time investment.

So this is the end of the Pokéject project. It’s been fun, but the official versions contain way more information, I suggest people use them moving forward.

* A recent check shows that there are still a number of Pokédex apps in the Windows Phone store, though the most popular and best presented ones were removed long ago.

Metro vs. Your Own Design Language

Facebook Banner

There was a little stir about the Facebook Beta for Windows Phone when it came out. Check out the comments on the official post. A few news sites covered the release, which ended in similar comments. This got me thinking about my view on the situation…

Why has the Metro design gone? Where is the uniqueness of Windows Phone?

Yes, as immediately noticed by those who care – the app doesn’t use the Metro hub pattern that the previous app used, but in my opinion it doesn’t matter because Facebook have their own design language.

Facebook News Feed

In March Facebook announced an update to the News Feed that will bring a lot of design elements from their mobile applications into their main web application, here they clearly state that they’re after a consistent user experience across all of their platforms. While there’s no doubt that the design borrows heavily from Android and iOS apps, but – more importantly to me – it also is very similar to the mobile web experience, which was my primary way of accessing Facebook throughout the day.

Original, Web and New Facebook Experiences for Windows Phone

But the principles are forward looking and similar to Metro, Facebook are focussing on stories and imagery, removing clutter and keeping their distinctive look with the typography and colour choices that users are familiar with. See below an example of how the same information is displayed on both the old and new versions of the Facebook app for Windows Phone. Which one looks more like Facebook?

Old and New Facebook App

By focussing on Facebook design language rather than Windows Phone design language, they’re actually following one of the most important UI principles for Windows Phone – content over chrome. Where the Facebook experience is the content, and the previous Metro UI treatments – like larger fonts and the main panorama – were essentially just chrome.

Does this mean the end of the Metro design language? Obviously not.

My personal view is that the built in templates that come with Windows 8 and Windows Phone 8 are to be used as starting points. You get a lot of good design for free that way, but if your application has its own way of doing things then the Microsoft development tools will allow you to craft them. Real designers make the best decisions from the options that are available to them. In this case, the consistent Facebook experience makes the most sense.

Using Windows 8 (without Touch)

Using Windows 8 (without Touch)

When I had my first Windows PC, I spent a large amount of my time in the DOS environment, playing with scripts and trying to optimize memory. When I went into Windows I had access to cool applications like Solitaire… but most of the things I had ran in DOS.

Using Windows 8 (without Touch)

Windows 8 is like that today, most of the applications I need to complete tasks – be that for work or for personal endeavours – are well established on the Desktop UI paradigm. I tend to use laptops mainly, but when I’m working I plug the laptop into a monitor and a keyboard to get stuff done.

Using Windows 8 (without Touch)

I use a lot of utilities in the desktop for various development tasks, including F#, Python, Ruby, Vim, Filezilla, WinMerge, Fl.ux, KatMouse – all of which are portable applications which do not require installation. I keep these inside my Scripts folder and usually access them via PowerShell commands.

Because these applications sit inside my Scripts directory I get a number of benefits:

  1. I can sync the tools between computers (manually or via the cloud)
  2. I don’t need to sit through loads of installs on new machines (and remove the icons from the start screen!)
  3. I can be sure I always have a rich development environment for when I need to build software

On top of my scripts, I also run a number of proper desktop applications that require installing. Chrome, Office, Visual Studio, SQL Server, the Windows SDK and a few more.

Using Windows 8 (without Touch)

Once I have all these applications installed, Windows 8 gives me everything I need to get tasks done. I have Email, Word Processing, Spreadsheets, and an extremely rich development and scripting environment thanks to Visual Studio and PowerShell.

Using Windows 8 (without Touch)

My Desktop doesn’t include a number of things – apps don’t want to see there. No instant messenger, news readers or weather apps. That kind of information is made visible directly through the start screen and its use of Live Tiles. Clicking on the tile takes you to a full screen application that brings your focus to the task at hand.

Using Windows 8 (without Touch)

The full desktop is just one click away. If I want to check if a Visual Studio build has completed I can just flick back to check. This combination of the new and old interfaces seems to work perfectly for me. Taking all the distractions out of the desktop, and moving them into their own space. If I want to play a game of Solitaire – it takes over the full screen, giving me a rich experience. One click in the top left hand corner and I’m back in the desktop with all my windows exactly as they were.

Using Windows 8 (without Touch)

Am I going to continue using the desktop to access applications and consoles? Yup. Windows 8 has more than this though. The new applications we have today are pretty good. The Bing app has turned out to be extremely useful, for example. But where the new apps currently lag is in the more complex tasks like photo manipulation or music creation.

These kinds of experiences would be better in the full screen UI, and I’m very interested in finding out what the likes of Adobe and Propellerhead Software come up with in the future. But at the moment their products like Photoshop and Reason will have to be accessed via the multi-tasking desktop interface.

Many windows features are still only available in the desktop interface. Most notably File Explorer. There’s no way of casually browsing your file system through the new user interface. Sure you can select files to open inside of other applications – but if you fancy just browsing around – you are out of luck.

Through my use, I can say that Windows 8 has surpassed Windows 7 for its ability to get stuff done with a mouse and keyboard. The new start screen is also going to provide a rich user experience for touch input, and the new applications will really shine in these finger friendly scenarios.

While Using Windows 7 now feels like going back in time, I still think there is work to be done with Windows 8. It’ll be interesting to see if Windows Blue brings any changes to the desktop interface.