Live data from Hacker News

Apple announces full Swift rewrite of the Foundation framework (2022)

infoq.com

221–230 of 402 posts

Re: Apple announces full Swift rewrite of the Foundation framework (2022)

#221
post #41

Earlier quoted context omitted.

Yes, and it means Swift scripts and modules that don’t reference UIKit/AppKit/SwiftUI/Combine will run on Linux and possibly Windows with zero or little modification. I‘m a little sad though that they didn’t start this endeavor years ago, because IMO Rust has already built so much momentum that it will win (for the popular, medium to long term definition of „winning“).

Swift would never have won, and will never win, while it's so closely associated with Apple. Many people in positions of power believe (correctly) that Apple will always put its own needs above everyone else's. Those are the people who have chosen Rust.

Swift will never win against Rust for a much simpler reason: performance. Invariably, rust is chosen where performance is critical, and Swift’s reference counting GC ensures it will never compete with Rust in those scenarios.

Re: Apple announces full Swift rewrite of the Foundation framework (2022)

#222

Earlier quoted context omitted.

Id rather be spied on by foreigners who couldn't do anything about my eccentricities even if they cared. When you're own government's security services are spying on you, they own you.

The options weren't foreign government or local government, the current state is both, the future is local only. It's clearly an improvement. These security exploits also get used by local police who wouldn't have access to the top government access used for terrorists.

[deleted]

Re: Apple announces full Swift rewrite of the Foundation framework (2022)

#223

Earlier quoted context omitted.

It’s not respectful to not read the link and instead ask somebody to summarise it for you.

You’re making the wrong assumption! I have read the article before I asked, and still have no idea what it is! Saying it provides these abstraction NSObject, NSString, NSArray tells me nothing! The article is clearly written towards readers familiar with Apple ecosystem.

Objective-C is an object-oriented programming language that is essentially a super-set of C. In fact the earliest implementation of Objective C, if I recall correctly, translated Objective-C code to C.

The only built in types in Objective-C are the C types, like int, char and so on. The "Foundation" is a set of classes that implement many useful types that all inherit from a superclass called NSObject. The "NS" prefix refers to Next Step, the name of the company that Steve Jobs started and where Foundation was first created.

One of the advantages of this scheme is that it is possible to have heterogeneous collections (like an array of objects, where the objects do not all have to be of the same type/class).

Underneath the NS foundation (whose headers are all in Objective-C) is something called Core Foundation, which implements the same classes, but in pure C. To do this well requires huge programming discipline, especially around memory management, and much of that pain is taken away by using the NS classes.

Swift has already started replacing some of the foundation classes, NSString and NSDictionary, for example, giving them the names String and Dictionary without the cumbersome name-space two letter prefix.

I suspect that some of this rewrite may still "bridge" to the CF classes, but in other cases, it would be much better to simply write the class in its entirety in Swift.

I hope that helps.

Re: Apple announces full Swift rewrite of the Foundation framework (2022)

#224

Earlier quoted context omitted.

Swift certainly can be a scripting language. #!/usr/bin/env swift print("hello, world!")

Of course, but so can C++ and Java: https://stackoverflow.com/a/29709521

Right, but unlike C++ and Java, the scriptability of Swift was designed by spec. It's not a hack or convolution.

Re: Apple announces full Swift rewrite of the Foundation framework (2022)

#225

Tangental question: How do you Swift-using, non-app developers find out how to do basic anything non-app related, such as reading files and making network connections? I Google for stuff and probably 3/4s of the result are out of date and won't work in any reasonably modern version of Swift. I find Apple's Developer documentation sub-par, to say the least. So, how do you navigate it all? It's quite a shock coming fro…

Apple's documentation is pretty good in this regard.

Network comms are generally done using URLSession: https://developer.apple.com/documentation/foundation/urlsess...

Reading files is most often done using the String and Data types:

- https://developer.apple.com/documentation/foundation/nsdata/...

- https://developer.apple.com/documentation/swift/string/init(...:)

I've found Apple's documentation for Foundation to be quite exemplary.

Re: Apple announces full Swift rewrite of the Foundation framework (2022)

#226

Tangental question: How do you Swift-using, non-app developers find out how to do basic anything non-app related, such as reading files and making network connections? I Google for stuff and probably 3/4s of the result are out of date and won't work in any reasonably modern version of Swift. I find Apple's Developer documentation sub-par, to say the least. So, how do you navigate it all? It's quite a shock coming fro…

That’s all part of the lower level foundation library, which is what this post is about.

https://developer.apple.com/documentation/foundation/file_sy...

Re: Apple announces full Swift rewrite of the Foundation framework (2022)

#227

Earlier quoted context omitted.

I would not describe Rust as being particularly ergonomic. While it is a suitable replacement for C++, that is not necessarily a high standard to meet.

Reading the super majority of Rust code is equally easy or easier than reading Python, or Typescript, or even Ruby. Writing Rust applications is also very ergonomic. The Rust web server frameworks are approaching the ergonomics of Typescript web server frameworks. The only Rudy lacking ergonomics is writing net new frameworks or missing framework pieces, or when std is not available. 95%+ of all new Rust code will fa…

This isn't really the case. Rust code is almost as complex as C or C++ for any non-trivial application.

Re: Apple announces full Swift rewrite of the Foundation framework (2022)

#228

The article quotes this: > With a native Swift implementation of Foundation, the framework no longer pays conversion costs between C and Swift, resulting in faster performance. and this: > A reimplementation of Calendar in Swift is 1.5x to 18x as fast as the C one (calling from Swift in various synthetic benchmarks like creation, date calculation). First, that range of 1.5x-18x is kind of huge. Why? Second, why would…

I’m not deeply familiar with swift, objective-C or the next-step APIs, but it seems like they’re describing the difference between a (virtual?) function call (ie: swift to swift) vs a “message passing operation” in objective C. If that assessment is correct, then it’s really an exercise in small costs adding up quickly. If you call through the function pointer you have way lower latency, and if you call through the same operation hundreds of times to render a single screen (the calendar) inside of the render loop where latency matters- that’s measurably better. Especially on a device that tries to throttle CPU frequency to save battery power.

This is somewhat analogous to the same arguments that can be had about JIT compiled languages having the the opportunity to exceed performance of AoT compiled ones because of inlining opportunities- except in this case I don’t know if the call has any chance of being actually inlined so much as at least bypassing the message passing machinery overhead.

Re: Apple announces full Swift rewrite of the Foundation framework (2022)

#229

Is there anything genuinely innovative about Swift or is it just another "cross-platform scripting language" that I'll only see on 1 platform? The only reason I learned Powershell is because I have to admin for Windows. At least Powershell is interesting for its pipeline and object handling. I get not one spark of joy from Swift, and the comments I see are "at least we're not writing C anymore". Stockholm syndrome. S…

"It's not Objective-C" is pretty much the only advantage it has. You're not missing anything, it's basically a superfluous language that only exists in its current form because Objective C needed replacing and Apple would never adopt a language they didn't have effective control over. Language-wise, I see zero benefit over Rust, possibly Go (I'm not familiar enough to comment) or even JVM-less Kotlin.

But hey, we're stuck with it now so no use complaining.

Post reply on HN