r/ProgrammerHumor • • Jul 20 '18

Every Time

Post image
52.2k Upvotes

749 comments sorted by

View all comments

Show parent comments

128

u/mpa92643 Jul 20 '18

Python is wonderful, but the lack of static typing drives me crazy sometimes (which is why I fell in love with Kotlin: best of both worlds). It's almost never a problem, but when the IDE can't tell me, "yup, that's definitely a string, here are all the things you can do with it" and instead tells me "yup, that's definitely some kind of object. Here's a list of functions you've used on it before, including your typo-ed ones, just try something and you'll find out if it actually works at runtime."

0

u/[deleted] Jul 20 '18

[deleted]

58

u/mpa92643 Jul 20 '18

It's exploding in use now that it's officially supported by Google for Android programming. It also forces Java best practices by default, which leads to cleaner code. I don't ever want to go back to Java after becoming familiar with Kotlin.

0

u/[deleted] Jul 20 '18

[deleted]

49

u/strike01 Jul 20 '18

I almost thought that "No" is a programming language

0

u/[deleted] Jul 20 '18

[deleted]

0

u/[deleted] Jul 20 '18

[deleted]

2

u/rolo90 Jul 20 '18

but...typescript!

7

u/mpa92643 Jul 20 '18

Yeah, Google's policy seems to be "throw everything at the wall and hope something sticks, and occasionally just throw stuff away that people like." Kotlin is developed by JetBrains though and has been around for 7 years already, and they have a strong interest in keeping it around now that it has first-class support on Android. It's even got coroutines now, which are extremely useful in reducing callback hell on Android.

There are a ton of major Android apps and developers that have been using Kotlin in their codebase for years (since they can safely mix Kotlin and Java without having to rewrite any of their codebase), and lots of major libraries are adding Kotlin extensions to their code since it makes writing code so much easier and more concise.

→ More replies (1)

2

u/coshjollins Jul 20 '18

Android is really the driving force behind why it's catching on. At first I was a bit angry because I had spent so much time learning android dev in java, but kotlin seems easy enough to transition to and seems to keep the same structures

2

u/mpa92643 Jul 20 '18

It's definitely worth it. You don't even have to completely redesign your codebase. Just start writing new code in Kotlin. You can keep using all your old code in Kotlin, and you get extremely useful protection against nulls. Basically, you'll never have to write a null check ever again. That alone makes it worth the switch.

Check out this article that explains pretty concisely why the switch is worth it. Kotlin is essentially everything good about Java without the boilerplate and backwards-compatibility limitations.

→ More replies (1)

2

u/bradbrok Jul 20 '18

Dude, Kotlin is the best! Interoperability with Java is kind of incredible, and IntelliJ has world class IDE support for it.

0

u/[deleted] Jul 20 '18

[deleted]

2

u/coshjollins Jul 20 '18

I didn't know people liked it so much until this thread.

4

u/profbalr Jul 20 '18

Is there something equivalent for Python like Typescript for JS? I had the same issue with JS but recently picked up Typescript and it really changes the language.

2

u/mpa92643 Jul 20 '18

There are type hints for Python that can give you (and the IDE) an idea of what type an object can be expected to be, but it's no guarantee that the object will actually be of that type since Python is duck-typed.

→ More replies (1)
→ More replies (1)

3

u/anders987 Jul 20 '18

That depends on which IDE you use. Visual Studio Code knows that it's a string.

→ More replies (4)

1

u/Flatscreens Jul 20 '18

Are type hints close enough?

1

u/mpa92643 Jul 20 '18

They help, but like their name, they're only hints. It's pretty easy for the object to be set as something else accidentally. It gives you an idea of what type to expect for a variable, but you have no guarantee that it will actually be that type at runtime.

1

u/miran1 Jul 20 '18

Python is wonderful, but the lack of static typing drives me crazy sometimes

If you want Python-like syntax (including the significant whitespace) with static typing, give Nim a try. (As a bonus, you get C-like speed!)

→ More replies (2)

1

u/tinman_inacan Jul 20 '18

Oh hey have I got something for you. I’ve been using PyCharm IDE for a few months now and what you’re describing has always bothered me, but I recently discovered that providing type hints will provide the wanted behavior most of the time.

For example:

def foo(bar: str=“hello”) -> int:

Now when you reference bar, the IDE will treat it as a string object and give you the proper methods. Same with any object type, even those from external libraries! You can also do it during assignment.

You’ve also provided the expected return type as well, so if you call the function you can see the right methods for the return type.

The only problems I’ve found it that it can make the code look less pythonic and you cannot type hint in control flow or loop definitions.

1

u/z0mbietime Jul 20 '18

FWIW Python introduced dataclasses which offer optional static types

→ More replies (2)