Live data from Hacker News

Kotlin for data analysis

kotlinlang.org

101–105 of 105 posts

Re: Kotlin for data analysis

#101
post #27

Earlier 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…

> it looks like the Kotlin version is going to do more iteration and make four separate lists.

Someone with kotlin experience could comment too, But I don't think it creates four separate lists. The last map function iterates and asks for element from previous function which asks for element from its parent function. So there is only one list.

Re: Kotlin for data analysis

#102
post #96

Earlier quoted context omitted.

What if you want to filter on the mapped value in python? Or group by something and work further on the groups? It's almost unreadable after a few operations.

In that case I think the "Pythonic" thing to do would be to have some named intermediate steps: foos = (make_foo(bar) for bar in bars) acceptable_foos = (foo for foo in foos if acceptable(foo)) ... Depending on your circumstances, this may or may not be awkward (coming up with temporary names can be hard), or may or may not be a good idea anyway (naming things can help make the code more self-documenting). I can't re…

That's kinda my point, though. It becomes either awkward or unreadable. You chose awkward in your solution. But simple things as mapping, sorting, filtering quickly becomes unwieldy. Either you have to make it lots of unnecessary steps, potentially also lots of function definitions because of the lack of proper lambdas, or you end up with filter(groupby(map(filter(...)))) trying to figure out what is going on.

Re: Kotlin for data analysis

#103
post #65

Earlier 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…

> `foo({ a -> a })` and `foo { a -> b }` are the same

I am new to kotlin, so I may be missing something obvious, but shouldn't it be "a->a" in the 2nd case, too?

Re: Kotlin for data analysis

#104

Earlier quoted context omitted.

Yes but it's reasonable that they didn't. For quick hacky scripts you really want a lightweight syntax that supports interactive REPL exploration. Kotlin is the first language that manages to combine a strict static type system with a Python-weight syntax, and there's a REPL too although I don't think it gets much use. These days notebooks are a better replacement for REPLs anyway when doing data analysis, but Kotlin…

Kotlin isn't the first language offering any of these features, not even remotely. Even if you look only at the JVM: Scala is much older.

Haskell and SML are even older.

Re: Kotlin for data analysis

#105
post #103
post #65

Earlier quoted context omitted.

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…

> `foo({ a -> a })` and `foo { a -> b }` are the same I am new to kotlin, so I may be missing something obvious, but shouldn't it be "a->a" in the 2nd case, too?

You're right, my brain farted somewhere in the middle.
Post reply on HN