46

I'd consider myself pretty well versed in C#. It's my language of choice at the moment, and it's where basically all my professional experience lies.

Still, I'm puzzled by the existence of the MonoDroid project. My understanding has always been that C# and Java are very close. Like, if you know one, you can learn the other really quickly. So, as I've considered developing my first Android app, I just assumed I would familiarize myself with Java enough to get started and then just sort of learn as I go.

Wouldn't this make more sense than using MonoDroid, which is likely to be less feature-rich than the Java Android SDK, and requires learning its own API (albeit a .NET API) anyway? I just feel like it would be better to learn a new language (and an extremely popular one at that) and get some experience in it—when it's so close to what you already know anyway—rather than stick with a technology you're experienced with, without gaining any more valuable skills.

Maybe I'm grossly misrepresenting the average potential MonoDroid user. Maybe it's more for people who are experienced in Java and .NET and just prefer .NET. Or maybe (in fact it's likely) there are other factors I just haven't considered. I'm just wondering, why would you use MonoDroid instead of just developing for Android using Java?

Dan Tao
  • 1,201
  • 2
  • 10
  • 16

5 Answers5

55

Any competent C# programmer should be able to quickly pick up enough Java to write an Android program, but that's not the point. It's a matter of code reuse.

Think about six months from now, when your Android program is popular and your users are asking for a version for iPhone and Windows Phone 7. If you had used MonoDroid, you can reuse most of your application logic with MonoTouch (Mono for iOS) and the Windows Phone SDK. Now they want a web-based version, so you include the same class libraries in an ASP.Net project. Desktop versions? No problem, that same class library works with .Net under Windows or Mono on Linux and OS X.

Other than C or C++, I can't think of any other languages that would let you reuse the same code on all of those targets.

Edit to address some concerns in the comments: .Net and Mono will not let you write a complete program and use that same program everywhere. They will let you share some code, and like all cross-platform programming the amount of shared code depends on the type of programs you're writing and how well you separate the UI and hardware code from the application logic.

However, if you write your Android app in Java, how much of that is reusable on iOS or Windows Phone? That's the point I was trying to make. I had existing C# libraries that were working on Mono for Android in much less time than it would have taken to reimplement them, even though I already knew Java. I have some code that is shared--unmodified--between a web site, desktop programs, and mobile apps on two different mobile platforms, thanks to Mono.

I didn't mean to imply, even indirectly, that Mono was the perfect tool for every mobile development situation. It's a tradeoff, but I firmly believe that there are situations when Mono is a much better choice.

Please see (and upvote!) Jason S's answer for another perspective.

Kevin
  • 666
18

This is a kind of supplementary answer, since one thing that seems to have been overlooked in answers so far, concerns what is actually cross-platform. According to Xamarin themselves that is basically your business logic, not your UI or any hardware control such as GPS, audio, address book and so on. Those will have to be written specifically for each platform. See their FAQ entry I have a MonoTouch or WindowsPhone 7 application, can I just rebuild it with Mono for Android and target Android?.

Using Mono, you can write your UI and phone control code using C# but it will not be portable to any platform. You will have to write the UI and phone control for each platform, even though you can write it in C#. Either way, you will still have to learn the specifics of UI controls on Android and how Android handles phone resources.

Using Mono, you'll have to learn the Mono API, that calls into the Android API. You'll also have to wait for Mono to implement new Android features and hope they implement all Android features. Even if C# is more powerful than Java, you'll not be able to do more than if you use the Android SDK directly (in Java).

If you're going straight from C# to Android, since C# is so syntactically similar to Java, then most of a C# developer's learning for Android will be learning the Android API.

Some considerations...

C# to Android

Need to Learn

  • Android API
  • Java API : String, Calendar and event handling etc.

Don't need to learn

  • Java syntax : C# is very similar syntax.

Other considerations

  • You won't be able to reuse code across platforms.
  • You won't have any dependencies between you and the Android SDK. You will get new Android features as they are released.
  • You will likely have greater support and examples for Android code than Mono.

C# to Mono

Need to Learn

  • Android : You still need to learn Android's UI and hardware control features.
  • Mono API : You have to learn how to call Mono's API to do stuff with Android's UI and hardware.

Don't need to learn

  • Java API and syntax : You can develop in C#

Other considerations

  • Reuse code : You can re-use C# code that is devoid of any UI or hardware control code and so is pure "business logic". Although ideal, having such a clean separation is not always easy. You will have to evaluate how much of your code will not have any UI or hardware control.
  • Dependencies : You are dependent on Mono implementing the Android API. There may be some lag from Android API releases or some Android features may never be implemented.
  • You may have less documentation and examples to choose from.
Jason S
  • 289
13

I think a lot of it has to do with the resources that are available.

The syntax in C# and Java may be similar, but they offer very different things. For example, working with dates using standard Java libraries is a nightmare, while in C# it's quite pleasant.

Corey
  • 1,822
9

It looks like a great opportunity for learning a new language, which I don't think you should pass up.

Going from C# to Java is a breeze as they are based on the same concepts. Java is like a subset of C#, so you'll have to unlearn some stuff (like properties and assemblies) and getting used to a some new conventions, but mostly it should be a no-brainer.

3

Quick history lesson -- MonoDroid grew up out of MonoTouch. Made alot of sense at the time. Unfortunately, Novell got sold and the whole Mono team was laid off. Good news is that Miguel de Icaza secured funding and has started a new outfit to rebuild what was MonoTouch/MonoDroid. So you are kind of in limbo until they really launch.

July 2011 Update: Miguel's outfit has regained rights to the whole Mono* stack. Get it while it's hawt.

Wyatt Barnett
  • 20,787