I do both Kotlin and Python. More Kotlin than Python to be honest. But I'm pragmatic. Python is where all the action is when it comes to data science, llms, and all the rest. So it's the path of the least resistance. And there's a great argument to not challenge that and just do what everybody else does and put your head down and not criticize any of that. Which is why I use it on a few projects. The library ecosyste…
Kotlin just needs some stubborn people not to use python just because everyone else does, and build up the Kotlin ecosystem. That's how progress is made.
Kotlin for data analysis
71–80 of 105 posts
Re: Kotlin for data analysis
#72I do both Kotlin and Python. More Kotlin than Python to be honest. But I'm pragmatic. Python is where all the action is when it comes to data science, llms, and all the rest. So it's the path of the least resistance. And there's a great argument to not challenge that and just do what everybody else does and put your head down and not criticize any of that. Which is why I use it on a few projects. The library ecosyste…
Re: Kotlin for data analysis
#73I do both Kotlin and Python. More Kotlin than Python to be honest. But I'm pragmatic. Python is where all the action is when it comes to data science, llms, and all the rest. So it's the path of the least resistance. And there's a great argument to not challenge that and just do what everybody else does and put your head down and not criticize any of that. Which is why I use it on a few projects. The library ecosyste…
I'm not sure how someone could see Kotlin as more expressive than Python, unless I am misinterpreting what expressive means. Python has a good language features and helpful abstractions like list comprehensions. What makes Kotlin more expressive? I understand it has some functional features but I've never seen anything dramatically flexible.
Personally, I see Kotlin as the closest thing to a statically typed Smalltalk that we have among major languages, and that's a major draw.
A key part here is that Kotlin closures are fully-featured equivalents of Smalltalk blocks (up to and including even non-local returns [1]), whereas in many other languages that falls short. Java does not allow mutation of local variables and Python restricts lambdas to normal expressions.
I find code whose behavior can be parameterized by code to be an essential feature of modern-day programming and this should be as frictionless as possible.
This is also a situation where syntax matters, and while it isn't quite as nice as Smalltalk, Kotlin's syntax (esp. with trailing closures) make such code as readable as possible in a brace-style language with minimal additional syntactic noise.
In a similar vein, the functionality of Smalltalk's cascades is offered through scope functions [2], especially `.run {}`.
But ultimately, fully-featured closures (and the fact that they are widely used in the standard library) power a lot of the things that people seem to like about Kotlin.
That does not mean that there aren't downsides. The limitations of running on the JVM are one (e.g. while Kotlin has workarounds for the JVM's type erasure, they're still workarounds), and then Gradle is arguably Kotlin's weakest point (which apparently even JetBrains are seeing, given their investment in Amper).
That said, personally I'd say Kotlin's static typing and performance would be the primary reasons for me to reach for Kotlin over Python, not necessarily expressiveness. Type annotations in Python + mypy etc. just aren't the same experience, and writing performance-sensitive code in Python can be very tricky/hacky when you can't delegate the hot paths to numpy or other existing C/C++/Rust libraries.
Conversely, Python often has a leg up when it comes to fast prototyping and scripting, even with Kotlin Worksheets in IntelliJ IDEA and with kscript.
[1] Which, to be clear, are a nice-to-have thing, not essential, but still impressive that even that was covered, when previously Ruby was the only major language I know of that did it.
Re: Kotlin for data analysis
#74Kotlin Notebooks are supported only in the Ultimate version of IDEA
> For other Jupyter clients, you'll need to install the Kotlin Kernel separately using conda, pip, or sources.
I think `pip install kotlin-jupyter-kernel` is all you need to add Kotlin to a standard Jupyter environment. I don't know if editors can deal with this stuff, though.
Re: Kotlin for data analysis
#75My issue with Kotlin is the same as my issue with Groovy. Both are interesting and definitely something new, but... under the hood it's JVM and come with the Java baggage. Some see it as an advantage, I see it as a burden. My clients are using mostly Python and Golang and I have grown to like simple toolchains and the results I am getting. Another point against Kotlin is the fact that my clients like to keep things s…
Also, practically it's only really viable to use IntelliJ as editor, since the language server in e.g. VS Code is pretty bad.
Re: Kotlin for data analysis
#76Earlier quoted context omitted.
> the 'yield' keyword Am I missing something here? $ cat fib.kts fun fib() = sequence { var a = 1; var b = 1 while (true) { yield(a) a = b.also { b += a } } } println(fib().take(10).joinToString(" -> ")) println(fib().first { it >= 50 }) $ kotlin fib.kts 1 -> 1 -> 2 -> 3 -> 5 -> 8 -> 13 -> 21 -> 34 -> 55 55 Of course, yield() is a function in Kotlin, not a keyword, but the same functionality is there.
The mechanism in Kotlin that allows them to limit yield() to a sequence{} block , without introducing a new keyword, is pretty dang cool.
The actual functionality is then provided by the coroutine system, though a lot of the heavy lifting is done by the optimizer to eliminate all or most of the runtime overhead.
Re: Kotlin for data analysis
#77My issue with Kotlin is the same as my issue with Groovy. Both are interesting and definitely something new, but... under the hood it's JVM and come with the Java baggage. Some see it as an advantage, I see it as a burden. My clients are using mostly Python and Golang and I have grown to like simple toolchains and the results I am getting. Another point against Kotlin is the fact that my clients like to keep things s…
Re: Kotlin for data analysis
#78Earlier quoted context omitted.
That's interesting. I've heard complaints about Kotlins standard library in comments like this[1]. I understand they may be nitpicks but they seem annoying in practice. [1] https://www.reddit.com/r/Kotlin/comments/mh2z5u/comment/gt2n...
Hmm, coroutines are definitely a bit of a mess, but in ways that aren't super relevant when you just want to use them and not implement a framework on top of them. They definitely sacrificed implementation simplicity in favor of interface simplicity. > don't even try to tell me that anyone uses sealed classes in practice I use sealed classes for errors all the time. > Nothing is concurrency safe. Yes, but I know of n…
Re: Kotlin for data analysis
#79Earlier quoted context omitted.
Kotlin's standard library has ruined me for other languages, especially its collections library. The consistency and comprehensiveness of its approach to collections is unmatched in any language I've tried, including all the big name functional languages. It's hard to get across what's so great about the library in writing because it's not just one standard library function, it's how they all interact with each other…
Couldn't agree more if I tried. Scope functions are also great. And the syntactic sugar where `foo({ a -> a })` and `foo { a -> b }` are the same makes code so much more readable. I've done Python for a project at a previous job for a few months and it made me realize just how awful Python is, especially because you can't chain functions on collections as easily as you can in Kotlin. I also made me realize that I don…
They are useful but I'm not sure they carry their weight. I have to look up the differences often, maybe they're just terribly named?
Re: Kotlin for data analysis
#80Earlier quoted context omitted.
As someone who uses Kotlin for work and Python for side projects (and loved Python years ago in college), Python's list comprehension feature is one of the things I hate the most about the language now. As a simple example using only two collection functions I find it much easier to read val hundredOrLessEvenSeconds = (1..1000) .toList() .filter { it than hundred_or_less_even_seconds = [timedelta(seconds=it) for it i…
Not that I especially want to defend Python, but can you elaborate a bit on why you find that chain easier to read? The Python version is straightforward enough - if it's just the absence of newlines you can write hundred_or_less_even_seconds = [ timedelta(seconds=it) for it in range(1, 1001) if it Also, I don't know Kotlin well enough, but is what you wrote going to be efficient? The Python version iterates once and…