Live data from Hacker News

Swift is like Kotlin

nilhcem.com

281–290 of 364 posts

Re: Swift is like Kotlin

#281

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…

Maybe you haven't checked out Kotlin lately? Kotlin has somewhat pattern matching: https://kotlinlang.org/docs/reference/control-flow.html#when... Tail call optimization: https://kotlinlang.org/docs/reference/functions.html#tail-re... Type classes: https://kotlinlang.org/docs/reference/sealed-classes.html And I'm not sure what you mean by recursive data structures. Basically every C style language I'm aware of can co…

> Type classes: https://kotlinlang.org/docs/reference/sealed-classes.html

Those are not type-classes, at least not in the Haskell sense. They allow you to avoid an else branch, yes, which is actually quite useful; but one basic ability they're missing is the ability to define a new branch for a new instance of the type defined by library users.

Just as an example. They're really not much like type-classes at all.

Re: Swift is like Kotlin

#282
post #46
post #35

Earlier quoted context omitted.

As an alternative opinion, I personally hate when ranges are exclusive by default. In addition to it feeling somewhat unintuitive to me that I need to use range(0, 6) to include 5, it also makes downward ranges quite awkward, e.g. needing range(5, -1) to count from 5 to 0.

Exclusive by default is designed to fit with 0-based indexing (0..length(v), instead 0..(length(v)-1)). That said, this thinking is less relevant in languages with iterators/ranges and doubly so ones that offer a way to explicitly, but abstractly, iterate over the indices of a vector/array. On the point of downward ranges, you can often reverse the range explicitly, rather than swapping the endpoints, like reversed(r…

I understand the benefits, I just personally don't prefer it. But this is just my subjective opinion.

Re: Swift is like Kotlin

#283
post #270

I find it very annoying that Google and Apple are creating new languages to solve similar problems and not worrying about cross platform. If you write for Apple you've been told to use Objective-C and Swift. If you're on Android it's Dart and now Kotlin. None of that stuff is used for Windows or Linux development or even mobile on the other OS. I'm not a fan of proliferation of "platforms" but when it goes beyond lib…

Imagine having just one programming language where there is likely one gatekeeper. I doubt language innovation would happen with that setup.

Imagine having hundreds of languages with only trivial difference in syntax. Consider the fragmentation and effort wasted on re-inventing the same low level libraries again and again (here is the hundredth version of unit test library). Sure, only language would be bad but so is too many.

Re: Swift is like Kotlin

#284

Earlier quoted context omitted.

> Here in Ukraine it would be very hard to get adoption of a programming language that is named after a Russian military base. This sounds really stupid, considering that many Ukrainian programmers are already using JetBrains products and that punishing a great company for the actions of politicians is kind of sad.

Would you work in a programming language called Hitler? Any multinational company needs to do their research before deciding on a name.

Well, you already have java formal verification tool named Bandera http://bandera.projects.cs.ksu.edu/people.shtml (which name is obviously choosen by Oksana Tkachuk, one of the tool authors)

Re: Swift is like Kotlin

#285

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…

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 structures which is why I mistakenly used that term instead of ADTs.

TCO: glad to see I was wrong. Kotlin added support for this in the past year.

Android: I realize that to support Swift on Android, Google would need to do significant work, but they wouldn't have to change the VM since Swift could also be compiled to Dalvik bytecode. But obviously that would be a lot of work. I only mention Swift since there were rumors in the past that Google was considering fully supporting Swift on Android.

Plus, to be clear, you can run Swift on Android now using the native SDK, just not on Dalvik for making GUI apps.

Re: Swift is like Kotlin

#286

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.

Re: Swift is like Kotlin

#288
post #73

Earlier quoted context omitted.

Why is it a..b instead of the logical a..=b or a..<=b?

You only need to know that the language handles one explicitly, since there's two choices, so you might as well take the (more common | uglier to express) case and give it the "cleanest" special syntax: no special syntax.

[deleted]

Re: Swift is like Kotlin

#289

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.

Yes, and immutability! Kotlin has not much support for this, unless it's also been added in the past year.

Both Clojure and Scala that run on JVM have strong support for immutability, so it's quite possible on the JVM.

And yes, Swift has let binding, and other features to support immutability.

Re: Swift is like Kotlin

#290
post #270

Earlier quoted context omitted.

Imagine having just one programming language where there is likely one gatekeeper. I doubt language innovation would happen with that setup.

Imagine having hundreds of languages with only trivial difference in syntax. Consider the fragmentation and effort wasted on re-inventing the same low level libraries again and again (here is the hundredth version of unit test library). Sure, only language would be bad but so is too many.

If a language has trivial difference from another language, I doubt it can gain traction.

Can you cite an example?

Post reply on HN