Bianca Curutan Kotlin vs. Swift, Not So Different After All

Automatic Summary

Kotlin vs. Swift: Not So Different After All

Welcome, everyone, to this exciting discussion delving into the fascinating world of programming languages. Specifically, Kotlin vs. Swift. Although seemingly different, these two languages share a striking similarity. Understanding these nuances can significantly optimize collaborative work among client teams and elevate your programming knowledge.

Who am I?

Hi, I'm Bianca, currently an Android lead and mobile engineer at Postmates, San Francisco, where my primary responsibility lies in developing iOS and Android apps. With prior experience at Fandango and Rotten Tomatoes, my tech journey and expertise span several programming languages.

The Difference and the Similitudes

Kotlin, an open-source language by JetBrains, operates on the Java Virtual Machine, interoperable with Java seamlessly. In contrast, Swift, developed by Apple, uses the Objective-C runtime library. Apple incorporates C, Objective-C, C++, and Swift into one program. But, even though they appear different, my experiences revealed their striking resemblance. For better understanding, let's consider some practical examples.

Basic Programming Paradigms

  • Variables: Kotlin uses 'val' and Swift uses 'let' for constants. The keyword 'var' in both languages, changes the value of a constant.
  • Automatic Type Inference: Both languages decide the datatype based on the value assigned.
  • Implicit and Explicit Type Conversion: The variables can be declared without explicit initialisation, but further cast as different types explicitly.
  • Optional Types: These languages support optional types, thus permitting variables to possess null values.

Advanced concepts

  • String Interpolation: It helps in injecting variable values into format strings.
  • Collections: Swift and Kotlin both provide the functionality of initializing lists, providing a versatile way to group related items.
  • Functions: Both languages support named arguments, allowing the creation of a result string.
  • Lambdas: It permits creating small, anonymous functions.
  • Unwrapping Non Null Optionals: For safety, optional string type values should be unwrapped and used.

Conclusion

When compared to their ancestral languages, Java and Objective-C, Kotlin and Swift clearly stand out as safer as they catch more issues at compile-time, less verbose offering leaner syntax, and interoperable with the ancestral languages.

Comparing Kotlin and Swift with each other reveals their uncanny similarity, both syntactically and functionally, sharing a common ideology to resolve the obstacles posed by their ancestor languages. Thus, understanding these languages can significantly enhance developer skills and facilitate easier cross-platform development.

If you have any further questions or would like to learn more about me, my work, or programming languages, feel free to reach out. Thanks for joining me today and happy coding!


Video Transcription

Hi, everyone. Thank you for your patience. I just wanted to give it a few extra minutes in case there were any last minute stragglers coming in, but it of course is open to people to come in and drop by whenever they'd like.Please let me know if you can't hear me or if you'd like me to slow down. Um I'll try my best to keep an eye on the chat and answer questions as we go along or feel free to save them to the end. And with that being said, let's get started so well. Firstly, I hope you're all doing well. You're staying safe and healthy during this time. My name is Bianca and this is kin versus swift, not so different. After all. Today, we'll be walking through some examples that demonstrate that these two languages follow the same programming paradigm, understanding these differences and especially can help developers work more collaboratively and efficiently across client teams and provide a higher level understanding of programming concepts in general before we jump into that.

However, let me tell you a bit about my background. I'm currently a mobile engineer and an Android lead at Postmates in San Francisco where I develop I Os and Android apps primarily on the courier experience team. If you're not familiar with Postmates, it's an on-demand delivery platform similar to seamless Uber eats delivery deliveroo or doordash. Although we're not just limited to food deliveries and we at Postmates have mobile apps on all three sides of the marketplace. So that's the buyers or consumers, which may be the app you're most familiar with. If you've used our platform before fleet, which is the courier experience and the team that I'm on and the merchants. Fun fact, I was on the team that developed the merchant I OS app for the very first time. Just a few weeks ago, it was part of our company wide hackathon. So building an app from scratch in 1 to 2 days and it's hopefully pending release in the near future. Anyway, the client texts that we use across the mobile teams at Postmates include Java and Klan on Android and Objective C and Swift on I Os. Prior to Postmates, I used to do I Os and Web at Fandango and Flix Rotten Tomatoes where I worked on the Flix iphone and ipad apps and the Rotten Tomatoes review website, which some of you may know for movie and TV.

Although I'm currently working in the Bay Area, I'm originally from Canada. Uh I went to the University of Waterloo and mcmaster University where I studied math and software engineering, particularly code generation and one of the things I sought to prove with my master's research was the semantic similarities between any programming languages, regardless of their different syntax or paradigms.

Sound familiar. I hope so. So let's get more technical. Now, firstly, what is coin coin is an open source programming language developed by jetbrains. It runs on the Java virtual machine and is 100% interoperable with Java. What is Swift? It's an open source programming language developed by Apple.

It uses the objective C runtime library and allows c objective C C++ and swift code to run within one program. But wait, that actually sounds like they're different. And here I am claiming they're actually very similar. So let's check out some examples. First, we'll start with the basics variables for variables. You set once consonants, we use the keyword vowel in Collin and let in swift. The constant here is forever 20 with the value 20 it will stay at 20 unless it's changed using the keyword there. The next example which actually uses Behr is called not on not always 12 where we start off with the value 12, but then change it to 87 soon after simple, right? What about types? Perhaps the simplest one to understand or that's at least familiar is automatic type inference.

In the first example, the variable auto will be determined to be a string type based off the June text. The next example shows implicit type conversion. The variable is declared as a double but is not explicitly initialized as one. And the value is 2020. Of course, if there is implicit type conversion, then there must also be explicit type conversion. Here we cast the number 19 to be a string. Otherwise, automatic type inference would likely cast it as an in finally coin and swift allow for optional types. Meaning variables can be null or some other non null value if you're familiar or and or have used Java before. This would be that null annotation by non null. In this example here, I'm of course referring to Women Tech global conference string interpolation or variable substitution is a way to inject values into a format string. The variable here is who is it with value? Women Tech putting it together with greeting. The final result is hello, Women Tech.

You both the F out for me but

on to collections lists in particular like their ancestral languages. It's possible to initialize lists on the fly and Collin and swift. Here we're listing out the themes for the conference sessions. Today we have work revolution tech, innovation and purpose, humanity and collaboration.

And here's another example of a collection maps. In this example, we're mapping Android OS s specifically to the letters to the names. You may have noticed a mistake here where we accidentally mapped M twice first to lollipop and then correctly to marshmallow. But no worries, it's a mutable map and we'll just say the latest corresponding value like variables, do lists and maps are only two examples of collections. Of course, other collections you might want to look at are arrays, sets and sequences available in both languages. Putting together some of the concepts we've talked about, we can write functions, a group of related statements that perform a specific task. Here, we have a name argument and we use string interpolation to create a result string, calling this function hello yields hello Jane Doe.

Now perhaps those examples were a little too simple or boring for you. So let's take a look at some complicated ones. Next, unwrapping, non null optionals. Let's say we have a constant world that has an optional string type for safety. The compiler only allows us to use world after unwrapping it by using let in coin with the Elvis operator. And if L in swift and as you can see here, world is not null. So we'll end up with hello world just as a side note if you do try to use it while it is not un not unwrapped. So it's still in an optional state. Um For example, if you try to print it, the printer will actually say optional and string, which in most cases, we probably don't want to see that. So using the same example from before, we can see how the result changes when we have a null value instead. Now we'll end up here with nothing to see here folks on to LAMBDAS, which are a way to create small functions without names. So the lambda I'm referring to here is the braces. But um right after side stop map in this example, map, like I mentioned is used on a list and applies a cube operation to each value by multiplying it to it to it. The result is a new list of values where each value of sides is cubed.

So providing list 123 to the function will return a list 1827. Other LAMBDAS you may want to explore are filter and reduce both of which can be combined along with map and to each other. So building on our example from before, does anyone know what the function fu here? Does it filters out the list of sides to use only even numbers or mod to equal zero? Then it essentially keeps those values returning 860

four

interfaces in Collin can contain declarations of abstract methods as well as method implementations. Then a class or an object can implement one or more interfaces. Similarly, there are protocols in swift which can then be adopted by a class structure or enumeration to provide an actual implementation of those requirements. So in this coin example, we have my awesome coin class which implements my awesome interface with function F food.

And next to it on the swift side, we similarly have my awesome swift class implementing my awesome protocol again with the function F food. Well, there may have been a lot to take in but there are some useful conclusions that we can draw from these examples. So first let's compare coin and swift to their ancestor languages, Java and objective C, they're safer. Remember that unwrapping example, we looked at we're able to catch and fix more issues and compile time or if we do decide to find them at run time, we can hopefully catch those errors like optional strings. They're less verbose, they have leaner syntax, making them more convenient and readable, particularly for developers newer to the languages. And this also drastically reduces the amount of boilerplate code. They both have functional programming support useful if you're familiar with other functional languages such as Lisp or Haspel.

And on top of all that, they're still interoperable with their ancestor languages. So it's possible to use Java and Kin in the same code base or objective C and Swift. And this makes it easier to develop new projects or maintain older ones. So fun fact at, like I mentioned at Postmates, we do use all four of the languages in our mobile code bases, but they're heavily skewed towards the newer languages. So for example, we have I believe, 90% swift based code and then 10% objective C and then on the android side, it's about 70% coin and 30% Java.

This talk of that.

Well, now that we've compared co and swift to their ancestral languages. How do they compare to each other? That part is easy. Syntactically, they're close enough. You can see that in the examples we covered today functionally, they're also close enough and semantically, they share the same ideology since they solve the same problems created by their ancestor languages. So what does that mean for you? Well, there are benefits to learning and understanding both languages or at least the ideology that they come from, it can improve your skills and experience giving you a stronger understanding of development concepts based on that. It can also be easier to make the leap from I OS to Android, and Android to I OS. It aids in native development so it becomes faster and easier to develop tests and maintain both clients. It encourages cross team collaboration and app parody. I mentioned in the beginning that I'm a mobile engineer for both clients. And fortunately, I'm not the only one at the company since others have also taken advantage of the similarities to be able to work on both platforms. And as a bonus, Swift is not limited only to I OS code and coin is not only limited to Android, you can build I OS apps using coin on multi platform and you can build Android apps using Swift for Android. So that's it for today.

Um Here are some resources to help you get started the slides for this presentation and other talks I've done are available at the wordpress link and thank you for joining me today. I hope what you learn can be applicable in your daily development lives. Um I will still be here for questions if you have any. Otherwise, please feel free to reach out to

me. Thanks. I hear you ever do that with that? You more than that. Great.

Thank you, Amanda Miriam. I haven't used flutter before. How do you like it so far? Um I'm not sure how many languages I know on a regular basis I use perhaps three of them. So Java Klan and Swift, um, when I was in school I actually took a programming language class. So this is just for one class where we had to, um, do assignments in 14 different languages. So I guess it depends on your question on what, what do you, how do you define, how do you know a language versus just having used it before? I guess you might want to write more than Hello World. Which one do you like most? That's difficult to say. Uh, I think I tend to have recency bias. I like Clan and Swift because those are the ones I use the most often day to day. So it's very easy to be able to use without thinking too much about it. But I'm sure as I start to use different languages, I would see the benefits of those as well. Oh, great bye. Yeah, I have heard really nice things about flutter um with React native, it's I'm not sure if you've ever brought it up with mobile developers, but there always tends to be a big eye roll like, oh no React native. Although personally, I haven't used it what I find.

And sometimes I do get asked the question like, why are you learning Collin and Swift? Why don't you just build the two apps in React native? I tend to just um I, I've had the observation that React native tends to be used by web developers, whereas mobile developers tend to use native languages. So it depends on the skill set of the engineers, I guess on what they would prefer, which one has taught me the most about logic language and its use? Hm I would say, I think Java, I believe it would. But yeah, I, I suppose there's no correct answer to that because everyone has their own experiences. Um I tend to like Java for learning logic and language because it was the first language that I learned way back when I was in school. Um But besides that, it's, if you've ever done developer interviews, it tends to be a very common interview language. So it's a lot easier, well, easier, it can be a lot easier to pick up on concepts but as, as well as um communicate those concepts to other people. Since a lot of people tend to be familiar with that. Another one that I see, but not, well, it depends on which uh what type of engineer you're talking to. But another language I see a lot of people using, especially for back end is Python.

Um And that one, they also tend to teach in a lot of boot camps and in schools. So that seems to be a good one too.

That

best platform to learn. C sorry, can you please clarify that question a little? Um I'm not quite sure what you mean by the best platform. Um the way that I've learned coin and if you're interested in mobile development, what seems like a good direction to go is just to build an app using coin. Fortunately, since it's an official Google language now and it has been out for some years, there's a lot of tutorials online and other resources that can help you learn. And I, I guess again, since it is an official Google language, there do tend to be more production apps using it now than there used to be. Uh Yes, we do use Android studio for DEV environment and also X code for Swift for I Os

office one. Oh, I can do that. I can do you put the once more treatment just to get your

great. Well, thank you again for, oh sorry. One last question. I got confused between clutter and Collin. Mhm. Thank you, Amanda. Um Flutter and Colin. Uh Well, I haven't personally used flutter before but it depends what direction you wanna go with, how you're learning um for, for pure native mobile development coin does seem to be more common from what I've observed. Um But that could also just be the companies and the engineers I'm surrounded with, it might just be my own experience. Um It would be great if anyone else has other things to mention. Um But both are used in mobile development. So it just depends on what direction you wanna go and where you wanna go from there. Yeah, because uh what Amanda says is a great way to mention it. Um It's easy for a web dev to learn. So if you're coming from a web background, then that would be a shorter jump to be able to learn mobile development from there. And then if you want to learn co or if you come from a background that's neither web nor oh sorry, that's just not web. Then it seems like they're about even jumps to be able to learn. What is your education journey? Um My education journey kind of went all over the place. I actually didn't take my first programming class until university. Uh Oh, sorry. Just to add to um ruti.

If I'm pronouncing that correctly, please let me know if you have any follow up questions as well. I can be reached at the contact information on the slide.

I can also be here.

OK. So I also plugged my linkedin information to the chat if anyone has follow questions after this. Um, but for jorge, if I'm pronouncing that correctly, um, so what is your educational journey? Yeah. I, I didn't know I wanted to be an engineer. I took my first programming class in university. I did not do that great on it, but fortunately I did not give up and I decided to take another one. I did a lot better and I guess from there, something kind of clicked. It was like, oh, this is actually something that's kind of cool. And I'm actually pretty good at it and I can get a job out of it. So everything seemed to align really well. And that's when I decided to pursue it a bit more seriously. Um I ended up finishing my degree in math because in my head, I had already started it and I wanted to finish it, but I went back to school to do software engineering and kind of for me that was uh what I thought was a good personal decision because it helped me bridge the gap math was a good way for me to start because it introduced me to programming concepts.

But I still felt like I was lacking some things that I wanted to learn more on. So from there, it was fairly linear. After getting my masters in software engineering, I moved to California and got my first development job in web. Um Then from Web, I switched over to I OS development using objective C. Uh And yeah, from there, I kind of kept going along the I OS path for a while. And then I learned Android in my current role. So when I first joined my current company, I had zero Android experience, but I learned it. Um I had really good opportunities and really good mentorship and now I'm leading one of the Android teams. So it's kind of cool, you never know where things will take you.

OK.

Um So if I want to be an I US developer, what other languages tools and software do you recommend? Learning Swift is definitely one that I would put high up there. Um But that really depends on the company, uh my current company and also at a lot of smaller or medium size start ups or just companies that tend to be less corporate. Um A lot of apps are built using Swift. Um Again, using my company as an example, Postmates, we require that you at least learn Swift prior to the interview to be able to pass if you give us solutions and objective C we'll say, OK, great. But you're not gonna pass, I'm so sorry, but for I OS in general, it's definitely valuable to also know objective c because a lot of companies, especially larger ones still use it, even my company still uses it for that 10% left with the code base. So it definitely helps to have familiarity. Fortunately, even if you don't know a specific language from my experience and for exactly what my um graduate research was on, the idea is if you know programming concepts, it should be fairly easy to start picking up new languages in the end, it's mostly just syntax.

So for I OS yes, definitely would recommend Swift and objective c um If you want to learn, sorry, this is assuming native I OS development. Um, if you would like, I would highly encourage you to build your own app as well. I found that was the best way to learn. It doesn't even need to be anything complicated. I believe the first app I built off of a tutorial was a calculator. Like it's a calculator, you know exactly what it's supposed to do. So you don't need to think about, oh, what features should it have? Like, what does it need to not have? It's a calculator. So, yeah. Mhm. Ok. Unfortunately, I think that might be all I have time for today. But thank you all again. Please feel free to connect and reach out. If you have any other questions, I'd be happy to connect with you. Right.