swift & kotlin - d2wakvpiukf49j.cloudfront.net · sources tell the next web that google is...
Post on 01-Sep-2019
9 Views
Preview:
TRANSCRIPT
SWIFT & KOTLIN@DagnaBieda, #IOExtendedCLT, 18th May 2016
Software Engineer at Quoin, 209 Delburg Street, Davidson, NC
“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
“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
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.
THERE ARE 800,000 NEW APP DEVELOPERS EVERY
YEAR
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
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
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
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()) }
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
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) // ... } }
USER BASE VS CODE BASE
THANK YOU!
#ifdef greatPresentation
#include ”standing-ovation.hpp”
#endif
top related