Lo scorso anno abbiamo iniziato ad esplorare MonoTouch come strumento per lo sviluppo di applicazioni Line of Business (LOB) su iPad ed iPhone, tenendo in particolare considerazione la possibilità di far girare gran parte del codice, in particolare la logica di business, su altre piattaforme (mobile, ma anche desktop e server).
Ad un anno di distanza possiamo fare un resoconto dell'esperienza (ancora in corso) avuta con questo tool, vedendo alcune ricette pratiche che consentano di utilizzarlo in modo più efficiente e discutendo insieme su quando ha effettivamente senso sceglierlo, evitarlo o addirittura affiancarlo rispetto ad altri strumenti e tecnologie, tra cui ovviamente quelli basati su HTML5.
3. Conosciamoci un po’
• Hai seguito la sessione di 1 anno fa?
• Hai usato MonoTouch in produzione?
• Conosci MonoTouch?
3
3
4. Chi sono?
• Dev / SEng @ KILOG Srl
‣ Da Palm OS a iPad, passando per Windows CE / Mobile
(C++, .NET CF) - 10 anni sul mobile!
• Communities
‣ DotNetMarche, XPUG Marche, TechBar
• Contatti
‣ steott@gmail.com
‣ @ste8
4
‣ blogs.ugidotnet.org/ste8
4
9. Cosa devo sviluppare? (1/4)
• Line of Business Applications (LoB)
Online e soprattutto OFFLINE
• Sales Force Automation, CRM,
assistenze tecniche, ...
• Ciclo di vita: medio / lungo
• Porting / Reengineering di app
esistenti (WM6, netbook, ...)
9
9
11. Cosa devo sviluppare? (3/4)
• Device:iPhone e iPad come riferimenti
‣ ma ci sono anche Android, WP7, netbook
• UX usabile e attraente!
11
11
12. Cosa devo sviluppare? (4/4)
• Performante
‣ L’exe non deve essere per forza piccolo
• Controllo sul deploy dell’app
• Ridurre potenziali problemi x sviluppo
‣ No puntatori & rilascio memoria
12
12
14. Che strumenti abbiamo? (1/2)
• Objective-C (nativo per iOS)
‣ learning curve ulteriore x il linguaggio
‣ target: “solo” iPhone, iPad, Mac OS X
• Java (nativo per Android)
‣ minore learning curve x il linguaggio
‣ target: dove gira Java (no iOS)
14
14
15. Che strumenti abbiamo? (2/2)
• HTML 5 + JavaScript
‣ “Pure Web” (jQuery Mobile, ...)
‣ “Native Wrapper” (PhoneGap)
• “Write Once Run Anywhere”
‣ es. Titanium Appcelerator
• ”Cross-platform Core”
‣ es. MonoTouch & Mono for Android
15
Fonte: http://www.agiledossier.com/doyouwanttocreatamobileapp
15
16. Con la diffusione di HTML5 e js...
pazzi?
Ma si am
aga zzi!
Oh r
ok, ma fare tutto in HTML5/JS è
come fare cibo vegerariano perchè
così lo mangiano (quasi) tutti
16
(cit. @alexbream)
16
18. La UI va rifatta...o no? (1/5)
Esempio MIX11 App
http://tinyurl.com/442vt3t
iPhone
18
18
19. La UI va rifatta...o no? (2/5)
Esempio MIX11 App
http://tinyurl.com/442vt3t
WP7
19
19
20. La UI va rifatta...o no? (3/5)
Esempio MIX11 App
http://tinyurl.com/442vt3t
Android
20
20
21. La UI va rifatta...o no? (4/5)
Ipse dixit: Martin Fowler
http://martinfowler.com/bliki/CrossPlatformMobile.html
To summarize:
• Don't use cross-platform toolkits
• For maximum reach: built a web app that looks
like web app
• To appeal to a particular platform: build a native
app 21 that platform, with a experience design
for
based on that platforms interaction style
21
22. La UI va rifatta...o no? (5/5)
... ma almeno riutilizziamo la logica
di business e di accesso dati...
... soprattutto in app offline!
Riscrivere il codice in linguaggi
diversi per ogni piattaforma è
22
molto costoso!
22
23. Quando usare
“Cross-platform Core” approach
If your application will contain a
significant amount of business
logic or will have lots of back-end
service interatactions (rather than
being focussing mostly on
presentation logic) but you still
want a very native feel then a
Cross-Platform Core may be the best
way to go.
23
23
24. Side effect del
“Cross-platform Core” approach
• nicely layered architecture
• non-presentation logic which is easy
to get under solid test coverage
24 Fonte: http://www.agiledossier.com/doyouwanttocreatamobileapp
24
26. Cos’è MonoTouch? (1/3)
• Come Mono... ma diverso!
‣ Suite per portare C# e .NET su iPhone!
• Alcune limitazioni da ambiente Apple
‣ Usa compilazione statica (AOT, Ahead of
Time) invece che a runtime (JIT)
• http://www.mono-project.com/AOT
‣ No generazione codice
• Reflection.Emit, Dynamic, ... =>
26
Attenzione! Usati da molti ORM ‘light’
26
28. Cos’è MonoTouch? (3/3)
• Thin layer sopra le API native
‣ rapidità di aggiornamento all’iOS SDK
‣ binding x utilizzo librerie Objective-C
‣ learning curve: conoscere le basi
dell’ambiente nativo
– Oltre alle HIG (Human Interface Guidelines)
– Infrastruttura (view controllers, ...)
– saper almeno leggere Objective-C
28
• Prezzo:pro o contro?
28
29. Soddisfa i miei bisogni? (1/3)
• App LOB (Line of Business)
‣ Online e soprattutto OFFLINE
✴Si... e fa molto altro!
• Device:iPhone e iPad come riferimenti
‣ ma ci sono anche Android, WP7, netbook
✴Posso condividere BIZ e DAL!
29
29
30. Soddisfa i miei bisogni? (2/3)
• UX usabile e attraente!
✴Stesse possibilità di Objective-C (IB)
• Performante
‣ L’exe non deve essere per forza piccolo
✴Compilazione “nativa”, LLVM compiler
✴iCircuit test: http://news.ycombinator.com/item?id=2557047
• Controllo sul deploy dell’app
30
✴Stesse possibilità di Objective-C!
30
31. Soddisfa i miei bisogni? (3/3)
• Ridurre potenziali problemi x sviluppo
‣ No puntatori & rilascio memoria
✴C# e Garbage Collector => No puntatori!
✴Non è tutto oro...attenti ai memory leak!
✴Ora è fornito anche un profiler
31
31
33. 1 anno fa...
Quale sarà il futuro di MT?
No P anic
Can
we
conDnue
working
with
MonoTouch?
All
technology
roadmaps
remain
intact
You
should,
yes.
It
will
be
compaDble.
33
33
34. Xamarin oggi (1/5)
• > 30 persone (di cui circa 20 del
team Mono)
• Diverse posizioni aperte (Developer
Evangelist/Advocate, Mobile Dev, ...)
• “We have competitive salary and
benefits. We’re growing fast and are
cash-flow positive”
34
34
35. Xamarin oggi (2/5)
• Numerosi rilasci
(es. MonoTouch dalla 4.0.4.1 di Luglio alla 5.3.*)
• Compatibile in ~ 24 h dal rilascio di
SDK Apple e Android
• Mailing list abbastanza frequentata
35
35
36. Xamarin oggi (3/5)
• “Our main products are Mono on iOS
and Mono on Android.” ...
• ... e molti altri progetti
‣ http://tirania.org/blog/archive/2011/Dec-21.html
‣ Mono, Sony PSSuite, Google Native Client, Compiler as a
Service, Unity3D, MonoGame, MonoDevelop,
XobotOS ...
36
36
37. Xamarin oggi (4/5)
• Xamarin Identified as a Leader in Mobile
Cross-Platform Application Development
Tools
37 Fonte: http://www.visionmobile.com/blog/2012/02/crossplatformtools/
37
38. Xamarin oggi (5/5)
38
Fonte: http://www.visionmobile.com/blog/2012/02/crossplatformtools/
38
39. Risorse per iniziare
• 2 Video da NDC 2010
‣ http://tekpub.com/conferences/ndc2010
• Stack Overflow / Mailing List
• Esempi: galleria su xamarin.com
• Libri
39
39
41. Ingredienti per iniziare
• Un computer Mac con Mac OS X
• iPhone SDK
• MonoTouch (+ Mono)
– Simulator only (free), studenti (99$),
Professional (399$), Enterprise (999$)
• MonoDevelop
41
41
42. Configurazione ambiente
• Boot Camp + Parallels =
stessa (ma unica) partizione Windows
• Shortcuts per
‣ Mac OS X
‣ Windows da Parallels
‣ MonoDevelop
42
42
43. Visual Studio come IDE (1/2)
• Perchè vorrei farlo?
‣ IDE migliore / Resharper, ...
• Si può fare! (cit)
‣ o quasi.... solo build, NO RUN
• Non solo per progetti BIZ e DAL,
anche per UI
43
43
44. Visual Studio come IDE (2/2)
• Soluzione funzionante:
‣ https://github.com/follesoe/VSMonoTouch
‣ (anche su nuget)
44
44
45. Architettura
• “Progetto” Server (Web API, IIS)
• “Progetto” Client (iPad)
• Biz e DAL in comune
• Tool ‘home made’ per sincronizzare i
progetti
45
45
46. UI Patterns
• No Data Binding :(
• MVP e Presentation Model
‣ http://martinfowler.com/eaaDev/PresentationModel.html
‣ http://martinfowler.com/eaaDev/SupervisingPresenter.html
• Soluzioni ‘MVVM’
‣ MonoCross, MvvmCross
‣ ATTENZIONE: Future direction (Under
consideration): More tablet support - for iPad, for
46
Windows Metro and for Android
46
47. UI: XCode vs Codice
• Approcci DSL (Domain Specific Language)
‣ iCircuit:
http://praeclarum.org/post/1520024382/interfaces-
caches-cross-platform
‣ Post Antonio Ganci:
http://blogs.ugidotnet.org/AntonioGanci/archive/
2010/04/19/un-approccio-per-ottenere-una-
architettura-malleabile.aspx
47
47
48. Request / Response
Service Layer (1/3)
• Cos’è e perchè ?
‣ http://davybrion.com/blog/2009/11/requestresponse-
service-layer-series/
‣ http://davybrion.github.com/Agatha/
‣ Video workshop DotNetMarche:
• https://vimeo.com/album/1490635/video/17700408
• https://vimeo.com/album/1490635/video/18120319
48
48
52. Data Access Layer (1/3)
• TransactionScope è supportato
‣ Utile per Request / Response SL
• Sqlite su iPad, Sql Server sul server
• No Core Data
• ORM o no? (es. Vici CoolStorage o altri
‘light’ per Sqlite)
52
52
53. DAL: Sqlite (2/3)
• Supporta subset query DDL!
‣ ALTER TABLE, DROP COLUMN, ...
‣ Attenti ai generatori di script!
• Molto lasco sui tipi di dati!!
‣ Lunghezza stringhe?
‣ Valori decimal?
‣ DateTime salvati come stringhe!
53
53
54. DAL: Performance Tips (3/3)
• DataReader via GetString, GetInt, ..
http://www.bayshield.com/2010/6/29/monotouch-sqlite-performance-tip
• Uso di transazioni e connection
pooling
• Quantificazione costi reflection (se
usata)
http://praeclarum.org/post/1572668275/quantifying-reflections-slowdown-in-sqlite-net
54
54
55. Accesso ai dati remoti
• ASMX Web Service e WCF
come in Silverlight
• REST via HttpRequest / Response
• JSON
‣ https://github.com/chrisntr/Newtonsoft.Json
55
55
57. DDD è un buon amico (1/3)
• Domain Driven Design: si può fare!
• Entity, Value Object, Repository...
chissené....
57
57
58. DDD è un buon amico (2/3)
• Applicabile anche a “rich” UI
• Task Based UI
‣ “It is possible to bring forward the
intention of the user; this will allow the
Application Server to process behaviors
as opposed to saving data”
‣ http://cqrs.wordpress.com/documents/task-based-ui/
58
58
59. DDD è un buon amico (3/3)
• Separare il comportamento dai dati
• Capire che entità state trattando
‣ Una fattura è la stessa fattura per tutti?
‣ Bounded Context
‣ Mandare il vostro DBA nei matti in tre semplici mosse
https://vimeo.com/31739391
• Command Handler di CQRS
59
(vedi Request Response Service Layer)
59
60. IoC / DI
• Diverse librerie
‣ TinyIoC (funziona :)
‣ OpenNETCF.IoC, Funq, PicoContainer
‣ http://monotouch.info/Tags/IoC
60
60
62. Testing (Unit, Integration)(2/2)
• Testare la business logic / DAL
• Testare l’”MVC” Apple:
‣ Supervisor Controller
http://ben.phegan.name/index.php/2011/02/28/
monotouch-and-unit-testing/
62
62
63. Alcune librerie di supporto (1/3)
• MonoTouch.Dialog
‣ https://github.com/migueldeicaza/MonoTouch.Dialog
‣ ATTENZIONE su iPad (se UITableViewController non full-screen)
63
63
64. Alcune librerie di supporto (2/3)
• Framework per MVVM
• MonoCross
‣ http://code.google.com/p/monocross/
• MvvmCross
‣ https://github.com/slodge/MvvmCross
‣ ATTENZIONE: Future direction (Under consideration): More tablet
support - for iPad, for Windows Metro and for Android
64
64
65. Alcune librerie di supporto (3/3)
• ReactiveUX per MonoTouch
‣ http://code.google.com/p/proactive-framework/
• Localizzazione
‣ https://github.com/rdio/vernacular
• Event Aggregator (Message Broker)
‣ http://merbla.blogspot.com/2011/03/monotouch-and-eventaggregator.html
• Xamarin Mobile API
65
65
66. Alcuni tool di supporto
• Workspace Reloader
‣ http://bit.ly/JM3FZe
• SourceTree
‣ http://www.sourcetreeapp.com/
66
66
68. Troubleshooting (1/2)
• Eccezioni compilatore AOT
‣ specialmente con LINQ
• Encoding non unicode dei caratteri
• Qualche problema con MonoDevelop
in full-screen
68
68
69. Troubleshooting (2/2)
• Attenzione ai Trampolini!
‣ Ran out of trampolines of type 0,1,2
http://docs.xamarin.com/ios/troubleshooting#Ran_out_of_trampolines_of_type_0
‣ Understanding the impact
http://monotouch.2284126.n4.nabble.com/Understanding-the-impact-of-trampolines-td4495086.html
69
69
71. Cosa è possibile fare a
questo punto...
• Riutilizzo di Biz e Dal in servizi
esposti sul web
• Creazione di client in qualsiasi
tecnologia su questi servizi
71
71