Elektrine lite

← Feed

@bd103@hachyderm.io

Post #944799

2026-02-25 05:09 UTC

I've been learning Swift recently, and I'm honestly surprised by how similar it is to Kotlin! Both have the feature where, when passing a closure as a final argument to a function, you can place the closure after the function call to get a DSL-like effect. Beyond that, they also have getters and setters that masquerade as plain variables, really good support for nullable types, and what seems to be a similar approach to concurrency through tasks. #swift #kotlin #programming

Replies (2)

  • @bd103@hachyderm.io 2026-02-25 05:34

    There are some things about Swift that I still haven't gotten over, however. I dislike the distinction between function argument labels and parameter names. In essence it lets you have two different names for a function argument: a user-facing name and an internal function body name. This feature infiltrates the syntax of Swift, and makes function definitions more difficult to read in my eyes. Additionally, the concept of a "mutating method" seems very tacked-on to me. By marking a structure's method as `mutating`, you enable it to modify the properties of the structure instance. This feels like something that was almost added as an afterthought; it feels like there was a bit of influence from Rust here, although I don't know if that's actually the case. Either way, it feels like a weird spot of the language that doesn't *quite* fit with the rest. And finally, trying Swift has given me a new appreciation for Rust's fantastic error messages. Writing Swift in Xcode as a beginner, I found it a lot harder to debug compiler errors because: - Error have a line number, but not column range, so it is harder to diagnose what section of a line is causing the issue. - Errors do not link to documentation nor have a stable error code that I can Google. Having an example of what causes the error and how to fix it is super valuable! Don't get me wrong, Swift is still a nice language to work with! I certainly prefer it over Objective-C and C++, and SwiftUI's composability has worked wonders in code organization, but it certainly has made me appreciate things I take for granted in the Rust ecosystem. #swift #rust

    Open ##2387923

  • @ctietze@mastodon.social 2026-02-25 06:46

    @bd103@hachyderm.io Swift also recently got the `cool function name` thing that I envied Kotlinners for

    Open ##2387924