News for hackers. Stuff that matters.
Re:From Rust to TypeScript by artificial on Saturday September 12, 2020 @12:18PM (#24453517)
Thank you for the excellent comparison with error precision. I’m diving into Swift (Vapor) and was curious if this remains true with Swift 5.2?
Re:From Rust to TypeScript by kibwen on Saturday September 12, 2020 @12:33PM (#24453616)
I'm no Swift expert, but I don't believe that any changes have been made to its idiomatic error-handling approach. Using the first example from the Swift 5.3 docs ( https://docs.swift.org/swift-book/LanguageGuide/ErrorHandlin... ):

    func buyFavoriteSnack(person: String, vendingMachine: VendingMachine) throws {
        let snackName = favoriteSnacks[person] ?? "Candy Bar"
        try vendingMachine.vend(itemNamed: snackName)
    }
The `try` is analogous to Rust's `?`, and the `throws` is the part of the type signature that indicates that the function may error but without any additional information about how it may error. Of course, I imagine a capable IDE should still be able to inspect all the `try`s in a function to determine what types can possibly be thrown.
Re:From Rust to TypeScript by NobodyNada on Saturday September 12, 2020 @03:11PM (#24454707)
Yes, that is still the case with 5.2. However, a proposal to add typed `throws` is currently being drafted and prototyped [0]. It won't be available in Swift 5.3, but if all goes well it might land in the next release after.

(Also, if you're doing Vapor programming, you may be pleased to know that Swift 6 is expected [1] to bring a real concurrency model, which will likely include some form of async/await so that you won't have to muck about with all those nested closures.)

[0]: https://forums.swift.org/t/typed-throws/39660

[1]: https://forums.swift.org/t/on-the-road-to-swift-6/32862/