Live data from Hacker News

Swift is like Kotlin

nilhcem.com

301–310 of 364 posts

Re: Swift is like Kotlin

#301
post #294

Earlier quoted context omitted.

pattern matching: swift has switf and kotlin has when, both are very similar recursive data structures: I don't get this one, kotlin has all the java api available and all the third party libraries. As java has been here for much longer than swift I guess that swift is lacking more here than kotlin. Tail call optimization: kotlin has the special word tailrec for this Yes, kotlin has a lot of things. It also has co-ro…

> Scala needs to add a runtime when compiling to bytecode This is nonsense? It doesn't need any more "runtime" than Kotlin does. > it is not fully compatible with java as kotlin. This is a lie. (I don't say this lightly, but I've seen it too often from too many kotlin advocates for it to be an innocent mistake)

> Scala needs to add a runtime when compiling to bytecode

Last time I checked you needed like 500kb of libraries for any scala program compiled to Android. Kotlin is a few kb. Kotlin is a small addition to the java API, Scala needs much more things.

> it is not fully compatible with java as kotlin.

As far as I know, the way scala treats types and functions make it that sometimes you cannot call scala code from java. Well, you can most times but requieres a lot of wrappers. This doesn't happen in kotlin.

I learn scala few years ago, my memory is weak and things may change. But I wanted to use it for android and give up quite quickly because of lot of issues. For kotlin was like love at first sight. No problems at all.

Re: Swift is like Kotlin

#302

Earlier quoted context omitted.

pattern matching: swift has switf and kotlin has when, both are very similar recursive data structures: I don't get this one, kotlin has all the java api available and all the third party libraries. As java has been here for much longer than swift I guess that swift is lacking more here than kotlin. Tail call optimization: kotlin has the special word tailrec for this Yes, kotlin has a lot of things. It also has co-ro…

Pattern matching: Kotlin has a `when` that desugars into if when statements, but it's pretty far from pattern matching like you see in Scala, Swift, and more traditional functional languages. Recursive data structures: Yeah, for some reason I wrote recursive data structure when I was thinking of algebraic data types, like Scala can encode with case classes. I often use them in Scala or OCaml to make recursive data st…

> Kotlin has a `when` that desugars into if when statements

Actually not. Not now, probably it was the case at the begining of the language.

> algebraic data types

they removed some restriction of sealed classes in 1.1. So I am not sure this is true anymore.

The memory management in Swift is completely different than in Java. That is the main reason you need to make changes in the virtual machine. JVM uses the garbage collector while swift uses reference counter.

Re: Swift is like Kotlin

#303

Kotlin lacks the ability to do true functional programming that Swift has. Swift has pattern matching, recursive data structures (edit: specifically ADTs with enums or case classes is what I was thinking of here, should have written algebraic data types), tail call optimization, even some form of type classes, immutability (thanks @tmail21), and so on. Kotlin does not have any of these (edit: this is now partly false…

What about immutability? A key part of functional programming is using immutable structures to avoid side effects. My understanding is that Swift has these to some extent ("let" vs "var", structs being immutable etc). And since Kotlin is built on JVM compatibility I _assume_ that Kotlin does not support an immutable style of programming. Maybe someone here has more clarity on this.

You can have immutability by making the setters methods of a class private. So if you combine it with "val" you have immutable objects. It is a bit more job in kotlin but as it is also object oriented programming you can achieve exactly what you want.

And for structures you have list, mutablelist, map, mutablemap, etc.

What else do you want?

Re: Swift is like Kotlin

#304

I've never really heard of Kotlin, is it supposed to be a Java replacement?

Yes, it runs on the JVM and is 100% compatible with Java code. While it was fairly easy to use Kotlin with Android before, Google just announced first-class support for it at IO.

Re: Swift is like Kotlin

#305

Does anyone else think the Kotlin syntax for array literals is super ugly: val shoppingList = arrayOf("catfish", "water", "tulips", "blue paint") What is wrong with square bracket syntax? (rant over). EDIT: I suppose it's consistent with other syntax e.g. listOf() etc.

First thing I noticed. The map entry syntax:

"Foo" to "Bar"

Is also nonsensical. What's wrong with ':'?

Re: Swift is like Kotlin

#306

Earlier quoted context omitted.

What about immutability? A key part of functional programming is using immutable structures to avoid side effects. My understanding is that Swift has these to some extent ("let" vs "var", structs being immutable etc). And since Kotlin is built on JVM compatibility I _assume_ that Kotlin does not support an immutable style of programming. Maybe someone here has more clarity on this.

You can have immutability by making the setters methods of a class private. So if you combine it with "val" you have immutable objects. It is a bit more job in kotlin but as it is also object oriented programming you can achieve exactly what you want. And for structures you have list, mutablelist, map, mutablemap, etc. What else do you want?

Looks like there is some distinction between Mutable, Read-only View and Immutable.

According to this http://stackoverflow.com/questions/33727657/kotlin-and-immut... Kotlin does not support true immutability.

For immutability to be practical one would need to implement structural sharing in their collections otherwise copying would be prohibitively expensive.

This Java library seems to be trying to implement this. http://www.vavr.io/

Again, I am not saying that Kotlin does not support immutability, just trying to get to the bottom of the reality of it.

Re: Swift is like Kotlin

#307
post #67

Earlier quoted context omitted.

Yes, agreed. IMO, curly braces would have made much more sense. It's not even bikesheding, really. It's just a fact that curly braces are less used in most written languages. I would also argue that curly braces are a better signal to the programmer that "something programmatic is happening here", due to their prevalence as scope delimiters in most popular languages. Swift's string interpolation doesn't catch my eye…

I definitely think a general guideline for language designers could be "when in doubt, make it look like Ruby". The language has its issues, sure, but damn if it didn't get syntax just right .

I think we will have to agree to disagree on this. Personally, Ruby code is only marginally better than Perl in terms of line noise I can't read, a dubious distinction.

Re: Swift is like Kotlin

#308

Earlier quoted context omitted.

Sure thing... When will Jetbrain have a decent interface builder? Decent instrumentation? Decent documentation viewer? Can you get an object graph with JetBrains? Xcode isn't perfect, but it's way better than JetBrains. Just because one has one feature that one doesn't have, doesn't mean that Xcode beats JetBrain's IDE all day.

Nobody should be using IB at all for iOS development. Ever.

I'm an indie iOS developer, I do what I want, I use IB, it's excellent!

Re: Swift is like Kotlin

#310

Kotlin lacks the ability to do true functional programming that Swift has. Swift has pattern matching, recursive data structures (edit: specifically ADTs with enums or case classes is what I was thinking of here, should have written algebraic data types), tail call optimization, even some form of type classes, immutability (thanks @tmail21), and so on. Kotlin does not have any of these (edit: this is now partly false…

Well, Google has to do extremely little to support Kotlin, as it runs on the JVM, does so fairly leanly, and does so on Java 6 JVMs.

Swift, they'd have to redo just about their entire stack, as Swift doesn't run on the JVM (Swift can be used with the NDK to build NDK libraries, but it's not standard to build a full app, outside of games, with that).

Scala has had big issues with the size of it's library that still haven't been resolved, and the new versions of Scala require Java 8, which only the beta version of Android supports right now.

Post reply on HN