Betting on C# and Native for Cross Platform Mobile Development

If there are 2 languages that I consider the most important and versatile are C# and Javascript. We can not deny the omnipresence of Javascript and the web that powers it. It’s an obviously forgone conclusion that Javascript rules the world, mostly client side but also server side with NodeJS.
But what about C#? I believe C# is the only other language that can claim to be having an as wide reach as Javascript. Today it can run on desktop, mobile phones (with Xamarin), small devices and so forth. At this year’s Xamarin Evolve conference Scott Hanselman presented a talk titled “How C# Saved my Marriage, Enhanced my Career and Made Me an Inch Taller“.
So several months ago, I decided I needed to get in to mobile development, get the basics, fully focused on learning the end-to-end mobile development stack. Purely for the fun and a forward looking possible need at my job.
Why Xamarin?
I’ve been watching Monotouch and Mono for Android for the past couple of years and it was time to get to it. Xamarin has created something awesome for us, .Net developers, who can take their existing C# and .Net skills and target cross platform mobile development. It’s not a very smooth ride in the beginning, but as with anything, you will get over it and learn to have the challenging fun that follows. I think it’s worth it.
So why do I think Xamarin is a better direction for .Net and Web developers than going with a hybrid solution like Phonegap/Apache Cordova, Appcelerator, Icenium and a bunch of others? Well, I believe the ‘design and user focus’ is the answer. Native apps provide the best possible user experiences than any hybrid solution can. It will be years before the Web/HTML5 solution can match the native experience. At least that’s what I think. And I am saying that as a web developer with more than a decade and half of web experience. Now, this may not be the “one way” to do it all, and depending on your specific app requirements/cases, a hybrid solution or a pure native (objective-c or java for android) may be a better, cost-effective solution. There are a number of articles, blog posts on which solution is better suited for a given app-scenario, so I won’t get in to it.
For me, end user experience trumps everything in most cases. You’ve gotta be designing in the modern world for the end user. Go watch this fantastic talk by Billy Hollis titled “Design or Die: The Challenge to the Microsoft Developer Ecosystem“.
The key thing really is – build real native apps with native SDK for UI and do it using my beloved C# and .Net.
So I picked Xamarin. There was no where else for me to go. It was like the good old ASP.Net days, of taking something you already know and venturing in to a new direction and a new universe, with unknown challenges. So far, I am loving it. It’s been very transformative experience. I haven’t yet gone so far as to develop in F# with Xamarin. Someday!
One of the major challenges I had early on is to figure out how to lay out the solution, where should the reusable/decoupled pieces go, how does it work with server code etc. Finally I decided to go with Platform specific libraries (with code file reuse, and separate csproj file for each platform) than trying the ad-hoc, error-prone PCL (Portable Class Library). As of this writing, we are still waiting for Xamarin to provide full support for PCL, which I hear is coming very soon.
Sometimes you might run in to, “Oh yeah.. but wait, no…” experiences. Well, that’s normal.
First thing I needed was solid equipment, what could be better than a Macbook Air. The Mac mini is just mini, I want the full OS X experience while developing, plus portable. Takes getting used to, but I think, why not? So after the SAF (Spouse Acceptance Factor) was high enough, I bought this Macbook Air.
Paid $1158 with the apple insider promo code.
Product Image


Development setup:

On the Macbook Air, first you need to download and install XCode and iOS simulators from the Mac app store. Then, I’ve setup VirtualBox to host Windows 8.1 VM (link for a gotcha), where I can do all the server side/web-api/database work. Create 3 desktops (areas, a OSX concept) on the Mac side of the house, move the Windows to one desktop, Xamarin Studio to another, and Chrome browser on the third one. And then I get to use the sweet 3-figure gesture to move between them very smoothly with no friction. Then I setup all the keyboard shortcuts I know and love from Visual Studio, on there with the Xamarin Studio (F9, F10, F12 and the whole nine yards). I prefer to work with ‘Xamarin Studio on Mac‘ than ‘Visual Studio on Windows and use the Mac as build-host. It just feels faster. I use the Inconsolata font which is not as great as Consolas, but I can live with it.

Xamarin Links:
Here is a link roundup for the cool and productivity enhancing avenues/components for Xamarin. It’s like the .Net world has opened up new possibilities.

Restsharp – Fantastic library to decouple all your service calls using this component.

Servicestack – I love their serialization/deserialization (ServiceStack.Text), it’s the fastest, I am using it everywhere replacing everything else on server side web apis.

MvvmCross – a leading MVVM xplatform library for Xamarin

MvvmLight – MVVMLight comes to cross platform mobile apps

Monotouch dialog – check out this json based UI creation

Xamarin.Mobile – exposes a single set of APIs for accessing common mobile device functionality across iOS, Android, and Windows platforms.

Xamarin.Social – Share statuses, links, and images on Facebook, Flickr, Twitter and more.

Xamarin.Auth – A cross-platform API for authenticating users and storing their accounts.

Platform specific libraries for code reuse – PSL as opposed PCL (Full support for PCL in Xamarin is coming, still not there yet) – Use the same poco on client and server side for json serialization/deserialization – for clean and maintainable code

NativeCSS / Pixate – yes, write CSS to theme your native UI, win for us the web guys!!!

Google maps component for mapping solutions

ObjectiveSharpie – a very powerful binding definition generator for third party Objective C libraries to help provide APIs matching the .NET idioms and ensure delightful APIs.

Testcloud for testing – it’s an awesome testing solution

Native SignalR – Real time web for the native mobile apps

Signature pad (Imagine building paperless document signing app)

Enterprise grade barcode component

ProtoPad – great prototyping tool for UI, just like linqpad but for UI has whole bunch of other useful components as well

With this stack, the stuff you can build is pretty much whatever you like. There is a short 1-2 weeks learning curve, but after that it’s a lot of fun.

There is a good chance, you will feel like this, after you finish writing your first app.
Hope that helps folks who want to get in the world of Xamarin and Cross platform mobile development.
Update: For a detailed post on why native UI and Xamarin is the way to go for XPlatform mobile development, read this fantastic blog post by Wally McClure
Happy coding !!!

One thought on “Betting on C# and Native for Cross Platform Mobile Development”

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>