Impressions of Xamarin.Forms After Some Coding

Kürşat Duygulu
Commencis
Published in
5 min readJan 31, 2017

Mobile application development became the trend after the first iPhone was announced on January 2007; and as of January 2017, it is still one of the fastest-growing industries. Every day hundreds of applications take their place in stores and every day some of them make their owners rich and happy.

As a company operating in a competitive market, you need to listen to your customers’ needs and react to those needs before your competitors do. If you need to develop a mobile application, you need to be quick. Moreover, you need to develop your application for at least two platforms, iOS and Android, which means separate developers/development teams, different programming languages/technologies, and almost zero code sharing. Therefore, native application development is getting more and more threatened by cross-platform application solutions as they get mature, since cross-platforms solutions offer one common technology/programming language, one development team and less effort, which means lower cost.

Cross-platform mobile solutions include HTML-based hybrid application frameworks and native cross-platform frameworks. The former is actually boxing web pages into an application with limited device features, while the latter is converted to native application codes and has almost the same performance as native applications. Cordova, Ionic are some examples of hybrid application frameworks, whereas Xamarin, React-Native and NativeScript are examples of native cross-platform application frameworks.

For native cross-platform application development, Xamarin has the advantage over others with Universal Windows Platform (UWP) support. Founded in 2011 and acquired by Microsoft in 2016, Xamarin platform offers development for iOS, Android and UWP with C#.

Xamarin.Forms is a specialized solution offered by Xamarin, which provides having the same UI code for all platforms. If your application does not depend heavily on platform-specific features, and it does not have a complicated UI design, then Xamarin.Forms may be the perfect match for you.

Xamarin.Forms architecture (source: Xamarin Blog)

We have developed a fully-functional mobile banking application using Xamarin.Forms in just 4 months, and our client was satisfied with the results. Development is easy if you obey the rules of the framework, but sometimes it can give you headaches. Most of the time we enjoyed the framework, there were times when we developed pages in minutes, but also there were times when we struggled to change a single property of a component and wasted several hours. Hence I will try to point out the pros and cons of Xamarin.Forms after this development period.

Pros of Xamarin.Forms

  • Shared logic, shared UI: The most powerful feature of Xamarin.Forms is shared code for all platforms, including both business logic and the UI. Most of the code is written on Portable Class Library (PCL) projects, and you usually do not care about the native components of each platform. Moreover, starting from Xamarin.Forms version 2.3.3, you can define platform-specific native components on your shared UI declarations. In our project, over 90% of our code resides on the PCL. Therefore, if your project does not require a complicated UI design, total development effort will be dramatically lower when you choose Xamarin.Forms over native development for each platform.
  • C# and .NET Environment: As a former ASP.NET developer, this is the part I like the most. C# is a beautiful programming language, and Xamarin supports most of the .NET Framework libraries. Therefore you can use lovely features such as Properties, LINQ, and Lambda Expressions.
  • MVVM Pattern: Model - View - ViewModel (MVVM) pattern helps you to separate the business logic from the UI. You can define your UI, business logic and model separately and then share them across different teams or team members.

Cons

  • Custom Renderers: If you are not familiar with native application development, this will be the most painful part for you. When Xamarin.Forms standard components does not meet your needs, you will need to look for some custom renderers, which include implementing renderer classes for each platform. This is acceptable if your UI design is complicated and you need to change the behaviour of an existing component, but you may be surprised when you need a minor styling change of a component and the only suggested solution is to write a custom renderer for it. Believe me, this happens very frequently.
  • Build Times: When you make a small change on the code, you need to build the entire project again, which takes centuries.
  • Backward Compatibility: Every time you upgrade to a newer Xamarin.Forms version, there is a huge probability of seeing newer compile errors. When we upgraded our project from 2.3.0.107 to 2.3.1.114, we spent 2 days for fixing the compile errors, since signatures of some of Page class members were changed and some 3rd party components did not work. Moreover, things get worse when you decide to upgrade the dependencies of your Android project. Xamarin officially states that one can not simply upgrade the Android project dependencies by selecting the Packages folder and clicking “Update”.
  • Xamarin Studio: Visual Studio is one of the best IDEs in the market. However, this is not the same when you download Xamarin Studio for your MacBook. It crashes randomly, has a poor Previewer, consumes excessive memory and CPU, and does not have Team Foundation Server (TFS) support. Our client uses TFS for source control, and it was embarrassing when we read that Xamarin officially suggests downloading Eclipse and using the TFS Plugin when you need to connect to the TFS. When you work on the Windows environment and edit some code, Visual Studio automatically detects changes and checks out corresponding files. However, you need to explicitly check out each file in Eclipse, make your changes in Xamarin Studio, then return back to Eclipse and check in your changes. If you do not check out your files first, then for every file that is modified without being checked out, Xamarin Studio will torture you with the following annoying alerts:
Xamarin Studio vs read-only files

Conclusion

Xamarin.Forms is a new and fast-growing framework, offers many features of native application development, but has some drawbacks since it is not mature yet. Nevertheless, in spite of these drawbacks, I will still choose Xamarin.Forms over its alternatives for new projects where applicable.

References

https://blog.xamarin.com/meet-xamarin-forms-3-native-uis-1-shared-code-base/

--

--