I do not work with Xamarin (yet) so I can not talk about the experience, and to not have to rely on that zé mané like me, I've been researching about it.
I found a Miguel de Icaza article , the creator of Xamarin. He recommends the use of Shared in contrast to Jason Smith who prefers PCL.
I found it interesting because he validated something I always thought. With partial
we do not always need to use #ifdef
.
Looks like opinion, and even is. In fact, if the two forms exist, they serve different situations and different tastes. I stay with Miguel, not because he's the bambambam of the thing, but because it makes more sense to me. Let's see
PCL
- The same code can be used for various platforms
- All maintenance affects all platforms in a unique way, no need to replicate
- The executable can be shared between different projects
- Allows the application to be dynamically pluggable
But
- Only one subset of .NET is available
- The application can only use the most basic parts that can work evenly on all supported platforms.
- You will not always have the best user experience
- The code tends to become complex in order to make it work well on all platforms
Shared
- It's easy to share the code with several projects and some parts of the code can work on all platforms
- You can use compilation directives or
partial
to compile the parts of each platform
- The code tends to be simpler
- The application works as expected on that platform and uses whatever is available on it
But
- Must generate a monolithic executable and can not share with other applications
- Most, but not all, development should be done for each platform, which leads to some duplication
- Maintenance has to be done on each platform code
- The application is what it is, if you want to improve it with something extra, you do not have the option to do this dynamically, you have to generate another application
Obviously, if you do not need more than one platform it makes it easier to choose, since you do not have to share anything.
PCL can be more useful if you need to make cross-platform applications quickly and cheaply even if the result is not so good. It is also interesting if it will be common for the user to have several different applications with the same base running on their device.
Shared is more interesting if you want the best possible result on each platform and the application will generally be unique with that base.
More can be read at Xamarin.Forms Portable or Xamarin.Forms Shared