Category Archives: software development

How to test and debug an app on Surface RT in a hotel room

I wanted to test an app on Surface RT this morning, though I am out of the office with just a Samsung Slate (has Visual Studio), the Surface, and hotel wi-fi.

You can do remote debugging on Surface RT as explained here, however you need a private network.

I set up an ad-hoc network from the Samsung Slate as described here:

Open an elevated command prompt

netsh wlan show drivers

netsh wlan set hostednetwork mode=allow ssid="wireless name" key="password"

netsh wlan start hostednetwork

This allowed me to connect the Surface RT to a private network with the Slate.

Next, I needed to download and install the remote debugging tools for ARM from here.

I ran the remote debugger and was able to connect from Visual Studio on the Slate, but ran into a small issue. I needed a developer license for the Surface, but while on the private network it was not on the internet. When the remote debugger prompted to install a developer license, it could not retrieve it.

The solution was to disconnect, connect to the internet, then install the developer license using PowerShell. Run show-windowsdeveloperlicenseregistration from an elevated PowerShell window.

image

Then I returned to the private network and was able to launch my beautifully designed test app:

image

image

Note that for the actual test I did not run the app attached to Visual Studio. Rather, I deployed in release mode and then ran separately, to avoid the slowdown from the debugger. Once deployed, the test app remains in the Start screen for launching.

Investigating Surface RT performance: Counting primes in C# and JavaScript

How is the performance of Surface RT? Tolerable but rather slow would be my quick summary. Surface RT has a quad-core NVIDIA Tegra 3 chipset.

In order to investigate further, I built a simple app to count primes, using essentially the code here. I ran the code both in JavaScript and in C#. This is a single ad-hoc and naive test that only covers one aspect of performance, but I have still found it an interesting indicator. I then ran the app both on my Intel Core i5 Samsung Slate and on Surface RT (yes it was interesting figuring out how to debug on Surface RT in a hotel room).

Here are the results:

On Intel Core i5:

  • Count primes up to 1,000,000: 1.05 secs (in browser)
  • Count primes up to 1,000,000: 0.88 secs (in embedded webview)
  • Count primes up to 1,000,000: 0.32 secs (C#)
  • Count primes up to 10,000,000: 6.31 secs (C#)

On Surface RT:

  • Count primes up to 1,000,000: 3.49 secs (in browser) Slower by 332%
  • Count primes up to 1,000,000: 3.53 secs (in embedded webview) Slower by 401%
  • Count primes up to 1,000,000: 1.81 secs (C#) Slower by 565%
  • Count primes up to 10,000,000: 49.03 secs (C#) Slower by 777%

The Core i5 is running at 1.6 Ghz. Surface RT has an NVidia Tegra 3 1.3 Ghz chipset.

You could count primes more quickly in both cases by using parallel processing; this is a single-threaded test.

What is notable here?

  • First, Surface RT is slower than I would expect and I hope Microsoft improves performance with future updates.
  • Second, C# is substantially faster than JavaScript in this test, around twice as fast, which makes me question the advice I have heard from some spokespersons that HTML and JavaScript is the preferred approach for apps.
  • Third, the factor by which C# is slower is greater than the factor by which JavaScript is slower. This surprised me; I had expected the reverse for some reason.

Of course, other performance tests will yield different results. When I tried the Sunspider JavaScript test Surface RT was about 5 times slower.

One piece of good news: there was little difference between performance in the embedded or non-embedded browser.

Update: I also tried this test in C++. There was barely any difference. The Core i5 counted primes up to 10,000,000 in 6 seconds. The Surface RT performed the same feat in 46 seconds.

Update 2: A Google Nexus 7, which also has a Tegra 3 chipset, can only manage 76 seconds for the JavaScript test (primes up to 10,000,000).

Steve Ballmer shows off Windows 8 in Build keynote

Microsoft’s BUILD conference has kicked off in Redmond with a keynote featuring CEO Steve Ballmer, Developer evangelist Steven Guggenheimer, and Kevin Gallo from the Windows Phone team. There were also a few guest appearances, including Tony Garcia from Unity, a cross-platform games engine.

The company has a lot to talk about, with Windows 8 just launched – four million upgrades sold so far, we were told, which seems to me a middling OK but not great result – and Windows Phone 8 also fully announced for the first time.

The keynote opened with a performance by Jordan Rudess from Dream Theatre, enjoyable and somewhat relevant given that he has helped create two music apps for Windows 8, Morphwiz and Tachyon, which he talked briefly about and played on a Surface RT and Lenovo desktop.

image

Then Ballmer came on and gave what I can only describe as a hands-on tutorial in how to use Windows 8 apps. I found this odd but it was well received; my conclusion is that many people have not bothered to look closely at Windows 8, or have been put off by the Start menu issue, and much of what Ballmer showed was new to them. It was not to me, so I was not gripped by this section of the keynote.

I preferred the presentation from Steven Guggenheimer; most of what he presented is also covered here, and included the announcement of forthcoming Windows 8 apps from Disney, ESPN and Dropbox. The Dropbox announcement is particularly significant, since I have heard complaints about its absence from Surface RT, which is unable to run the usual desktop client for Dropbox. Another app that is on the way is from Twitter. Guggenheimer also described a new PayPal API for Windows Store apps.

I do wonder why key services like Dropbox and Twitter are only now announcing Windows 8 apps. Windows 8 has been available in preview versions since last year’s Build event, and has not changed that much as a developer platform.

Gallo introduced some of the new features in Windows Phone 8, and claimed that Microsoft has delivered the majority of developer requests in the new Phone SDK which is available from today. He emphasised the possibility of sharing code between Windows Phone 8 and Windows 8, using Visual Studio to ensure compatibility.

Garcia presented Unity for Windows Phone, which is potentially a big deal, since it is widely used. The demo of immersive gaming graphics on Windows Phone 8 was impressive.

image

Finally, Nokia’s Richard Kerris came on, mostly to announce a giveaway of the new 920 Windows Phone 8 device for Build attendees.

image

This raised a loud cheer as you would expect, though it may be significant that the free phone won an even warmer reception than the earlier announcement of a free Surface RT.

The cost of signing up for a Windows Phone developer account has been reduced to just $8.00 for the next few days; see here for more details.

Did Microsoft do enough in this keynote? Personally I would like to have seen more technical depth, and a more convincing presentation of why the company thinks these new devices have what it takes to take on Apple and Google. Still, this is all about partners, and the arrival of Dropbox and Twitter as Windows 8 apps, and Unity for Windows Phone 8, are all significant events.

Windows 8 launches: key questions remain, but Surface shines

I am in New York for the launch of Windows 8. This morning was the general launch; the Surface RT launch is to follow this afternoon. Windows chief Steven Sinofsky introduced the event. I was intrigued by how dismissive he was about a key Windows 8 issue: the learning challenge it presents to new users. He gave the impression that a few minutes experimenting will be enough, though he also referred to a guide that may be new; yesterday I picked up a small booklet which I had not seen before, introducing Windows 8.

Next Microsoft’s Julie Larson-Green and Michael Angiulo came on to show off a few details about the Windows 8 user interface, followed by Ballmer who gave what is for him a muted address about how great Windows 8 is going to be. Solid facts were few, but Microsoft did mention that over 1000 devices are certified for Windows 8.

So what is Windows 8 all about? It’s a tablet, it’s a laptop, it’s a PC we were told, in other words, everything. But everything is also nothing, and my sense is that even Microsoft is struggling to articulate its message, or at least, struggling to do so in ways that would not offend key partners.

Personally I like Windows 8, I find it perfectly usable and appreciate the convenience of the tablet format. That said, I look at all these hybrid devices and my heart sinks: these are devices that are neither one thing nor another, and pay for it with complexity and expense. Will they win over users who might otherwise have bought a MacBook? I am doubtful.

Windows RT and Intel Atom devices are more interesting. If Microsoft and its partners can push out Windows 8 devices that inexpensive and work well on tablets without keyboard clutter, that is what has potential to disrupt the market.

That brings me on to Surface. It is all in the body language: the conviction that was missing from the Windows 8 keynote in the morning was present in the Surface keynote in the afternoon. Even the room was better, with stylish Surface fake pavement art in the corridor and smart white seating.

image

General Manager Panos Panay showed off little details, like the way the rear camera angles so that it is level when the Surface is set on its kickstand. He talked about Microsoft’s drop tests, claiming that they had tested 72 different ways to drop a Surface and designed it not to break. He demonstrated this by dropping it onto a carpet, which was not too challenging, but the fact that Sinofsky successfully used it as a skateboard was more impressive.

image

No doubt then: Microsoft has more enthusiasm for Surface, described by Panay as “the perfect expression of Windows”, than it does for the 1000 certified devices from its partners, though the company would never admit that directly.

What is the significance of Surface? It goes beyond the device itself. It will impact Microsoft’s relationship with its hardware partners. It embodies an Apple-like principle that design excellence means hardware designed for software designed for hardware. It shows that the “OK but nothing special” approach of most Windows hardware vendors is no longer good enough. If Surface is popular, it will also introduce demand for more of the same: a 7” Surface, a Surface phone, and more.

Despite its quality, the success of Surface is not assured. The biggest problem with Windows 8 now is with the lack of outstanding apps. That is not surprising given that the platform is new, and you would think that users would make allowance for that. On the other hand, they may lack patience and opt for better supported platforms instead, in which case building app momentum will be a challenge.

ITWriting app hits the Windows 8 store

Hands on where possible is part of my technical journalism philosophy, so I have been trying out Windows 8 development for some time. After playing around with and adapting Microsoft’s blog reader sample I decided to take it further and try submitting it to the Windows 8 Store.

Today it was certified so you can install it now. It is free of course. 

image

There is not much to it. It features quick access to recent posts on itwriting.com and gadgets.itwriting.com, recent tweets, and dedicated links to Windows 8 survival guides for both keyboard/mouse and touch/tablet users.

Despite its simplicity, creating the app was an interesting exercise. Having the app layout change in a moderately sensible way when switched between portrait and landscape, and filled or snapped, taught me a bit about XAML and the VisualStateManager element. I also struggled a bit with the flyouts that you use to implement app settings, the ones that appear when the user displays the Charms menu and taps or clicks Settings when your app has the focus. I used the official sample though I discovered that it will not compile as-is because the standard brush names have changed since the release preview for which the sample was apparently created. I have have some sort of z-order bug there which I have not yet solved.

Creating apps for Windows 8 is not difficult exactly, but it is fiddly. It seems to me harder than, for example, creating a desktop app using Windows Forms. In mitigation, setup and deployment is done for you which is a significant advantage. I was also pleased to discover that the app works fine on a Surface RT.

image

The Windows Store certification process was rather straightforward in my case; the app passed first time. I had noticed from other reports that having a privacy policy in place is important, so made sure that this is linked in this settings.

I do have some ideas for making the app a little more interesting. Share support and offline support would be obvious enhancements. Watch out for future updates!

Telerik Icenium: new desktop and cloud IDE for mobile development

When I heard that Telerik is bringing out a new IDE for mobile app development, I could contain my excitement, especially after learning that it is another PhoneGap/Cordova based approach, wrapping JavaScript and HTML as a native app. While speaking to Telerik’s Doug Seven though, I found myself increasingly impressed.

If that name sounds familiar, it might be because Seven was a director of Product Management in the Visual Studio team at Microsoft, and you can see that influence in the new IDE, which is called Icenium. Spot the Metro-style buttons at top left of the IDE!

image

Icenium has several components. There is a Windows IDE called Graphite, illustrated above. Those on other platforms, or in distributed teams, can use Mist, which is a browser-based IDE which replicates many of the features of Graphite. There is also a set of cloud-based services to handle building apps for iPhone, iPad and Android devices. This means you do not need to install all the necessary SDKs on your own machine. Icenium also lets developers build signed iOS packages without needing to have a Mac.

The Icenium Device Simulator lets you test applications quickly on your own machine.

image

The tools look good, though I have not tried them yet, but the unique feature of Icenium is the ability to deploy and test quickly on multiple devices. Code is kept synchronized between Graphite and Mist, and also pushed out though LiveSync to multiple devices. Here is a snap of the view from Doug Seven’s desk, grabbed from his online presentation. He showed me how a code change ripples almost instantly to all these devices for testing.

image

An intriguing part of this is an iOS app called Ion which is a sort of runtime shell for Icenium apps. This means you can load apps for testing onto iOS devices that are not unlocked for developer use. You can also demonstrate apps on a client’s device using Ion. Apple’s attitude to runtimes in the App Store must be softening.

Icenium supports version control using either a Git repository hosted on the service, or your own choice of URL-based Git repositories.

Pricing will be per-developer at $16.00 per month if you sign up for a year, or $19.00 per month without a contract. Once you sign up, you can use all the tools on all your machines. You can also use Telerik’s Kendo UI Mobile framework. It is free until May 1 2013.

Isn’t Icenium’s cloud build feature similar to what Adobe’s PhoneGap Build already does?

“It’s a great comparison,” says Seven. “Adobe has the technology to make this [seamless development experience] possible, they just chose not to do it … [PhoneGap Build] is not integrated into the workflow. It’s a very manual process, I have to zip up my files, submit them to the PhoneGap Build process, then I get back these application packages that I have to manually deploy to my devices to see if it works.”

There is no support yet for mobile web apps, as opposed to apps packaged with Cordova, but this is a possibility for the future.

Like Adobe, Telerik has found WebKit and Google Chrome irresistible, despite Seven’s Microsoft background. WebKit is embedded in the Graphite IDE. You can use Mist with any modern browser, though “the one limitation is that the browser-based device simulator does require Chrome,” though he add that in general, “I use Mist on my iPad all the time.”

ThoughtWorks bemoans excessive software complexity, advocates small, focused services

ThoughtWorks has released its latest Technology Radar, an opinionated analysis of software development trends.

Things the folk at ThoughtWorks like include automated build and deployment, essential for Continuous delivery; NOSQL database managers especially Neo4j; mobile-first development; the AppCode IDE for Apple’s Objective-C; the Graphite realtime graphing tool for creating dashboards; Clojure and Scala for programming.

I meet some of the ThoughtWorks team at developer conferences from time to time, and generally find them smart and though-provoking to talk to. They must be the despair of the big enterprise software vendors, with a liking for open source and an aversion to heavyweight high-maintenance systems.

This remark particularly caught my eye:

Simple architectures—Simple continues to gain traction, including both techniques for building and composing applications, as well as infrastructure-based techniques to enable simple deployment, failover and recovery. This theme is a recurring one for us, but we have not yet seen the usage shifts we believe are necessary.

I asked consultant James Lewis and practice lead Sam Newman to expand on that. Why do we continue to choose complexity over simplicity?

“A lot of people like to stay inside their big box, and don’t understand the complexities that then creates,” said Newman. “There’s a lack of critical thought given to how services talk to each other. A lot of them are driven by whatever the vendor says you do. Java makes RMI very easy. [Microsoft] .NET makes binding to WSDL [SOAP] schemas very easy. All these tools make bad things very easy to do.

“When you start talking to organisations about smaller services that are focused on doing one thing well, they have the horror associated with now having more than one box to manage and operate. So it’s hard to talk about moving from one big monolithic complicated box that is hard to change, to lots of little boxes, without also having conversations with those clients about how they get better at managing multiple services.

“Netflix has 300 services. Each service runs on at least six machines. They are very good at deploying those services. Yet they are not an overly complicated domain compared to some of our clients.”

“Amazon were talking about this in 2004,” adds Lewis, “the idea that you join up development of these small, simple applications with the operational control, so the same people who build them are also the people who run them. Now that we’re seeing both private and public clouds, and the ability to spin up machines becoming more and more prevalent, its starting to become more attractive.”

This is a consistent theme from ThoughtWorks. Break up complex solutions into many small services, think about how they talk to each other (with REST and HTTP favoured), and think about the infrastructure and how to automate it as well as the software itself.

“In many organisations these conversations are happening,” Newman told me. “I go to clients now, and they talk about the Enterprise Service Bus as being something they’d love to get rid of if they only knew how. Five to ten years ago, to even mention the Enterprise Service Bus as being a problem, they’d look at you with daggers in their eyes.”

“It’s almost like we’re now able to fulfil the promise of service orientation,” says Lewis. “It needed these additional practices, around things like automated deployment, automated rollback, and an understanding that people and process are tied intrinsically with it.”

Another issue, claims Lewis, is that software architects simply get out of touch with best practice.

“Most architects who build big systems are quite a long way from their codebases. They sit in rooms talking to other architects. They might have last written a line of code five or ten years ago. What they do is to design systems as they would have done ten years ago. People do get divorced from the latest trends and perpetuate less effective ways of doing things.”

Finally, here’s something for the Microsoft platform people who read this site. ThoughtWorks is not altogether averse to Microsoft and mentions the Azure cloud platform as something which is becoming interesting. But Windows Phone:

Despite a promising start to Windows Phone, a well thought-out user interface, and probably the best development experience of any mobile platform, we have seen several stumbles in the execution of the platform strategy by Microsoft and its partners. This makes us less optimistic about the future of the platform than we were in the last radar.

Translation: nice mobile platform, but nobody’s buying it. Then again, on Monday next week Windows Phone 8 will be properly unveiled. Still hope?

Hands on Windows 8 development: Twitter and hyperlink hassles

I have been messing around with a Windows 8 app to present content from ITWriting.com in an app, mainly as a learning exercise. I came up with the idea of showing recent tweets on the main page of the app. Like this:

image

I thought this would be easy, but encountered several problems. I am developing in XAML and C#; this aspect would probably be easier in HTML.

The first problem: retrieving the tweets. The Twitter REST API version 1.1 has GET statuses/user_timeline which does what I want, except that it requires “user context”, in other words a Twitter log-in. That is an unacceptable requirement for a user simply viewing my tweets, rather than their own timeline.

The deprecated  Twitter RSS API on the other hand is perfect. Unfortunately:

Please note that there is no support for the RSS response format in API v1.1. Properly versioned API v1 URLs will cease functioning in March 2013

Never mind, it will do for the moment. I created a Twitter data source which retrieves the tweets as RSS. In my XAML I have a ListView which is bound to this data source. This ListView has an ItemTemplate which defines what appears in the list. I added a TweetItemTemplate in the Resources section of the XAML which displays each tweet in a TextBlock. So far so good.

image

No hyperlinks though – they are dead. What is the use of a tweet without hyperlinks? Not much. I thought of a hack which would let you click or tap an entire tweet, look to see if a hyperlink is there, and then launch it. Ugly, and would only work for one hyperlink per tweet.

TextBlock does not support hyperlinks. However there is a way to do this using RichTextBlock. This supports a collection of inline elements. You can have a Run element containing text, then an InlineUIContainer containing a HyperLinkButton, then another Run element and so on. The Hyperlink will be out of alignment, as shown here, but you can fix that by tweaking margins and padding.

Of course, this approach does mean parsing the tweet to extract the URLs and then building the RichTextBlock content. So in place of my simple TextBlock binding I now have this:

  <ContentControl Content="{Binding Path=Title,Converter={StaticResource tweetToBlocks}}"></ContentControl>

I have also written a converter class which takes the bound value, builds the RichTextBlock in C#, and returns it. This gets you the result in the first image in this post. Not too bad, and the links work.

What is annoying though is that the mouse pointer does not change to a hand icon when you hover over the link. I thought I could fix this by subclassing HyperLinkButton and adding code to change the cursor on the PointerEntered event:

Window.Current.CoreWindow.PointerCursor = new Windows.UI.Core.CoreCursor(Windows.UI.Core.CoreCursorType.Hand, 1);

This does not work. At least, you can see a flash as the cursor tries to change, but it is overridden by the RichTextBlock which changes it back to a text select cursor. I have not found a way round this yet.

I then tried another approach. You can use a RichEditBox which does support links. The approach is different; you set the text of the Document property and then use the Link method to assign a link to a TextRange within it. It works; but I was frustrated to find that the mouse pointer still does not change to a hand when over the link. The RichTextBlock actually works just as well and is more integrated with XAML.

image

I am sure you could fix this by using a WebView – embedded IE – for each tweet, but that seems to me an unduly heavyweight approach. Better perhaps would be a single web view showing all the tweets, which I might try when I have a moment.

Even so, I was surprised how tricky it is to show tweets with hyperlinks in a ListView.

Twilio adds support for WebRTC: real time communications in JavaScript

Cloud telephony company Twilio has announced beta support for WebRTC at its conference in San Francisco.

WebRTC is a project supported by Google, Mozilla and Opera and lets you do real time communications, including access to camera and microphone, using a JavaScript API without a plug-in. There is also a W3C Working Group.

WebRTC support will be a feature of the Twilio client:

When Twilio Client apps are used with a WebRTC compatible browser, such as future versions of Google Chrome and Mozilla Firefox, Twilio Client will automatically take advantage of the improved audio performance of the WebRTC technology. If the browser doesn’t support it, Twilio Client will still work and fall back to existing browser technologies.

says Twilio.

Other new APIs announced at the conference include Test Credentials, which lets developers test code against the Twilio API without actually placing calls; Usage for retrieving Twilio usage logs and Usage Triggers which you can use to implement usage caps in order to limit cost.

Adapting the Items Page template in a Windows Runtime app

A while back I adapted a sample application in order to create an app for Windows 8. I am mulling over putting it in the Windows Store, but it needed some work. In particular, I wanted to add a Twitter feed to the front page. There is plenty of space:

image

Sounds easy; but inspecting the layout code I realised that I did not understand it all that well at first.

It is based on the Items Page template in Visual Studio 2012, and there is a fair amount going on in that template:

image

  • The contents are data-bound, which is great at runtime but inconvenient at design time as the page is empty.
  • The contents are layout-aware which means that they account for the four views possible in a Windows Runtime app: landscape, portrait, snapped, and filled. The “filled” name is a little misleading; this is an app which occupies most (but not all) of the screen when another app is snapped to one side.
  • The page uses resources and templates for its element styling, which are defined either in the page itself, or in StandardStyles.xaml which resides in the Common folder in your project (added automatically in projects which use the ItemsPage template).

It’s worth adding some dummy data early on so you can see what the page really looks like:

image

For example, imagine that you want to use a smaller item size that the default 250 x 250 size. Proceed as follows:

  1. Copy the DataTemplate called Standard250x250ItemTemplate from StandardStyles.xaml. Place it in the Page.Resources section of ItemsPage1.xaml (or whatever you called your ItemsPage). Rename it to, say, “MyItemTemplate”.
  2. Modify it to use a smaller size. You will probably want to adjust the bound elements as well, plus change the references to the standard Brush elements like  ListViewItemPlaceholderBackgroundThemeBrush as well.

Here is how the page looks with the space for the image removed, the DataTemplate height set to 50, and the height of the bound Title field set to 20:

image

Note that this template is not used by the Snapped view. For that, you will need to copy and modify the Standard80ItemTemplate, or make your own template suitable for an item in the Snapped view.

The code that determines which templates are used in which state is in the VisualStateManager.VisualStateGroups element. This has a Storyboard animation for the Portrait and Snapped views. The way this works:

  1. The default view is landscape. This is why in the XAML there is a GridView called itemGridView which is visible, and a ListView called itemListView which is hidden (Visibility="Collapsed").
  2. In the Snapped view there is only room for a single-column list, not the grid. Therefore the Storyboard for the Snapped view sets the itemListView to visible and the itemGridView to hidden.
  3. When you change back to a non-Snapped landscape view, the layout reverts to the default. Code for this in in LayoutAwarePage.cs, also in the Common folder.

After working this out I was better able to adapt my own page. More on that another time!