Newer posts are loading.
You are at the newest post.
Click here to check if anything new just came in.

June 05 2012

Developing cross-platform mobile apps with C#

Building a mobile app that runs on more than one platform, with minimal code changes, is a technical Holy Grail. The HTML5 stack (using CSS and JavaScript, among other standards) and Java are two solutions. Another is Microsoft's .NET plus C#, a combo that's been overlooked outside the Windows Phone 7 developer community despite its potential to create apps that can run natively on Android and iOS.

In the following interview, software engineer Greg Shackles (@gshackles) aims to expand the potential of this platform. Shackles is the author of "Mobile Development with C#" and maintains a blog focusing mainly on .NET and its related technologies.

We hear a lot about using C++ to build mobile apps, so why use C# — and the associated .NET?

Greg Shackles: There are various ways to share code across different platforms. Unfortunately, many approaches will abstract away the user interface from the developer in order to achieve a "write once, run anywhere" solution, making it easier to release an application quickly on many platforms. This sounds great, but often it will lead to a degraded user experience since the app won't look and feel native to that platform. The user experience is the most important thing to consider when designing an application.

Using C# and the Mono Tools allows the developer to share a large subset of an application's code across multiple platforms while still building a completely native user interface on top of it for each platform. Applications created with this approach will look and feel native because they're using the exact same APIs and toolkits exposed by the platform. In some cases, the Mono tools even help to clean up the platform APIs to make them easier to work with than those exposed by the native languages.

This approach allows developers to concentrate on solving business problems rather than having to manage multiple languages and reinvent the wheel every time they want to expand to a new platform. Going even further, the code that is shared across platforms isn't limited to mobile applications. It can go pretty much anywhere that C# and .NET are supported, such as ASP.NET, Silverlight, or WPF. Developers already familiar with these technologies can easily hit the ground running and start targeting these new platforms while reusing the skills they already have.

What else makes the .NET Framework well suited for mobile development?

Greg Shackles: C# and .NET are both very mature and powerful technologies. They have evolved over the years to provide support for things like asynchronous programming and memory management, and features like LINQ help make them great to work with as a developer.

For example, there is no garbage collector when writing iOS apps with Objective-C. That's a feature .NET developers are used to having. MonoTouch actually brings a garbage collector along with it, making it much easier to work with, without having to worry about manual memory management.

What are a few of the technical weaknesses of C# or .NET?

Greg Shackles: There aren't too many technical limitations, but whenever you place another layer between you and the native platform, some problems are unavoidable.

One example is that on iOS, you are not allowed to dynamically execute code at runtime, meaning that the standard .NET style of just-in-time compilation is not permitted and that aspects of .NET that rely on runtime code compilation are not possible, such as Reflection.Emit and the Dynamic Language Runtime. To get around this, MonoTouch compiles the application down to static code ahead of time. This particular limitation does not apply on Android, which does allow for just-in-time compilation.

For those who are already developing native apps for Android or iOS, what benefits would they gain from using C#?

Greg Shackles: For developers who have already built their apps in Java in Objective-C, the case for switching to a new set of tools definitely becomes more difficult to make. The benefits they would get from making such a move would largely be in the ability to share code across all of the platforms rather than have to rewrite it in a different language every time. Both MonoTouch and Mono for Android offer the ability to interact with code written in Objective-C and Java, so code already written in those languages could still be leveraged.

What kind of cross-platform mobile apps are easy or best to make under C#?

Greg Shackles: I don't think there's any particular category of app that's obviously more difficult to write in C#. For extremely simple applications that don't have much logic, it becomes more of a decision of preference for the developer rather than a strategic advantage. In reality, not many applications fall into this category. A majority of applications will need to perform tasks like accessing the Internet or saving to a database, and that is where it becomes beneficial to be able to write that code once and share it across all platforms. Personally, I find C# to be a much nicer language to work with than Objective-C and Java, so that alone becomes an advantage of using it.

.NET is native on Windows Phone 7, but it's not on Android or iOS without the use of MonoTouch or Mono. What are the performance issues or differences across these mobile platforms when you're developing for all three at once using C# through .NET and its unofficial variants?

Greg Shackles: The addition of another layer between you and the platform will have its consequences, but by and large, it's not something you'll notice or need to worry about as a developer. Since MonoTouch applications are run through its ahead-of-time compiler, their performance is already highly optimized. Mono for Android applications include their own instance of the Mono runtime that .NET code is run against and includes an intelligent garbage collector that is optimized for managing objects across the different runtimes. In general, you won't be able to see any difference in performance between an app written in C# and one that is not.

One other common concern is the size of the application, since the .NET Framework is not known for being minimal. Both Mono for Android and MonoTouch ship with a tool called a linker that is included as part of the build process. The linker is a static analysis tool that scans the compiled assemblies in the application and actually strips out any pieces of the framework that are not referenced. As a result, your application will only ship with precisely the pieces of the .NET Framework that you actually use, which drastically cuts down the size of the application. With each release, the Mono team seems to find new ways to optimize the linking process, so this size overhead continues to dwindle down further, even though it is already rather minimal.

This interview was edited and condensed.

Mobile Development with C# — This hands-on guide shows you how to reuse one codebase across iOS, Android, and Windows Phone by combining the business logic layer of your C# app with separate, fully native UIs.

Related:

March 29 2012

Developer Week in Review: Google I/O's ticket window open and shuts in record time

This week, I'd like to take a moment to thank the good folks over at Parkland Medical Center, who took pity on the retching, sweat-covered soul who appeared on the doorstep of their emergency room last Friday morning. They swiftly (well, after 15 eternal minutes in the waiting room, which is pretty swift for a walk-in to an ER) got him hooked up to an IV and introduced the two God-given holy fluids of morphine and Dilaudid. On a totally unrelated note, I'd like to proudly announce the birth of a healthy 3mm kidney stone at 5PM last Friday. Donations to its college fund can be made ...

Extending the trend line doesn't look good

Google IOLast year, Google I/O sold out in under an hour. This year, it only took 20 minutes. If we extend the trend-line out a few years, the only people who will be able to get in will be those who have access to micro-second responsive stock market trading programs and hyper-tuned eBay auction sniping software.

At least, however, Google fans have some clue when the registration opens for their conference. Those of us still waiting for Apple's WWDC conference know it will have to open for registration soon, but the exact date and time is a mystery. Thankfully, the multi-thousand dollar registration fee tends to make WWDC a bit slower to fill up, but it will still be a race for those who require authorization from their management to go (some of us get authorization months in advance, specifically for this reason).

If there's a solution to this classic supply versus demand problem, I can't see it. Regional conferences reduce the benefit of getting all the developers together in one place and would have the companies sending their development staff to the four corners of the world. Maybe Apple and Google need to start renting out football stadiums instead of conference facilities.


More pigs spotted airborne

For those who have been taking a skeptical view of Microsoft's avowed embrace of the open source movement, there's more reason to believe it's genuine. This week, Microsoft released a whole crop of its .NET technology to its CodePlex open source repository, and the company did it under the hyper-liberal Apache 2.0 license rather than something proprietary and restrictive. In addition, Microsoft has started using the developer-friendly git source control system — another attempt to make itself more compatible with the open source community as a whole.

Of course, releasing portions of its proprietary environment as open source is still an attempt to get people to use Microsoft's technology as a whole, including Visual Studio, but the more it puts out there under licenses that include patent grants, the more possible it is to incorporate compatibility with Microsoft products in non-Microsoft platforms and products.

Was the cake made out of 0xDEADBEEF?

It's practically unimaginable today, but when the gcc compiler was first released 25 years ago this week, the only way to compile your code was to pay your hardware vendor for a proprietary compiler package, sometimes costing tens of thousands of dollars.

In the intervening years, the shining star of the Free Software Foundation (FSF) has become the go-to (excuse the expression) compiler for most modern compiled languages, available on and for just about every hardware platform you can think of. It doesn't have the death-grip hold on the industry it once did, with Apple among others moving to LLVM, but it was the first and for a long time the best compiler money couldn't buy. You may argue with the current philosophy of the FSF, but give it due props for opening up the world of programming to the world by making free tools available to anyone who wanted them.

Fluent Conference: JavaScript & Beyond — Explore the changing worlds of JavaScript & HTML5 at the O'Reilly Fluent Conference (May 29 - 31 in San Francisco, Calif.).

Save 20% on registration with the code RADAR20

Got news?

Please send tips and leads here.

Related:

June 15 2011

Developer Week in Review: Are .NET programmers going extinct?

After an adventure-filled return trip from WWDC (Southwest eventually did find my luggage ...), it's back to the regular grind, spanning the globe to bring you all the news you need.

Are .NET developers the next buggy whip makers?

So, you say you're a ninja .NET guru, able to churn out WFC C# code in the blink of the eye, and you've got every obscure Microsoft API call memorized? Well, if recent rumblings from Redmond are to be believed, there's a large asteroid heading your way called Windows 8.

To say that Microsoft developers are unhappy over the news that tablets running Windows 8 will use HTML5 and JavaScript as an app programming platform would be to say that Steve Jobs likes black turtlenecks. While Microsoft was clear to point out that old-style Windows programs will run on Windows 8, the message seems to be that spending years and years becoming a master of the arcane programming secrets that make Windows tick will no longer be necessary.

This is certainly good news for anyone who has ever taken one look at the phonebook-size manuals that .NET programming requires and ran away screaming. It also would seem to be good news for the HTML5 standard, although Microsoft's history with standards is a checkered one. But if your claim to fame is knowing the Microsoft platform inside and out, the writing may be on the wall that your talents are no longer going to be in such high demand.

Sorry I missed gym class, I was managing my IPO...

You may feel pretty proud of your child, who just won the spelling bee or got an A on her last math test. Then again, you could consider young Daniil Kulchenko, who just sold his company to ActiveState at the tender age of 15. Kulchenko's product, a tool for Perl development in the cloud, evidently caught the eye of the scripting IDE maker, and ActiveState both bought out the company and brought Kulchenko on-board as a part-time employee.

Forget feeling inadequate about your child. Kulchenko makes me feel inadequate.

OSCON Java 2011, being held July 25-27 in Portland, Ore., is focused on open source technologies that make up the Java ecosystem. (This event is co-located with OSCON.)

Save 20% on registration with the code OS11RAD

Get Ready for J2SE 7

It's taken five years, but the Java Community Process (JCP) executive committee has finally put their seal of approval on Java v7. The vote was 13-1, with Google the lone holdout. However, if you look at the comments that accompany the "yes" votes from companies such as Red Hat and IBM, you'll see that no one was particularly happy about Oracle's insistence on retaining the licensing veto on Java implementations, a stand that drove Apache out of the JCP after Oracle refused to bless the Apache Harmony implementation.

Java 7 will include support for multicore processing, as well as a bunch of improvements to the language, such as being able to switch on a string value, and a better way to check for null values. The new standard faces a final vote before it becomes the law of the land.

Got news?

Please send tips and leads here.


Related:

April 23 2010

Bank Reform and Net Neutrality

The case for net neutrality and William K. Black on bank reform.

February 09 2010

02mydafsoup-01
Older posts are this way If this message doesn't go away, click anywhere on the page to continue loading posts.
Could not load more posts
Maybe Soup is currently being updated? I'll try again automatically in a few seconds...
Just a second, loading more posts...
You've reached the end.

Don't be the product, buy the product!

Schweinderl