Diese Präsentation wurde erfolgreich gemeldet.
Wir verwenden Ihre LinkedIn Profilangaben und Informationen zu Ihren Aktivitäten, um Anzeigen zu personalisieren und Ihnen relevantere Inhalte anzuzeigen. Sie können Ihre Anzeigeneinstellungen jederzeit ändern.
Nächste SlideShare
What to Upload to SlideShare
What to Upload to SlideShare
Wird geladen in …3
×
1 von 49

Speed up the mobile development process

0

Teilen

Herunterladen, um offline zu lesen

A presentation for the IoT course at Sapienza university about tools to speed up the development process for your application

Ähnliche Bücher

Kostenlos mit einer 30-tägigen Testversion von Scribd

Alle anzeigen

Ähnliche Hörbücher

Kostenlos mit einer 30-tägigen Testversion von Scribd

Alle anzeigen

Speed up the mobile development process

  1. 1. Speed up the development process Gianluca Capozzi, Gabriele Cervelli, Giorgio De Magistris, Daniele Davoli Giuseppe Capaldi, Leonardo Sarra
  2. 2. Mobile development: different approaches One of the most important aspects required by a developer is the speed with which a mobile application can be developed. There are two main approaches: ● Native application ● Cross platform application
  3. 3. Native application approach Native apps are developed exclusively for a specific platform. These apps are developed in a language compatible with the platform (i.e. Swift and Objective-C for iOS and Java for Android) ● High performance ● Accordance with the design language ● Usually more scalable ● No limitations when it comes to using phone hardware ● Native look and feel for the UI ● Multiple platforms require separate applications ● Higher development costs
  4. 4. Cross-platform approach Cross-platform apps are compatible with multiple platforms. In order to write cross-platform applications for mobile devices there are many frameworks (such as Xamarin and Cordova) and programming languages (Kotlin, JavaScript). ● Faster development ● Lower costs ● Wider audience ● Consistency between platforms ● No native look and feel when a common UI is used ● Some frameworks have a big performance hit ● Some frameworks don’t expose the latest device APIs ● Knowledge of the underlying platform is still required
  5. 5. Faster development by using Kotlin
  6. 6. What is Kotlin? - Open-source programming language developed by JetBrains - Statically typed - Runs on top of the JVM,Javascript and LLVM (Native) - Officially supported language by Android since 2017, Android reference language since May 2019 - Kotlin evolution driven by the Kotlin Foundation (Google + Jetbrains)
  7. 7. Why Kotlin? ● Open-source ● 100% interoperability with Java ● Expressive & concise code with lean syntax ● Enforces null safety ● Easy to learn ● Functional programming features ● Support for MPP (Multi-platform projects) ● Great IDE support (IntelliJ Idea and Android Studio)
  8. 8. Expressive and concise code ● Less boilerplate ● String interpolation ● Default parameter ● Type inference class Person (val name:String, val surname:String, var age:Int, val birthCity :String = "Rome") fun main(args: Array<String>) { val person = Person(name = "Leonardo", surname = "Sarra", age = 22) val person2 = Person("Leonardo", "Sarra", 22,"Rome") println("Name: ${person.name}") println("Age: ${person.age}") println("City: ${person.birthCity}") println("Equals: ${person == person2}") //Returns false (default equals, //different objects) }
  9. 9. Complete Java Interoperability public static void main(String []args) { Person person = new Person("Leonardo","Sarra", 22, "Rome"); System.out.println(String.format("%s %s - %s years old",person.getName(), person.getSurname(),person.getAge())); } class Person (val name:String, val surname:String, var age:Int, val birthCity :String = "Rome") fun main(args: Array<String>) { val person = Person(name = "Leonardo", surname = "Sarra", age = 22) val person2 = Person("Leonardo", "Sarra", 22,"Rome") println("Name: ${person.name}") println("Age: ${person.age}") println("City: ${person.birthCity}") println("Equals: ${person == person2}") //Returns false (default equals, //different objects) }
  10. 10. Less boilerplate: OpenStud as an example Let’s take as an example the Java Student class from the OpenStud Android app and its Kotlin counterpart. The student object contains all student-related information and is made of 23 variables
  11. 11. Student object is made of: import java.time.LocalDate; import java.util.Objects; public class Student { private String socialSecurityNumber; private String firstName; private String lastName; private String birthCity; private String birthPlace; private String courseYear; private String firstEnrollment; private String lastEnrollment; private String departmentName; private String courseName; private String nation; private String email; private String citizenship; private String gender; private String studentStatus; private String studentID; private LocalDate birthDate; private int academicYear; private int academicYearCourse; private int codeCourse; private int typeStudent; private int cfu; private boolean isErasmus; public String getStudentStatus() { return studentStatus; } public void setStudentStatus(String studentStatus) { this.studentStatus = studentStatus; } public String getBirthPlace() { return birthPlace; } public void setBirthPlace(String birthPlace) { this.birthPlace = birthPlace; } public String getCitizenship() { return citizenship; } public void setCitizenship(String citizenship) { this.citizenship = citizenship; } public String getEmail() { return email; } public void setEmail(String email) { this.email = email; } public int getCfu() { return cfu; } public void setCfu(int cfu) { this.cfu = cfu; } public String getSocialSecuritNumber() { return socialSecurityNumber; } public void setSocialSecurityNumber(String CF) { this.socialSecurityNumber = CF; } public String getFirstName() { return firstName; } public void setFirstName(String firstName) { this.firstName = firstName; } public String getLastName() { return lastName; } public void setLastName(String lastName) { this.lastName = lastName; } public LocalDate getBirthDate() { return birthDate; } public void setBirthDate(LocalDate birthDate) { this.birthDate = birthDate; } public String getBirthCity() { return birthCity; } public void setBirthCity(String birthCity) { this.birthCity = birthCity; } public String getCourseYear() { return courseYear; } public void setCourseYear(String courseYear) { this.courseYear = courseYear; } public String getFirstEnrollment() { return firstEnrollment; } public void setFirstEnrollment(String firstEnrollment) { this.firstEnrollment = firstEnrollment; } public String getLastEnrollment() { return lastEnrollment; } public void setLastEnrollment(String lastEnrollment) { this.lastEnrollment = lastEnrollment; } public String getDepartmentName() { return departmentName; } public void setDepartmentName(String departmentName) { this.departmentName = departmentName; } public String getCourseName() { return courseName; } public void setCourseName(String courseName) { this.courseName = courseName; } public String getNation() { return nation; } public void setNation(String nation) { this.nation = nation; } public int getAcademicYear() { return academicYear; } public void setAcademicYear(int academicYear) { this.academicYear = academicYear; } public int getAcademicYearCourse() { return academicYearCourse; } public void setAcademicYearCourse(int academicYearCourse) { this.academicYearCourse = academicYearCourse; } public String getStudentID() { return studentID; } public void setStudentID(String studentID) { this.studentID = studentID; } public int getCodeCourse() { return codeCourse; } public void setCodeCourse(int codeCourse) { this.codeCourse = codeCourse; } public int getTypeStudent() { return typeStudent; } public void setTypeStudent(int typeStudent) { this.typeStudent = typeStudent; } public String getGender() { return gender; } public void setGender(String gender) { this.gender = gender; } public boolean isErasmus() { return isErasmus; } public void setErasmus(boolean erasmus) { isErasmus = erasmus; } public boolean isEnrolled() { return getTypeStudent() != -1; } @Override public String toString() { return "Student{" + "socialSecurityNumber='" + socialSecurityNumber + ''' + ", firstName='" + firstName + ''' + ", lastName='" + lastName + ''' + ", birthDate=" + birthDate + ", birthCity='" + birthCity + ''' + ", birthPlace='" + birthPlace + ''' + ", courseYear='" + courseYear + ''' + ", firstEnrollment='" + firstEnrollment + ''' + ", lastEnrollment='" + lastEnrollment + ''' + ", departmentName='" + departmentName + ''' + ", courseName='" + courseName + ''' + ", nation='" + nation + ''' + ", email='" + email + ''' + ", citizenship='" + citizenship + ''' + ", gender='" + gender + ''' + ", studentStatus='" + studentStatus + ''' + ", academicYear=" + academicYear + ", academicYearCourse=" + academicYearCourse + ", studentID=" + studentID + ", codeCourse=" + codeCourse + ", typeStudent=" + typeStudent + ", cfu=" + cfu + ", isErasmus=" + isErasmus + '}'; } @Override public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; StudentJava student = (StudentJava) o; return academicYear == student.academicYear && academicYearCourse == student.academicYearCourse && studentID.equals(student.studentID) && codeCourse == student.codeCourse && typeStudent == student.typeStudent && cfu == student.cfu && isErasmus == student.isErasmus && Objects.equals(socialSecurityNumber, student.socialSecurityNumber) && Objects.equals(firstName, student.firstName) && Objects.equals(lastName, student.lastName) && Objects.equals(birthDate, student.birthDate) && Objects.equals(birthCity, student.birthCity) && Objects.equals(birthPlace, student.birthPlace) && Objects.equals(courseYear, student.courseYear) && Objects.equals(firstEnrollment, student.firstEnrollment) && Objects.equals(lastEnrollment, student.lastEnrollment) && Objects.equals(departmentName, student.departmentName) && Objects.equals(courseName, student.courseName) && Objects.equals(nation, student.nation) && Objects.equals(email, student.email) && Objects.equals(citizenship, student.citizenship) && Objects.equals(gender, student.gender) && Objects.equals(studentStatus, student.studentStatus); } @Override public int hashCode() { return Objects.hash(socialSecurityNumber, firstName, lastName, birthDate, birthCity, birthPlace,courseYear, firstEnrollment, lastEnrollment, departmentName, courseName, nation, email,citizenship, gender, studentStatus, academicYear, academicYearCourse, studentID, codeCourse, typeStudent, cfu, isErasmus); } } The Java way 1. Declaration 2. Getter and setters 3. equals, hashcode, toString (A lot)
  12. 12. Java way: 280+ lines of code of pure boilerplate to implement a class that abstracts a student Kotlin counterpart: data classes In Kotlin, declaring data class is more than enough. Getters, setters, equals, hashcode, toString are provided by default. Can be used in Java thanks to the complete interoperability. import java.time.LocalDate data class Student ( val socialSecurityNumber: String, val firstName: String, val lastName: String, val birthCity: String, val birthPlace: String, val courseYear: String, val firstEnrollment: String, val lastEnrollment: String, val departmentName: String, val courseName: String, val nation: String, val email: String, val citizenship: String, val gender: String, val studentStatus: String, val studentID: String, val birthDate: LocalDate, val academicYear: Int , val academicYearCourse: Int, val codeCourse: Int, val typeStudent: Int, val cfu: Int, val isErasmus: Boolean) Student object is made of: 1. Declaration 2. Getter and setters 3. equals, hashcode, toString (A lot)
  13. 13. Safe - var (mutable) vs val (immutable) variables - Null safety fun prettyPrint(student: Person?){ student?.let { println("Name: ${it.name}") println("Last name: ${it.surname}") println("City: ${it.birthCity}") } ?: println("No person found!") } fun prettyPrintAssert(student: Person?) { student!!.run { println("Name: $name") println("Last name: $surname") println("City: $birthCity") } // If student is null, assert is triggered }
  14. 14. Functional programming fun collectionProcessingExample(students:List<Student>){ students.filter { it.examsTaken > 6 && it.averageGrade > 4.0 } // 1 .sortedBy { it.averageGrade } // 2 .take(10) // 3 .sortedWith(compareBy({ it.surname }, { it.name })) // 4 } fun lambdaExample(students:List<Student>):Int { val sumLambda = {x:Student, y:Student -> x.examsTaken + y.examsTaken} return if (students.isEmpty()) 0 else sumLambda(students.first(),students.last()) } fun highOrderExample(student1: Student, student2: Student, func: (Student, Student) -> Int) : Int { return func(student1,student2) } - Lambdas - Higher-order function - Anonymous functions
  15. 15. Standard collection extensions functions fun main(args: Array<String>) { val people = listOf(...) // print all person name and age people.forEach { println("Name: ${it.name}, age: ${it.age} years old") } // all people sorted by age (ascending) people.sortedBy { it.age } // first Luigi people.first { it.gender == "Luigi"} // oldest Luigi people.filter {it.gender == "Luigi" }.maxBy { it.age } // group people by age people.groupBy { it.age }.maxBy { it.value.count() } // age 10 years from now people.map { it.copy(age = it.age + 10) } // partition people with age below and equal or above 25 people.partition { it.age <= 25} // each gender count people.groupingBy { it.gender }.eachCount() // all people where age below average age val averageAge = people.map { it.age }.average() people.filter { it.age <= averageAge } }
  16. 16. What else ● Coroutines ● Delegation ● Inline lambdas ● Reified generics ● Sealed Class (Algebraic Data Type) and Anonymous Class ● Smart casts ● Supports for Reactive Programming (RxKotlin extension) ● And much much more
  17. 17. Kotlin Common ● Kotlin common code means that it relies only on the standard library. Support for HTTP, serialization, and management of coroutines is provided by default. ● Enables support for multi platform projects ● Kotlin common can be exported to native code which runs on JVM, Android, JavaScript, Native(iOS, x86 and even embedded systems like STM32)
  18. 18. Behind the scene of Kotlin Common Kotlin/JVM Kotlin/JS Kotlin/Native
  19. 19. JVM-exclusive project - Kotlin + JVM environment - Can be used to create Android apps using the Android SDK - Supports Kotlin Android Extensions for extra features and APIs - Can use Java artefacts freely Multiplatform project - Shared code written in Kotlin common - Platform specific bits (like UI View) must be written using native code for that platform (e.g: Java/Kotlin for Android, Swift/Objective C for iOS). - Apps will have a native look and feel
  20. 20. Kotlin for multiplatform. Why? - Compilation to native platform-specific executable artefacts - No bridges between shared code and native platforms - Faster development - Best possible performance - Can easily support platform-specific libraries and solutions - Perfect for typical apps and for games, native or high performance applications But... - Kotlin Multiplatform support is still an experimental feature and things are subject to changes - You still need to have a good-enough knowledge of the platforms on which you are working on to write the platform-dependant bits of your code - Kotlin/Native is always lagging behind Kotlin/JVM and Kotlin/JS in terms of features
  21. 21. Another approach… Xamarin
  22. 22. Xamarin is... A framework for app-development that allows to: ● Write native applications on different platforms (Android, IOS, MacOS, Windows Phone) ● Share the same C# codebase ● Use Visual Studio IDE ● Take advantage of all the .NET libraries https://docs.microsoft.com/en-us/xamarin/
  23. 23. Why Xamarin? Legacy applications development: ● APIs written in application-specific language ● Platform-specific features ● Different IDEs ● Application-specific UI and user experience
  24. 24. Two solutions...
  25. 25. Xamarin.IOS and Xamarin.Android ● 100% coverage of platform-specific APIs with the added benefits of .NET APIs ● Fully native performance ● Shared code for common logic
  26. 26. Pros ● Design UI with platform-specific user experience ● Access all platform-specific features (all that you can do in xCode and Swift or in Java and Android Studio you can do it also with Xamarin.IOS and Xamarin.Android) Cons ● Need to have experience with the specific framework APIs and functionalities ● Cannot share UI logic among different platforms
  27. 27. Xamarin.Forms ● Common API for all platform ● Can access most common hardware-specific features (Camera, GPS, Phone Dialer, etc) through Xamarin.Essential ● Xamarin.Forms creates native controls for each platform at runtime
  28. 28. Pros ● Fast deploy of applications among different platforms ● Native applications. Xamarin.Forms APIs are translated into native APIs ● Share markup for user interface ● Can access hardware-specific features using common APIs ● No platform-specific knowledge required ● Good unified documentation Cons ● Cannot access some very specific platform-specific features ● Cannot personalize UI to look and feel exactly like a platform specific application
  29. 29. Xamarin.Forms project When we create a new Xamarin.Forms project the solution includes: ● The shared project, containing: ○ All the dependencies (.NET Standard Library, Xamarin.Forms and Xamarin.Essential) ○ The App.xaml.cs class, that handles the cycle of life of the application and instantiates the MainPage.xaml.cs class, that’s the entry point of the application ● The platform-specific projects, each of which references the shared code and the Xamarin.Forms code
  30. 30. Mobile Backend as a service
  31. 31. MBaaS: what is it? ● Model for providing to mobile app developers a way to link their applications to backend cloud storage and APIs exposed by backend applications ● The provider (as Microsoft Azure for example) offers to the developer all the settings in order to reduce the time needed to setting up a customized (and traditional) backend
  32. 32. How services are provided? ● A MBaas usually provides some of this services: ○ User Management ○ Push Notifications ○ Integration with social networking services ○ File Storage ● Services are provided in the following ways: ○ Use of custom Software Development Kit (SDKs) ○ Application Programming Interfaces (APIs)
  33. 33. Advantages and disadvantages ● No waste of time: a consistent way to manage backend data implies that developers don't need to redevelop their own backend for each of the services that they want to access ● Scalability: the developer doesn't have to worry about what's going on the server side ● Analytics: the use of APIs give the access to all the traffic analytics ● Security: most of the BaaS vendors do provide real good security protocols. Pros Cons ● Control: developers usually like to have complete control over the source code but most vendors restrict access to the backend source code. ● Vendor Lock In: the user has to read carefully the terms of use of each vendor and evaluate if there is a vendor lock in when data migration is necessary.
  34. 34. AZURE MBaaS vs FIREBASE MBaaS
  35. 35. Azure Mobile App Service ● Microsoft MBaaS solution, first released in March 2015 ● Mobile applications built with this solution easily integrate with other services provided by Azure (such as website apps, logic apps, and API apps)
  36. 36. Azure Mobile App - Compatibility
  37. 37. Azure Mobile App Architecture
  38. 38. Major Functionalities ● Client SDK support for building native applications on Android, iOS, and Windows devices, as well as cross-platform applications using the Xamarin framework ● Applications that can work offline and sync data in the background by connecting with APIs and data sources ● Different options for user authentication and authorization, including integration with social media platforms (such as Facebook and Twitter) ● Customized push notifications
  39. 39. IoT hub Example
  40. 40. Java Example - Authentication with Google
  41. 41. Pros ● High availability: uptime guaranteed is 99.95% ● Good scalability options: you can add or remove instances to your application whenever you feel the need to ● Optimized for Mobile devices and Tablets: Data and network optimization for mobile applications, and minimized fragmentation troubles across multiple devices and platforms. ● Efficiency gains: Reduces the backend system development time & cost, and the maintenance cost as well ● It allows you to use any framework, language, or tool: Azure allows you to build apps with the language you prefer, including .NET, Java, and Node.js Cons ● Requires Management: it needs to be expertly managed and maintained, which includes patching and server monitoring ● Requires Platform Expertise: it requires expertise to ensure all moving parts work together efficiently ● Comparatively expensive ● Speed can be an issue for some businesses
  42. 42. ● Google comprehensive mobile development platform, released in 2011 by Firebase and acquired by Google in 2014
  43. 43. Features Overview
  44. 44. Example
  45. 45. The Firebase SDK - Compatibility Firebase SDK Is cross-platform capable
  46. 46. Java Example - Authentication
  47. 47. Firebase gives its best by using it in combination with Google Cloud Platform and some third party services Integration with services
  48. 48. Pros ● Getting a whole app off the ground is fast – auth, email, versioning, hosting, monitoring, devops, uptime. ● The data structure is JSON which maps perfectly to UI JavaScript ● Libraries across programming languages are similar and pretty good ● Minimal, or no, knowledge of devops/sysadmin is necessary ● All you need for the backend of a small mobile app Cons ● Your entire backend is proprietary (BaaS), owned and run by another company. ● Exceptionally expensive at scale compared to REST ● Migrating off means rewriting all backend tests and much backend code. ● You must duplicate any business logic across all systems that interact with firebase. ● Querying and aggregating are limited compared to SQL or popular NoSQL databases like MongoDB https://symboliclogic.io/firebase-pros-and-cons/
  49. 49. Contacts linkedin.com/in/gianluca-capozzi-b9a75a16b/ github.com/GianlucaCapozzi ● Gianluca Capozzi linkedin.com/in/danieledavoli/ github.com/danieledavoli ● Daniele Davoli linkedin.com/in/giuseppecapaldi github.com/not-a-genius ● Giuseppe Capaldi github.com/polyc ● Gabriele Cervelli linkedin.com/in/gabriele-cervelli-88406b181/ ● Giorgio De Magistris linkedin.com/in/giorgio-de-magistris-939a2b182/ github.com/giorgiodema ● Leonardo Sarra linkedin.com/in/leonardo-sarra-b34691182/ github.com/lithiumsr

×