Cross platform development
with C#
By Michele Scandura
Michele Scandura

Senior Software Developer at Compass Informatics (www.compass.ie)


EMAIL
michele.scandura@outlook.com


TWITTER
@mikescandy




BLOG
???
But… HTML5?

“I think the biggest mistake that we made as a company is
     betting too much on HTML5 as opposed to native”
                (Mark Zuckerberg, Sept. 2012)

 HTML5 is indeed a great technology and is here to stay
 Promise: write once, run everywhere
 JavaScript engines are getting faster, and you can use JavaScript
  on client and server
 But…
But… HTML5?


 You have to program in JavaScript 
 Write once, deploy everywhere not 100% true
 UI paradigms are different on each platform
 No access to native libraries
But… HTML5?




     iOS      Android   Windows Phone
C# as a multiplatform alternative

                                   Plus a few nice additions
 Mono makes it possible to run
  C# code on the most                Playstation Mobile (PS VITA)
  widespread platforms               The Unity 3d Engine uses C# as a
   All Windows variants              scripting language (and Unity runs
                                      on Wii and WiiU, PS3, XBOX, Flash)
   Linux
                                     PS4 will definitely run C# code
   OSX
                                     BSD, Solaris, Wii, PS3
   iOS
                                     CPU architecture is not an issue:
   Android                           x86, x64, IA64, PowerPC, SPARC,
                                      ARM…
Advantages in using C#

 Linq / Lamda, Parallel Linq, Tasks
 Memory management (no pointers, but leaks are still a problem)
 Strongly typed implicit variable declaration
 Extension methods
 Strongly typed
 Generics
 WCF
 Async/await
 (This applies only if using Visual Studio) ReSharper
C# as a multiplatform alternative



 “Between Windows, iOS and Android, your C# code can
             run on over 2.2 billion devices”
       Nat Friedman (CEO of Xamarin, Jan 2013)
Introducing Xamarin

 Newly released tools: Xamarin Studio,
  Xamarin.Android and Xamarin.iOS (formerly
  Mono for Android and MonoTouch
 Provide full access to platform SDK
 100% native
 Faster than native! (Mono vs. Dalvik,
  xobotos)
 Always in sync with native SDKs
 (iOS 6.1 released 28/1, MonoTouch update
 released the next day)
Reusable code


 Most non-UI code can be shared across platforms
   Core logic
   Entities, messages, interfaces
   Linq
   Network access


 File / Database access might be tricky
Reusable code: how to


 File linking
 Abstraction
 Observer pattern
 Partial classes
 Conditional compilation
 Portable class libraries
Useful C# libraries

 TinyIoC / TinyMessenger
 WaveEngine
 MonoGame (XNA)            We have IoC containers,
 EmguCv (open CV)          MVVM, 2D and 3D game
 NetTopologySuite          engines, ORM, Image
 MVVMCross                 processing library, Logging,
                            Web services, GIS tools…
 SQLite-Net
 ServiceStack
 Log4Net
 Many more
And native too


 Google Maps API V2
 Flurry
 OxyPlot.2DGraphLib
 Chipmunk Physics
 And many more
Tips and tricks


 Developing for iOS requires a Mac
 Emulators are good but:
     iOS provides an x86 simulator
     Android provides both ARM and x86 emulators
 iOS deployment still requires the usual certificates and some Xcode
 Memory leaks
 Git support in TFS / Xamarin Studio
Demo time (sort of!)
Conclusions


 It all sounds great, isn’t it?
 Sometimes is not straightforward as it seems
 Relying on semi-closed platform
 Specific platform knowledge is still a must: get ready to learn some
  Java and objective-c
 Mobile is not only coding, UI and UX are crucial for a successful app
Some links

Apache Cordova - http://cordova.apache.org/
Xamarin - http://xamarin.com/
iOS Dev Center - https://developer.apple.com/devcenter/ios/index.action
Android Developer - http://developer.android.com/index.html
Xamarin on GitHub - https://github.com/xamarin
The Mono Project - http://www.mono-project.com/Main_Page
TinyIoC - https://github.com/grumpydev/TinyIoC
TinyMessenger - https://github.com/grumpydev/TinyMessenger
WaveEngine - http://www.waveengine.net/
MonoGame (XNA) - http://monogame.net/
EmguCv (open CV) - http://www.emgu.com/wiki/index.php/Main_Page
NetTopologySuite - http://code.google.com/p/nettopologysuite/
MVVMCross - https://github.com/slodge/MvvmCross
SQLite-Net - https://github.com/praeclarum/sqlite-net
ServiceStack - http://www.servicestack.net/
Xamarin.iOS Bindings - https://github.com/mono/monotouch-bindings
OxyPlot.2DGraphLib - https://github.com/Emasoft/OxyPlot.2DGraphLib.MonoTouch
ShinobiControls - http://blog.xamarin.com/shinobicontrols-joins-the-xamarin-component-store-and-
evolve-speaker-lineup/

Cross platform development with C#

  • 1.
    Cross platform development withC# By Michele Scandura
  • 2.
    Michele Scandura Senior SoftwareDeveloper at Compass Informatics (www.compass.ie) EMAIL michele.scandura@outlook.com TWITTER @mikescandy BLOG ???
  • 3.
    But… HTML5? “I thinkthe biggest mistake that we made as a company is betting too much on HTML5 as opposed to native” (Mark Zuckerberg, Sept. 2012)  HTML5 is indeed a great technology and is here to stay  Promise: write once, run everywhere  JavaScript engines are getting faster, and you can use JavaScript on client and server  But…
  • 4.
    But… HTML5?  Youhave to program in JavaScript   Write once, deploy everywhere not 100% true  UI paradigms are different on each platform  No access to native libraries
  • 5.
    But… HTML5? iOS Android Windows Phone
  • 6.
    C# as amultiplatform alternative  Plus a few nice additions  Mono makes it possible to run C# code on the most Playstation Mobile (PS VITA) widespread platforms The Unity 3d Engine uses C# as a All Windows variants scripting language (and Unity runs on Wii and WiiU, PS3, XBOX, Flash) Linux PS4 will definitely run C# code OSX BSD, Solaris, Wii, PS3 iOS CPU architecture is not an issue: Android x86, x64, IA64, PowerPC, SPARC, ARM…
  • 7.
    Advantages in usingC#  Linq / Lamda, Parallel Linq, Tasks  Memory management (no pointers, but leaks are still a problem)  Strongly typed implicit variable declaration  Extension methods  Strongly typed  Generics  WCF  Async/await  (This applies only if using Visual Studio) ReSharper
  • 8.
    C# as amultiplatform alternative “Between Windows, iOS and Android, your C# code can run on over 2.2 billion devices” Nat Friedman (CEO of Xamarin, Jan 2013)
  • 9.
    Introducing Xamarin  Newlyreleased tools: Xamarin Studio, Xamarin.Android and Xamarin.iOS (formerly Mono for Android and MonoTouch  Provide full access to platform SDK  100% native  Faster than native! (Mono vs. Dalvik, xobotos)  Always in sync with native SDKs  (iOS 6.1 released 28/1, MonoTouch update released the next day)
  • 10.
    Reusable code  Mostnon-UI code can be shared across platforms Core logic Entities, messages, interfaces Linq Network access  File / Database access might be tricky
  • 11.
    Reusable code: howto  File linking  Abstraction  Observer pattern  Partial classes  Conditional compilation  Portable class libraries
  • 12.
    Useful C# libraries TinyIoC / TinyMessenger  WaveEngine  MonoGame (XNA) We have IoC containers,  EmguCv (open CV) MVVM, 2D and 3D game  NetTopologySuite engines, ORM, Image  MVVMCross processing library, Logging, Web services, GIS tools…  SQLite-Net  ServiceStack  Log4Net  Many more
  • 13.
    And native too Google Maps API V2  Flurry  OxyPlot.2DGraphLib  Chipmunk Physics  And many more
  • 14.
    Tips and tricks Developing for iOS requires a Mac  Emulators are good but:  iOS provides an x86 simulator  Android provides both ARM and x86 emulators  iOS deployment still requires the usual certificates and some Xcode  Memory leaks  Git support in TFS / Xamarin Studio
  • 15.
  • 16.
    Conclusions  It allsounds great, isn’t it?  Sometimes is not straightforward as it seems  Relying on semi-closed platform  Specific platform knowledge is still a must: get ready to learn some Java and objective-c  Mobile is not only coding, UI and UX are crucial for a successful app
  • 17.
    Some links Apache Cordova- http://cordova.apache.org/ Xamarin - http://xamarin.com/ iOS Dev Center - https://developer.apple.com/devcenter/ios/index.action Android Developer - http://developer.android.com/index.html Xamarin on GitHub - https://github.com/xamarin The Mono Project - http://www.mono-project.com/Main_Page TinyIoC - https://github.com/grumpydev/TinyIoC TinyMessenger - https://github.com/grumpydev/TinyMessenger WaveEngine - http://www.waveengine.net/ MonoGame (XNA) - http://monogame.net/ EmguCv (open CV) - http://www.emgu.com/wiki/index.php/Main_Page NetTopologySuite - http://code.google.com/p/nettopologysuite/ MVVMCross - https://github.com/slodge/MvvmCross SQLite-Net - https://github.com/praeclarum/sqlite-net ServiceStack - http://www.servicestack.net/ Xamarin.iOS Bindings - https://github.com/mono/monotouch-bindings OxyPlot.2DGraphLib - https://github.com/Emasoft/OxyPlot.2DGraphLib.MonoTouch ShinobiControls - http://blog.xamarin.com/shinobicontrols-joins-the-xamarin-component-store-and- evolve-speaker-lineup/