Live data from Hacker News

Swift: Things I really wanted that won’t make it

ericasadun.com

11–20 of 54 posts

Re: Swift: Things I really wanted that won’t make it

#11

Error and Result types in the standard library, macros, per-target configurations and tests, a fix for namespacing issues due to the lack of a central repository for open-source libraries. The presence/lack of each of these are some of my favorite things about Rust, and it's too bad to see them miss this release of Swift.

Swift's error handling model essentially tosses type information out the window. I really don't understand why it was created instead of a first-party Result type.

Re: Swift: Things I really wanted that won’t make it

#12

Sorry but final by default is not a good idea IMO. All my work is client work. There have been a bunch of occasions where I've had to work around some weirdness of an Apple SDK by creating my own subclass. I could see Apple releasing an SDK and many of the classes being @final. Then I'm stuck in a situation where I can't provide a deliverable to the specifications a client wants due to a limitation in an SDK. That's…

It would be nice to have an "evil_override" keyword (or some other such name). There's no fundamental technical reason you can't do it, with unsafe pointer black magic if necessary, and it's sort of like an LD_PRELOAD: it's not a good solution, but sometimes you have to break abstraction barriers to get things done, and at least if you're using it you're explicitly saying you're breaking abstraction barriers.

final by default doesn't prevent someone from manually adding final to their classes.

Re: Swift: Things I really wanted that won’t make it

#13
post #10

> Disambiguating SPM Naming Conflicts Perl 6 did some work on this. I'm not sure if it's fully supported yet, but the design docs[1] go into detail on how it's supposed to work, so it may be worth looking at. > Method Cascades I suspect you might find disambiguating your method/attribute access easier in your "with" syntax if you make it match what swift appears to do for anonymous variables, use $0. (pardon my unfam…

You can nearly implement your version of `with` today:

    func with(value: T, f: T -> Void) -> T {
        f(value)
        return value
    }
Which you could then use like:

    let task = with(NSTask()) {
        $0.launchPath = "/usr/bin/mdfind"
        $0.arguments = ["kMDItemDisplayName == *.playground"]
        $0.standardOutput = pipe
        $0.launch()
        $0.waitUntilExit()
    }
The `let task =` part would be optional, and you could leave it off if you don't need to use the variable later.

Re: Swift: Things I really wanted that won’t make it

#14
post #12

Sorry but final by default is not a good idea IMO. All my work is client work. There have been a bunch of occasions where I've had to work around some weirdness of an Apple SDK by creating my own subclass. I could see Apple releasing an SDK and many of the classes being @final. Then I'm stuck in a situation where I can't provide a deliverable to the specifications a client wants due to a limitation in an SDK. That's…

It would be nice to have an "evil_override" keyword (or some other such name). There's no fundamental technical reason you can't do it, with unsafe pointer black magic if necessary, and it's sort of like an LD_PRELOAD: it's not a good solution, but sometimes you have to break abstraction barriers to get things done, and at least if you're using it you're explicitly saying you're breaking abstraction barriers. final b…

That wouldn't really work, because the compiler can do things like generate static dispatch or even inline method calls for final classes.

Re: Swift: Things I really wanted that won’t make it

#15
post #11

Error and Result types in the standard library, macros, per-target configurations and tests, a fix for namespacing issues due to the lack of a central repository for open-source libraries. The presence/lack of each of these are some of my favorite things about Rust, and it's too bad to see them miss this release of Swift.

Swift's error handling model essentially tosses type information out the window. I really don't understand why it was created instead of a first-party Result type.

First-class error handling is a little more ergonomic than just having a `Result` type that is used by convention, so I can see why Swift went that route if they were looking to improve ergonomics a bit. Rust has been gradually working on making its own `Result` type a bit more first-class, first with the `try!` macro, and in the future with the `?` operator which will improve upon `try!`.

Re: Swift: Things I really wanted that won’t make it

#17
post #9

Earlier quoted context omitted.

Agreed. I don't even like the fact that you can turn off subclassing, that's very un-object-oriented IMHO.

Idiomatic Swift is primarily protocol-based, object-orientation is mostly used when talking to the Cocoa frameworks, which aren't idiomatic Swift code. But the main problem with subclassing is: https://en.wikipedia.org/wiki/Fragile_base_class

Back in the day, with Smalltalk, a programmer could override everything. If you did something that broke derived classes, you were simply being a bad programmer. You simply didn't do that, and if you couldn't deduce if your change would do this or not, you either had a badly architected system, or you were being a bad programmer.

This is how it should work in many production environments: Are you 100% sure about that? No? Don't do that! Then start asking why you can't be sure, then fix that. Rinse, repeat.

Re: Swift: Things I really wanted that won’t make it

#18

Method Cascades. Dart-like for the win. Smalltalk-like. Go back one more step and the influence almost certainly comes from there. (Drink!)

Right. To be fair, the linked gist does call this out: "Cascades currently appear in languages including Dart and Smalltalk"

Re: Swift: Things I really wanted that won’t make it

#19
post #13
post #10

> Disambiguating SPM Naming Conflicts Perl 6 did some work on this. I'm not sure if it's fully supported yet, but the design docs[1] go into detail on how it's supposed to work, so it may be worth looking at. > Method Cascades I suspect you might find disambiguating your method/attribute access easier in your "with" syntax if you make it match what swift appears to do for anonymous variables, use $0. (pardon my unfam…

You can nearly implement your version of `with` today: func with (value: T, f: T -> Void) -> T { f(value) return value } Which you could then use like: let task = with(NSTask()) { $0.launchPath = "/usr/bin/mdfind" $0.arguments = ["kMDItemDisplayName == *.playground"] $0.standardOutput = pipe $0.launch() $0.waitUntilExit() } The `let task =` part would be optional, and you could leave it off if you don't need to use t…

Okay, then I don't really see a reason for Erica's syntax,which is special and either ambiguous or limited. How do you know whether you are calling a method on the given object, or a plain function? How to you know whether you are using an attribute of the object or a variable? Just rely on scope? That seems far more problematic and error prone for the small convenience of not typing three more characters with object access.

Your solution is actually simple enough that I'm not sure there needs to be a change to the language, unless there's some special behavior they can and should impart that we aren't thinking if.

That said, I don't write swift, so feel free to take my opinion for whatever you think it's worth. :)

Re: Swift: Things I really wanted that won’t make it

#20
post #15
post #11

Earlier quoted context omitted.

Swift's error handling model essentially tosses type information out the window. I really don't understand why it was created instead of a first-party Result type.

First-class error handling is a little more ergonomic than just having a `Result` type that is used by convention, so I can see why Swift went that route if they were looking to improve ergonomics a bit. Rust has been gradually working on making its own `Result` type a bit more first-class, first with the `try!` macro, and in the future with the `?` operator which will improve upon `try!`.

If the type signature was:

    func throwing() throws FooError -> Int
or even:

    func throwing() throws (FooError, BarError) -> Int
to create an implicit sum type, I'd find it acceptable, but not being able to tell what types of errors an API will throw is far from ergonomic - you'll need a catch-all block if you use anything but NSError[1] or ErrorType, even if you know the function only throws FooErrors.

[1] this is especially weird because NSError is just some random Foundation class, it's not anything inherent to the Swift language.

Post reply on HN