Previously, we have seen cross-platform solutions but they either compromised on performance or reaching design expectations. Google, Facebook, and Microsoft have been hard at work and I think they now have solutions that are worth taking another look. I want to explore three such popular frameworks: Flutter, Xamarin, and React Native, explain what they are, how they work, and compare them against each other with a focus on performance. My hope is that after reading this article, you are inspired enough to go check them out and know enough to formulate in your mind which technology could be the right choice for your needs.
2. Agenda
iOS Summit 2017
• Flutter
o Demo
o Developer Experience
o Performance
• Xamarin
o Demo
o Developer Experience
o Performance
• React Native
o Demo
o Developer Experience
o Performance
• Comparison
2
22. C#
Xamarin - Overview
// Check out https://www.microsoft.com/net/tutorials/csharp/getting-
started for the comprehensive tutorial.
// Basic for loop.
for (int i = 0; i < 10; i++)
{
Console.WriteLine(i);
}
var myList = new List<string>() { "one", "two", "three" };
foreach (var item in myList)
{
Console.WriteLine(item);
}
// Holds 3 elements, with indexes of 0, 1, and 2.
int[] someIntegers = new int[3];
// Initializes the values of the array.
int[] moreIntegers = new int[] { 1, 2, 3, 4, 5 };
// You can omit `int` and just specify []; type is inferred.
int[] otherIntegers = new[] { 1, 3, 5, 7, 9 };
// Exception handling.
try
{
int sum = SumNumberStrings(new List<string> { "5", "4" });
Console.WriteLine(sum);
}
catch (System.FormatException)
{
Console.WriteLine("List of numbers contained an invalid entry.");
}
// Classes have members, which consist of methods, properties, and fields.
// You should rarely expose fields from your classes, and instead use propert
ies
// to control external access to your object's state.
public class Speedometer
{
private int _currentSpeed;
public int CurrentSpeed
{
get
{
return _currentSpeed;
}
set
{
if (value < 0) return;
if (value > 120) return;
// Value is a keyword used in setters representing the new value.
_currentSpeed = value;
}
}
}
22
32. Xamarin – GPU Performance
• 3.20 s Initializing application's address space
and dynamic linking required frameworks
took 3.20 s.
• 345.87 ms Application launched in 345.87 ms.
• ~53 fps .
32
40. JavaScript
// Lack of function signature.
var foo = 'im a number'
function divideByFour(number) {
return number / 4
}
console.log(divideByFour(foo)) //NaN
// Immutability support.
const array = [3, 6]
array[5] = 9
console.log(array) // [ 3, 6, , , , 9 ]
// Arrays don't have to contain same type of objects.
var array = [0, 1, 2]
array["hello"] = "world"
console.log(array) // [ 0, 1, 2, hello: 'world' ]
// Documentation suggests: It’s best to leave exceptions as a
last line of defense,
// for handling the exceptional errors you can’t anticipate,
and to manage anticipated
// errors with control flow statements.
function tenDividedBy(number) {
if (number == 0) {
throw "can't divide by zero"
}
return 10 / number
}
console.log(tenDividedBy(0))
/*
/temp/file.js:9
throw "can't divide by zero"
^
can't divide by zero
*/
JavaScript – Pain Points
40
41. JavaScript
// No support for decimals.
console.log(0.1 + 0.2) //0.30000000000000004
console.log(0.1 + 0.2 === 0.3) //false
// Confusing math operations.
var a = 0
var b = -0
console.log(a === b) // true
console.log(1/a === 1/b) // false
var x = Math.sqrt(-2)
console.log(x === NaN) //false
console.log(isNaN(x)) //true
console.log(isNaN('hello world')) //true
// Treatment of null and undefined is confusing:
var foo;
foo === null; //false
foo === undefined; //true
JavaScript – Pain Points
41