News for hackers. Stuff that matters.
Re:Highlights of new technologies introduced at WWDC 2021 by nxc18 on Monday June 07, 2021 @06:24PM (#27428016)
As someone preparing to transition from C# to Swift dev, async/await was a big missing piece. I’ll be curious to see how quickly the ecosystem picks it up as I move forward on my journey.

My experience interacting with teams and devs targeting Swift is that when Apple says “jump” you jump.

What do people already using Swift in production think?

Re:Highlights of new technologies introduced at WWDC 2021 by travisgriggs on Tuesday June 08, 2021 @01:01AM (#27430802)
I'm trying to figure out where Swift is going. I maintain 3 relatively complex apps in it. When I first started coding on iOS, it was objective C. Objc was a poor mans Smalktalk, and when that didn't scale you did some inline C. Being quite familiar with Smalltalk and C, I was comfortable with this two basic computing models (everything's an object OR pointer/stack machine), I just had to do the Frankenstein dance of knowing when to employ how much of which.

With Swift, I have a hard time getting a feel for what the unifying gestalt of the language is supposed to be. It's a better C! It's objects! It's functional! It's typesafe! It's protocols! It's async! It's closures! It's a better C++! It's modern! It's a systems language! It's a scripting language! It's for UIs! It's actors! It's declarative! It infers things!

I get stuff done with it (obviously) and it's capable, but the effect has not been "it's a bird, it's a plane, it's Superman." It feels like some sort of anime shapeshifter caught in a cycle sometimes. Or a bogart.

I keep hoping these are growing pains, intermediate steps, with a "long game" characteristic of Apple, but I'm not seeing it yet.

Kotlin seems to be following a similar path, just a few steps behind in some places, and a few steps ahead in other.

Re:Highlights of new technologies introduced at WWDC 2021 by pjmlp on Tuesday June 08, 2021 @09:56AM (#27435268)
A common trait to any multi-paradigm language, I fail to see the problem.

In fact, you could state the same complaints against Turbo Pascal on the MS-DOS days.

Re:Highlights of new technologies introduced at WWDC 2021 by SirensOfTitan on Monday June 07, 2021 @07:05PM (#27428463)
I worked with Swift extensively for a year and a half, and I absolutely adore the language. I think it does a lot right while avoiding more of rust's complexities (I am a rust n00b, so grain of salt).

The problem with Swift (as of like 1.5 years ago when I stopped using the language daily) was its ecosystem. Swift package manager wasn't really used (at least for iOS apps), there was no real decent ecosystem outside the xcode world (no langserver, some server-side swift abstractions).

I think Swift would really thrive if Apple were to give it some room to breathe in the open source community, but until Swift decouples itself more from Apple's own needs, I couldn't imagine using it for anything other than iOS development.

Re:Highlights of new technologies introduced at WWDC 2021 by armchairhacker on Monday June 07, 2021 @07:53PM (#27428884)
Two of my favorite languages are Swift and Kotlin. I basically always choose Kotlin, but I would actually like Swift more if it was supported more outside of Apple.

Swift has the benefit of actual value types, no GC, and IME it's much faster. But it only runs on Apple's OS (technically there's support for Linux but people say it isn't good). Kotlin has access to all Java packages and runs on the JVM, and with Kotlin multiplatform JetBrains is trying to make it run on almost anything.

Re:Highlights of new technologies introduced at WWDC 2021 by pjmlp on Wednesday June 09, 2021 @06:08AM (#27446195)
JetBrains will discover the pains of embracing multiple platforms.

Outside Android, Kotlin will always be playing catch-up with platform features, having two ways of doing the same thing for features introduced before the platform went their own way, FFI that only goes one way, the native variant is being redone due to the clever idea of being originally incompatible with JVM memory model, it is officially a way to sell InteliJ licenses.

Re:Highlights of new technologies introduced at WWDC 2021 by jolux on Monday June 07, 2021 @08:08PM (#27429005)
Swift is currently reference counted, which is more or less GC but worse because it’s not tracing/cycle-detecting.
Re:Highlights of new technologies introduced at WWDC 2021 by favorited on Monday June 07, 2021 @08:23PM (#27429144)
Every design decision has tradeoffs. RC has its own significant upsides, like deterministic deallocation and a much lower memory floor for preventing world-pauses during tracing.
Re:Highlights of new technologies introduced at WWDC 2021 by pjmlp on Tuesday June 08, 2021 @09:59AM (#27435306)
And possible stack overflow or freezing applications, when a domino effect of reference counting reaching 0 happens, and dealloc functions weren't properly written.

There is a Herb Sutter talk at CppCon about the downsides of reference counting.

Basically the solution to those problems is to make use of hazardous pointers or deferred destructions on background threads, which are a kind of lightweight tracing GC.

Re:Highlights of new technologies introduced at WWDC 2021 by jolux on Monday June 07, 2021 @09:40PM (#27429689)
How is RC deallocation deterministic?

Besides which I don't want to have to keep track of weak references, at that point I would rather just have a full ownership model: https://github.com/apple/swift/blob/main/docs/OwnershipManif...

Re:Highlights of new technologies introduced at WWDC 2021 by bjustin on Monday June 07, 2021 @10:06PM (#27429852)
I assume the grandparent was talking about how, as soon as the last reference to a refcounted object goes away, the object is deallocated. Pure Swift follows this rule though Objective-C code may not always do this due to things like autorelease pools.
Re:Highlights of new technologies introduced at WWDC 2021 by jolux on Tuesday June 08, 2021 @01:01AM (#27430804)
Sure but that's nothing like deterministic destruction, where I can tell you the order that things will be deallocated just from looking at a block.
Re:Highlights of new technologies introduced at WWDC 2021 by sjm on Monday June 07, 2021 @09:23PM (#27429579)
No langserver? SourceKit LSP has been around for a while now: https://github.com/apple/sourcekit-lsp
Re:Highlights of new technologies introduced at WWDC 2021 by moj on Monday June 07, 2021 @07:57PM (#27428917)
Yes, async/await will be terrific. It's been a long time coming though; I've been expecting it 'real soon now' for over 3 years: https://gist.github.com/lattner/429b9070918248274f25b714dcfc...
Re:Highlights of new technologies introduced at WWDC 2021 by singularity2001 on Tuesday June 08, 2021 @03:47AM (#27431686)
Async await is the mistake of the decade. Not the concept of concurrency but the function coloring approach. See previous discussions for why this is such a bad idea. In short: concurrency belongs on the caller side, not the callee side. Go does it right, most others follow the dark path.
Re:Highlights of new technologies introduced at WWDC 2021 by dkdbejwi383 on Tuesday June 08, 2021 @03:42PM (#27439833)
Interesting argument, do you have any links to said discussions on this topic?
Re:Highlights of new technologies introduced at WWDC 2021 by smw on Wednesday June 09, 2021 @01:50AM (#27444643)
Re:Highlights of new technologies introduced at WWDC 2021 by dkdbejwi383 on Wednesday June 09, 2021 @04:39AM (#27445610)
Appreciate it!
Re:Highlights of new technologies introduced at WWDC 2021 by myko on Monday June 07, 2021 @09:12PM (#27429505)
I still don't understand why I'd want to use async/await in a mobile/desktop app over something like Rx (Combine). Is there a good rundown on when to use one or the other?
Re:Highlights of new technologies introduced at WWDC 2021 by guacaswole on Tuesday June 08, 2021 @06:17AM (#27432761)
I wondered the same thing actually. After I read about async await I thought “Well, what’s the point in Combine then?”
Re:Highlights of new technologies introduced at WWDC 2021 by akmarinov on Tuesday June 08, 2021 @12:57PM (#27437724)
It’s your choice - you want Rx - you do Rx. Everyone gets something.
Re:Highlights of new technologies introduced at WWDC 2021 by myko on Wednesday June 09, 2021 @10:24AM (#27448216)
Yes but my question is more about what tradeoffs should I be looking for to decide which to use. There does not seem to be a simple way to bridge the worlds, so deciding early is probably necessary.

From what I'm gathering I should stick to Rx (Combine) when I have multiple related tasks or want to fire off changes in response to events, whereas async/await is useful for one-off asynchronous tasks like most web requests? I'm really not sure.

Re:Highlights of new technologies introduced at WWDC 2021 by elpakal on Monday June 07, 2021 @10:13PM (#27429881)
also interested in async vs combine, but i’m the other way around - unless you want to fight for rx programming i see Combine being in a very weird place. it looks like existing Foundation stuff will be easy to change to async, and for teammates without rx experience Combine can be a big mental model shift. plus Combine doesn’t compile on Linux, which is a big deterrent for me when thinking about how I might want to approach a Swift command line app.
Re:Highlights of new technologies introduced at WWDC 2021 by dmitriid on Tuesday June 08, 2021 @02:36AM (#27431290)
async/await are trivial to understand and use.

Anything Rx beyond the simplest of examples? Nope.

Re:Highlights of new technologies introduced at WWDC 2021 by myko on Wednesday June 09, 2021 @10:25AM (#27448241)
Rx is very powerful and can be difficult to understand at first, especially if you haven't done a lot of programming in functional languages before.

I'm not trying to argue about that though - I just want to know under what set of circumstances I should prefer async/await over Rx and vice versa.

Re:Highlights of new technologies introduced at WWDC 2021 by Pulcinella on Monday June 07, 2021 @07:02PM (#27428423)
We build a lot of REST based apps and are very, very excited to transition our internal networking framework to async/await. Currently we use GCD which can lead to a nightmare of closures as well as a lot of ugly indentation.
Re:Highlights of new technologies introduced at WWDC 2021 by toddh on Monday June 07, 2021 @06:31PM (#27428116)
The @MainActor is nice. It was always bewildering to me that we still had put UI operations on the main thread by hand. I still don't get why we need @MainActor. The compiler should do some sort of flow analysis and do the right thing.
Re:Highlights of new technologies introduced at WWDC 2021 by coldtea on Monday June 07, 2021 @07:55PM (#27428900)
Then you have two problems...
Re:Highlights of new technologies introduced at WWDC 2021 by eob on Monday June 07, 2021 @09:24PM (#27429588)
I've been using Swift to build the server-side of NLUDB.com and async/await is the biggest item on my wish list.

Maybe I just haven't learned proper EventLoopFuture-style development style, but you really seem to get stuck callback hell, similar to the early days of NodeJS. It's a bear on code readability.

Re: the sibling comment about Combine -- I've heard great things about Combine but AFAIK it's still part of Apple's platform-specific layer atop Swift so the small group of us using Swift atop Linux can't use it (yet?).

Re:Highlights of new technologies introduced at WWDC 2021 by elpakal on Monday June 07, 2021 @10:14PM (#27429894)
love Swift, largely agree with most comments here and feel like async fills a big hole.

> when Apple says “jump” you jump.

just not with the betas