SWIFT & KOTLIN - d2wakvpiukf49j.cloudfront.net · Sources tell The Next Web that Google is...

18
SWIFT & KOTLIN @DagnaBieda, #IOExtendedCLT, 18th May 2016

Transcript of SWIFT & KOTLIN - d2wakvpiukf49j.cloudfront.net · Sources tell The Next Web that Google is...

Page 1: SWIFT & KOTLIN - d2wakvpiukf49j.cloudfront.net · Sources tell The Next Web that Google is considering making Swift a “first class” language for Android, while Facebook and Uber

SWIFT & KOTLIN@DagnaBieda, #IOExtendedCLT, 18th May 2016

Page 2: SWIFT & KOTLIN - d2wakvpiukf49j.cloudfront.net · Sources tell The Next Web that Google is considering making Swift a “first class” language for Android, while Facebook and Uber

Software Engineer at Quoin, 209 Delburg Street, Davidson, NC

Page 3: SWIFT & KOTLIN - d2wakvpiukf49j.cloudfront.net · Sources tell The Next Web that Google is considering making Swift a “first class” language for Android, while Facebook and Uber
Page 4: SWIFT & KOTLIN - d2wakvpiukf49j.cloudfront.net · Sources tell The Next Web that Google is considering making Swift a “first class” language for Android, while Facebook and Uber

“Sources tell The Next Web that Google is considering making Swift a “first class” language for Android, while Facebook and Uber are also looking to make Swift more central to their operations.

Google’s Android operating system currently supports Java as its first-class language, and sources say Swift is not meant to replace Java, at least initially.

-The Next Web

Page 5: SWIFT & KOTLIN - d2wakvpiukf49j.cloudfront.net · Sources tell The Next Web that Google is considering making Swift a “first class” language for Android, while Facebook and Uber

“Unfortunately, sources tell The Next Web that Google’s current mindset is that Kotlin is a bit too slow when compiling.

But, Kotlin is billed as a language that “works everywhere Java works,” and has “seamless” support for projects that mix it and Java.

-The Next Web

Page 6: SWIFT & KOTLIN - d2wakvpiukf49j.cloudfront.net · Sources tell The Next Web that Google is considering making Swift a “first class” language for Android, while Facebook and Uber

DIFFERENCES

➤ Java, JVM, GC,

➤ created by JetBrains - mostly Java devs using IntelliJ for Android know about it,

➤ requires some level of programming knowledge,

➤ JetBrains has committed to long-term backwards compatibility starting with v1.0.

➤ Obj-C, rooted in C, ARC,

➤ created by Apple, so even non-devs know about Swift,

➤ very easy to pickup,

➤ community support, massive amount of courses,

➤ Swift 3.0 won’t be backward compatible.

Page 7: SWIFT & KOTLIN - d2wakvpiukf49j.cloudfront.net · Sources tell The Next Web that Google is considering making Swift a “first class” language for Android, while Facebook and Uber

THERE ARE 800,000 NEW APP DEVELOPERS EVERY

YEAR

Page 8: SWIFT & KOTLIN - d2wakvpiukf49j.cloudfront.net · Sources tell The Next Web that Google is considering making Swift a “first class” language for Android, while Facebook and Uber

WHERE TO LEARN FROM

➤ stackoverflow.com ~92k/1k vs ~1k/63 [question/votes]

➤ youtube.com: ~124k results vs ~2.3k results

➤ udacity.com:

A. Intro to iOS App Development with Swift

B. iOS Developer Nanodegree

➤ edx.com

➤ coursera.com

Page 9: SWIFT & KOTLIN - d2wakvpiukf49j.cloudfront.net · Sources tell The Next Web that Google is considering making Swift a “first class” language for Android, while Facebook and Uber
Page 10: SWIFT & KOTLIN - d2wakvpiukf49j.cloudfront.net · Sources tell The Next Web that Google is considering making Swift a “first class” language for Android, while Facebook and Uber
Page 11: SWIFT & KOTLIN - d2wakvpiukf49j.cloudfront.net · Sources tell The Next Web that Google is considering making Swift a “first class” language for Android, while Facebook and Uber

SIMILARITIES

➤ open sourced

➤ mix of good practices from multiple languages, combination of functional and objective approach,

➤ optional types, no nil as we know it, (“Null References: The Billion Dollar Mistake”)

➤ all variables must be initialized before using them,

➤ extension functions,

➤ no semicolons ;D

Page 12: SWIFT & KOTLIN - d2wakvpiukf49j.cloudfront.net · Sources tell The Next Web that Google is considering making Swift a “first class” language for Android, while Facebook and Uber

CODE EXAMPLES - OPTIONAL TYPES

let n = nil // won’t compile (type of expression is ambiguous without more context) let i: Int? = nil // the result is actually Optional<Int>.None

var b: String = “Google I/O“ b = nil // won’t compile

val n = null // won’t compile val i: Int? = null

var b: String = “Google I/O“ b = null // won’t compile

Page 13: SWIFT & KOTLIN - d2wakvpiukf49j.cloudfront.net · Sources tell The Next Web that Google is considering making Swift a “first class” language for Android, while Facebook and Uber

CODE EXAMPLES - OPTIONAL TYPES

class Department { func description() -> String {

return “Name” }

}

class Employee { let department: Department? = nil }

let sara: Employee? = Employee()

sara?.department?.description() sara!.department?.description() sara!.department!.description() // !

// implicitly unwrapped values if let department = sara?.department { print(department.description()) }

class Department { fun description() = “Name” }

class Employee { let department: Department? = null

}

val sara: Employee? = Employee()

sara?.department?.description() sara!!.department?.description() sara!!.department!!.description() // !

// implicitly unwrapped values if (sara != null && sara.department != null){ println(sara.department.description()) }

Page 14: SWIFT & KOTLIN - d2wakvpiukf49j.cloudfront.net · Sources tell The Next Web that Google is considering making Swift a “first class” language for Android, while Facebook and Uber

CODE EXAMPLES - EXTENSIONS

extension UIColor { class var random: UIColor { switch random()%6 { case 0: return UIColor.greenColor() case 1: return UIColor.blueColor() case 2: return UIColor.yellowColor() case 3: return UIColor.redColor() case 4: return UIColor.purpleColor() default: return UIColor.blackColor() } } }

var Color.random: Color get() = when (Math.random().nextInt(6)) { 0 -> Color.GREEN 1 -> Color.BLUE 2 -> Color.YELLOW 3 -> Color.RED 4 -> Color.MAGENTA else -> { Color.BLACK }

} // https://kotlinlang.org/docs/reference/extensions.html

Page 15: SWIFT & KOTLIN - d2wakvpiukf49j.cloudfront.net · Sources tell The Next Web that Google is considering making Swift a “first class” language for Android, while Facebook and Uber

CODE EXAMPLES - FUNCTIONAL

func prepareStudentMessages(tutor: Tutor, on date: NSDate) {

let matchIdAndSelectedDate = { (m: Message) -> Bool in return m.tutorId == tutor.id && m.date ~= date }

for message in messages.filter(matchIdAndSelectedDate) { let view = MessageView(message: message) view.origin = calculateTimelineOffset(message.date) // ... } }

fun prepareStudentMessages(tutor: Tutor, date: NSDate) {

val matchIdAndSelectedDate = { m: Message -> m.tutorId == tutor.id && m.date.sameDayAs(date)

}

for (message in messages.filter(matchIdAndSelectedDate)) { val view = MessageView(message: message) view.origin = calculateTimelineOffset(message.date) // ... } }

Page 16: SWIFT & KOTLIN - d2wakvpiukf49j.cloudfront.net · Sources tell The Next Web that Google is considering making Swift a “first class” language for Android, while Facebook and Uber
Page 17: SWIFT & KOTLIN - d2wakvpiukf49j.cloudfront.net · Sources tell The Next Web that Google is considering making Swift a “first class” language for Android, while Facebook and Uber

USER BASE VS CODE BASE

Page 18: SWIFT & KOTLIN - d2wakvpiukf49j.cloudfront.net · Sources tell The Next Web that Google is considering making Swift a “first class” language for Android, while Facebook and Uber

THANK YOU!

#ifdef greatPresentation

#include ”standing-ovation.hpp”

#endif