Don’t Count Xamarin Out

In the quest to build mobile apps with one code base, Xamarin just might be an unexpected underdog…

Photo by Vojtech Bruzek on Unsplash

I don’t think it’s any secret that I love C#. It’s easy on the eyes, allows for fast development, robust, has built-in support for asynchronous programming, and so much more. When I need to build a scalable, robust back-end, C# and .NET are my go-to.

I can’t say I share the same love for using it on the front-end. Razor pages do not provide the same flexibility and functionality that a Javascript framework like React or Angular provides. I do believe this is changing, especially after watching .NET Conf this year and them showing off all the new features they are adding, but for now, Razor pages are still not my cup of tea. I still have yet to try out Blazor, which is supposed to provide way more functionality than Razor being used in MVC or MVVM projects.

The question now becomes “What about mobile apps”? C# is fantastic on the backend and making large improvements on web apps, but what about C# in the mobile space? You may have heard of a tool called Xamarin, which allows you to build mobile applications for Android, macOS, and iOS using C#. Xamarin was always a little bit offputting to me. It’s not as widely used as Flutter or React Native nor is it as well known. After listening to .NET Conf, a .NET Rocks podcast, and going through some videos on the Xamarin Developers YouTube channel, my interest finally peaked, and decided to try it out. While not as accessible as Flutter and React Native yet, I was thoroughly impressed with what I saw and if the Xamarin team can implement what they say they want to, it might just come up from the underdog to a front runner in the mobile world.

Initial Thoughts

Upon creating the project, I saw it actually created three new projects in my solution, one for the forms app, one for iOS, and one for Android. This was a bit jarring to me, especially coming from Flutter and React Native where there was one solution and builds for each OS targeted their own folder within the project. Soon, however, this approach became clear when I began to implement Firebase Authentication. Both projects are treated as native apps for each platform.

When I set up Firebase, there were Nuget packages that are per platform and needed to be installed only on their respective project. The authentication scheme for each was slightly different but did allow me to take advantage of a shared service layer. I created an IAuthenticationService interface that contained three definitions, Login, Logout, and IsLoggedIn. These three methods I then implemented in each solution. The nice thing with this approach is I can reuse my service layer for a web app or desktop app. Having a services project in my solution lets me define what kind of methods I need to what functionality and leave the implementation up to each platform. It also lets me have multiple implementations if need be, and just inject the IAuthenticationService where need be. It puts a lot of power in the hands of the developer.

Sharing Code and Development

The built-in Hot-Reload works really, really lovely. It quickly rebuilds and displays your changes in your emulator. It also rebuilds on the fly when you change your code-behind, something that .NET Core MVC could take a few notes on. The one thing I wish was better that is less of an issue with Xamarin but more with Visual Studio for Mac is the Preview mode was not working for me, so I did not get to test out the drag and drop functionality. However, the shared code between iOS and Android worked well, and binding your UI to your logic is very easy.

One other thing that helps speed up development in .NET is using shared projects that are either .NET 5 or .NET Standard. Xamarin, for now, only targets .NET Standard, which means I can write a project that contains my database objects and use it in my Xamarin app and a web app or wherever else I might need it. This, along with the service layer, really decreases the amount of code needed and decreases any issue of data and data types not lining up as it gets passed from client to server. Being able to access service and data access layers from all my client apps help adhere to Clean Architecture principles and keep my codebase small and reusable.

One other neat tool is that if you are developing for iOS, you are not restricted to development on a Mac, although you still need one. On your Windows machine, you can connect to your Mac from the full-blown Visual Studio and run an emulator on your Windows desktop. So if you are more comfortable developing on Windows, then Xamarin will let you do all your development on Windows.

Current Drawbacks

The other drawback I see is having to generate three separate solutions that need to be edited and have their own packages installed. I understand the reasoning for it and love being able to take advantage of the extremely powerful dependency management system in C#. Having this many projects can be overwhelming however and not as intuitive as only having to work on a single codebase and have it build-out to multiple solutions.

Should you use it?

React Native is really nice because it’s just Javascript. The amount of overhead needed to create web and mobile apps is very little in it, especially if your front-end is already in Javascript. Javascript developers are also super easy to find. Flutter, while being a really cool piece of technology, has a higher learning curve due to it using Dart as it’s language, so a team transitioning from web to mobile may have to take time to learn Dart. It is also my personal opinion that Flutter's syntax is pretty ugly and can be hard to follow. It is also, in my experience, harder to customize the UI on, as it by default has Material Design engrained for its baseline properties.

Xamarin is more like a middle child between cross-platform and native development. You can build your entire stack in C# as you can in React and Javascript. C# is also way more accessible than Dart while still providing things like type safety. It also compiles down to native apps, so you do see a performance gain over the Javascript apps. But, like Native apps, it has a separation of back-end code and front-end UI markup. This creates some bloat and might not be as intuitive as having your backend interact directly with your UI in your .js or .dart files.

So using it then is going to be a choice of what your team is comfortable with. If you are using a .NET/C# stack, I don’t see a reason not to right now. If you are using a mix of .NET and Javascript, then you could go either way. A more Javascript oriented team might want to use React Native. With this in mind, however, Xamarin will continue to grow and become more integrated into the .NET ecosystem. As it does, the more code you can share between all your layers of your applications.

As .NET continues to grow and become more powerful, I believe Xamarin will have a much wider appeal. As its kinks start being ironed out and it becomes more integrated into the .NET platform, Xamarin will start becoming a more popular choice for mobile development.

There isn’t a better time than now to pick up .NET!

The Startup

Get smarter at building your thing. Join The Startup’s +800K followers.

Brock Joseph Herion

Written by

I am a software developer who love coding in Python, Javascript, and C#. I am a sucker for learning new technologies and tooling to make development easier.

The Startup

Get smarter at building your thing. Follow to join The Startup’s +8 million monthly readers & +800K followers.

Brock Joseph Herion

Written by

I am a software developer who love coding in Python, Javascript, and C#. I am a sucker for learning new technologies and tooling to make development easier.

The Startup

Get smarter at building your thing. Follow to join The Startup’s +8 million monthly readers & +800K followers.

Medium is an open platform where 170 million readers come to find insightful and dynamic thinking. Here, expert and undiscovered voices alike dive into the heart of any topic and bring new ideas to the surface. Learn more

Follow the writers, publications, and topics that matter to you, and you’ll see them on your homepage and in your inbox. Explore

If you have a story to tell, knowledge to share, or a perspective to offer — welcome home. It’s easy and free to post your thinking on any topic. Write on Medium

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store