DEV Community

Cover image for What I realised after learning Python, TypeScript and Kotlin
Andrew Baisden
Andrew Baisden

Posted on

What I realised after learning Python, TypeScript and Kotlin

Remember all those people who kept saying that once you learn one programming/scripting language then it's not too difficult to learn another one? Well, they were telling the truth. I have known Javascript for years and I decided that I should expand my skillset even more because knowing more languages and being a polyglot just makes you better equipped to work in different roles. I would not say that I have mastered any of them yet as its only been a month or so but I have noticed that the languages share many similarities. Here are some examples below in each programming/scripting language.

Programming Syntax

Variables

Python

welcome = 'Hello World'

print(welcome)
Enter fullscreen mode Exit fullscreen mode

TypeScript

const welcome: string = 'Hello World';

console.log(welcome);
Enter fullscreen mode Exit fullscreen mode

Kotlin

fun main() {
    val welcome:String = "Hello World"
    println(welcome)
}
Enter fullscreen mode Exit fullscreen mode

Arrays/Lists

Python

my_arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]

print(my_arr)
Enter fullscreen mode Exit fullscreen mode

TypeScript

const myArr: Number[] = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];

console.log(myArr);
Enter fullscreen mode Exit fullscreen mode

Kotlin

import java.util.*

fun main() {
    val myArr = arrayOf(1,2,3,4,5,6,7,8,9,10)
    println(Arrays.toString(myArr))
}
Enter fullscreen mode Exit fullscreen mode

Objects/Dictionaries

Python

my_dict = {
    "id": "1",
    "username": "user01",
    "role": "developer"
}

print(my_dict)
Enter fullscreen mode Exit fullscreen mode

TypeScript

const myObj: { id: number; username: string; role: string } = {
    id: 1,
    username: 'user01',
    role: 'developer',
};

console.log(myObj);
Enter fullscreen mode Exit fullscreen mode

Kotlin

fun main() {
    val myObj = object {
        var id: Int = 1
        var username: String = "user01"
        var role: String = "developer"
    }
    println(myObj.id)
    println(myObj.username)
    println(myObj.role)
}
Enter fullscreen mode Exit fullscreen mode

Functions

Python

def add(x, y):
    return x + y


print(add(7, 3))
Enter fullscreen mode Exit fullscreen mode

TypeScript

function add(x: number, y: number) {
    return x + y;
}

console.log(add(7, 3));
Enter fullscreen mode Exit fullscreen mode

Kotlin

fun main() {
    fun add(x: Int, y: Int): Int {
        return x + y
    }
    println(add(7, 3))
}
Enter fullscreen mode Exit fullscreen mode

Control Flow: if statements

Python

coding_is_fun = True

if coding_is_fun:
    print('Learning to code is fun!!!')
else:
    print('Learning to code is not exciting...')
Enter fullscreen mode Exit fullscreen mode

TypeScript

const codingIsFun = true;

if (codingIsFun) {
    console.log('Learning to code is fun!!!');
} else {
    console.log('Learning to code is not exciting...');
}
Enter fullscreen mode Exit fullscreen mode

Kotlin

fun main() {
    val codingIsFun: Boolean = true;

    if (codingIsFun) {
        println("Learning to code is fun!!!")
    } else {
        println("Learning to code is not exciting...")
    }

}
Enter fullscreen mode Exit fullscreen mode

Loops

Python

shopping_list = ["Shower Gel", "Toothpaste", "Mouth Wash", "Deodorant"]

for item in shopping_list:
    print(item)
Enter fullscreen mode Exit fullscreen mode

TypeScript

const shoppingList: string[] = ['Shower Gel', 'Toothpaste', 'Mouth Wash', 'Deodorant'];

shoppingList.forEach((item) => {
    console.log(item);
});
Enter fullscreen mode Exit fullscreen mode

Kotlin

fun main() {
  val shoppingList = arrayOf("Shower Gel", "Toothpaste", "Mouth Wash", "Deodorant")

  for (item in shoppingList) {
      println(item)
  }

}
Enter fullscreen mode Exit fullscreen mode

Import Statements

Python

from flask import Flask
Enter fullscreen mode Exit fullscreen mode

TypeScript

// ES6 Import
import express from 'express'

// CommonJS
const express = require('express')
Enter fullscreen mode Exit fullscreen mode

Kotlin

import java.util.*
Enter fullscreen mode Exit fullscreen mode

Conclusion

This was just a sample there are more areas like Classes which I did not mention. When learning all of these different programming languages I noticed many common themes between them. For example the data types are very alike. The way that you assign variables for example feels very similar. Python just lets you write the variable welcome = 'Hello World' whereas TypeScript and Kotlin require you to assign it a type first. TypeScript being a superset of JavaScript essentially means that you are still compiling to JavaScript. So assigning const and let before you write your variables or var if you are writing it for ES5. In comparison Kotlin uses val and var for variable definitions with val being the equivalent to const as it is immutable and can't be re assigned. The way you write your syntax just feels so familiar so switching between languages is a breeze once you learn the fundamentals.

Also logging to the console is almost exactly the same. Python uses print() TypeScript uses console.log() and Kotlin uses println(). Python and Kotlin are almost the same which makes it easy to remember again. Creating Data Structures like Arrays/Lists, and Objects/Dictionaries is just as simple if you look at the syntax. Interchanging between languages is a breeze. Python Dictionaries look just like JSON so if you know JavaScript this syntax is familiar already.

I was also amazed to see that functions look very much the same. The caveat here being that Python does not use curly braces like TypeScript and Kotlin. Instead you use : and you have to be aware of the tab spacing otherwise your code won't compile.

The control flow is much the same writing if and else syntax works almost exactly the same in all three languages. And when it comes to doing looping you can clearly see that syntax for Python and Kotlin looks almost identical. One pretty big difference between the 3 is that Python uses snack casing for variables such as first_name whereas TypeScript and Kotlin use camel case like firstName.

Lastly import statements follow a familiar pattern across all 3 languages. I used to believe that learning too many programming languages would lead to yourself becoming confused as you have to remember all of these different syntax and you could find yourself in a scenario where you are writing Kotlin in JavaScript for example which I'm sure has happened to some developers at least once with multiple languages. But actually it just makes you a better coder as you begin to grasp the fundamentals of each language a lot better and your understanding of the core concepts deepens significantly.

So as you can see they are very much alike. Learning multiple languages definitely opens up more doors and allows you to progress further as a developer.

Top comments (12)

Collapse
 
codemouse92 profile image
Jason C. McDonald • Edited

Very true. But be forewarned, the similarities are often only syntax-deep. Identical-looking things in Python, Kotlin, and TypeScript, (such as arrays/lists, imports, logging, classes, objects, dictionaries) do not necessarily behave the same under the hood, in ways that can have a profound effect on the code's stability, maintainability, performance, and security. In fact, I can guarantee that Python and Typescript are scarcely comparable in terms of identical-looking behavior!

With any language, assume nothing. "False cognates" are everywhere.

Or, to put that another way, abstractions are there to save us typing, not to save us thinking. Know your abstractions.

Collapse
 
andrewbaisden profile image
Andrew Baisden • Edited

Well that may be true however I did say that I am still learning them so this post was not meant to be a deep dive into all the differences between the 3. Only my current impressions and what I have noticed so far. I am learning them for career progression and to further employment opportunities. If I was doing research then of course I would have chosen different languages to compare πŸ™‚

Also not everyone knows that they came from C-like families only someone who has knowledge in this area would have that information. A beginner who reads this would not know that.

Collapse
 
mjgs profile image
Mark Smith • Edited

Thanks for sharing your experience. It’s good to know these languages are easy to pick up.

One thing I found that was more difficult in some other languages was the tooling, documentation, setting up builds, how to structure projects, discovering libraries, managing dependencies etc. I found all these things much easier in the NodeJS / javascript ecosystem (though frontend js tooling is quite complex these days). This would be the biggest thing that would put me off from switching / learning a new language.

Collapse
 
eriklz profile image
Erik Lundevall Zara

Good start to explore different languages, I think that is something every developer should do! Even if you are not using different languages on a daily basis, expanding your knowledge in different languages will expand your toolkit and also make you think differently about how you solve problems. Different tools for different tasks. As you yourself note, knowing more programming languages will help solidify core concepts.

As others have commented, these specific languages (Javascript/Typescript, Kotlin, Python) are relatively closely related to each other. Difficulty in transition between them probably will more be around tools and frameworks and behaviour in specific areas, more than syntax.

I can recommend looking at the presentation Four languages from forty years ago for some examples of languages that have taken different approaches and also help with thinking about problems differently. It also shows that some features that are "new" in some of the more common languages today are in fact quite old things - for example, type inference that you can see in Kotlin and Typescript is something that already appeared in the 70s, in ML and that family of languages.

Collapse
 
thesnowmanndev profile image
Kyle Martin

Andrew,

Interesting read. I'm not sure what you meant by the title. I feel like I'm either missing something or you didn't fully write a conclusion that solidifies the title. Did you realize they share similar structure? Could you elaborate.

Thanks!

Collapse
 
andrewbaisden profile image
Andrew Baisden

Thanks for the feedback my initial intention was to just show the differences between the Syntax so you could see how they look quite similar. Like Python using print() and Kotlin using println() for logging data to the console. Anyway I decided to update the post I added a section for Import Statements and a very detailed conclusion so enjoy 😁

Collapse
 
michaelcurrin profile image
Michael Currin

Thanks for sharing. Nice to see them side by side.

Python 3 supports type hints as well which you can validate with mypy, in case you are interested in making your python code type-safe.

Collapse
 
andrewbaisden profile image
Andrew Baisden

Oh cool I did not know that I will check it out.

Collapse
 
michaelcurrin profile image
Michael Currin

I wrote a guide here for you to use michaelcurrin.github.io/dev-cheats...

Collapse
 
jonrandy profile image
Jon Randy πŸŽ–οΈ

Your variable naming in the "Loops" example is a bit weird - item would be preferable to items - which is confusing

Collapse
 
andrewbaisden profile image
Andrew Baisden

Thanks I fixed it.

Collapse
 
ambitiont109 profile image
Muramoto Hideyosi

Yes. Correct.
So there are these words in our friends. If you can assign value to a string, you can do program