Live data from Hacker News

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

ericasadun.com

41–50 of 54 posts

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

#41

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.

I don't have any experience with Swift, but how to you approach unit testing with everything `final`? Being able to inject mock subclasses is a staple of OO testing.

Protocols and generics cover everything you need to do that. Idiomatic Swift makes little use of classes to begin with, it's mostly structs, enums, and protocols, none of which allow inheritance.

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

#42
post #20

Earlier quoted context omitted.

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 espe…

One reason to avoid explicit lists of "error types" (exceptions) for methods is that method parameters are usually covariant whereas you really want exceptions to be contravariant[1]. This has big implications for higher-order functions and it's why everybody rightly hates explicit "throws" clauses in Java. [1] Or to put it in more practical terms: Imagine two classes/interfaces A and B where B subclasses A. Any meth…

You have the variance bit totally backwards. Methods are contravariant on their input and covariant on their results. A method which can only feed cats is not a method which can feed all animals. A method which gives me a cat, well, that is certainly a method that gives me an animal. Exceptions are another type of result. Please see https://en.m.wikipedia.org/wiki/Covariance_and_contravarianc... for more info.

I agree with your assertion that this is part of what makes explicit throws a pain, though. I hadn't thought about it that way, thanks for the insight.

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

#43

Swift is not perfect but I've been writing it a bunch recently and it's hands down one of the most productive languages I've written in. Fundamentally I believe that it might be one of the most important languages because it's relatively close to the metal, it's a 'modern language' (i.e. functional, has a pretty good type system), open source, and a major company and platform behind it. I think that if Swift 4.0 adds…

And you gotta love the Swift REPL :)

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

#44
Once Swift has achieved its goal of readability and the lexicon has stabilized, it'll be nice if they [re]introduce a more compact syntax, that you could opt into on a per-file basis, say by setting ".swifter" as their extension.

Bring back ++ and -- and currying, even if just as syntactic sugar that can be converted into the regular syntax by a tool, for those choose to write in it.

I appreciate Swift's philosophy and agree with their decisions so far, but there's a certain beauty to concise code (when it feels like writing maths) and it'll certainly make prototyping in Playgrounds more fun and, shall we say, swift.

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

#45

Swift is not perfect but I've been writing it a bunch recently and it's hands down one of the most productive languages I've written in. Fundamentally I believe that it might be one of the most important languages because it's relatively close to the metal, it's a 'modern language' (i.e. functional, has a pretty good type system), open source, and a major company and platform behind it. I think that if Swift 4.0 adds…

Swift might be "functional" (which means it has immutable values I guess?) or have a "pretty good type system" (which means it has generics?) but for a supposed "most productive language", I've never heard anyone mention how short the standard library falls.

I decided to start using it this week and after learning the requisite umpteen fiddly syntax idiosyncracies was startled to discover how little Swift supports you where traditional platforms (Java, C#, Ruby, Python, Node, Go) you got for free: a dang HTTP server, for example, requires you to write several[0] thousand[1] lines[2] of[3] code[4].

For a batteries-included language, Swift has a long ways to go before thinking about "defeating Go on the web".

[0] https://github.com/PerfectlySoft/Perfect/blob/master/Sources... [1] https://github.com/PerfectlySoft/Perfect/blob/master/Sources... [2] https://github.com/PerfectlySoft/Perfect/blob/master/Sources... [3] https://github.com/PerfectlySoft/Perfect/blob/master/Sources... [4] https://github.com/PerfectlySoft/Perfect/blob/master/Sources...

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

#46
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

Objective-C (and Swift) don't have the fragile base class problem: http://www.sealiesoftware.com/blog/archive/2009/01/27/objc_e...

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

#47

Swift is not perfect but I've been writing it a bunch recently and it's hands down one of the most productive languages I've written in. Fundamentally I believe that it might be one of the most important languages because it's relatively close to the metal, it's a 'modern language' (i.e. functional, has a pretty good type system), open source, and a major company and platform behind it. I think that if Swift 4.0 adds…

Swift might be "functional" (which means it has immutable values I guess?) or have a "pretty good type system" (which means it has generics?) but for a supposed "most productive language", I've never heard anyone mention how short the standard library falls. I decided to start using it this week and after learning the requisite umpteen fiddly syntax idiosyncracies was startled to discover how little Swift supports yo…

> "functional" (which means it has immutable values I guess?)

No, it means that it's a functional language. Please consult google if you are not sure what that means.

> "pretty good type system" (which means it has generics?)

No, it means that it has a more advanced type system than any of the languages you mentioned. It's most likely the most popular language with a type system that can be considered somewhat advanced.

There might be idiosyncrasies but like compared with say JS or whatever it's still miles ahead.

Yeah, the standard library is somewhat lacking but like that will be fixed. The language is very solid though.

Also don't judge a language by lack of an HTTP server in the standard library.

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

#48
post #39

Dart's method cascade syntax is still the best I've seen, that's immediately intuitive and unambiguous: let task = NSTask() ..launchPath = "/usr/bin/mdfind" ..standardOutput = pipe ..launch() ..waitUntilExit()

I suppose you could then simply leave out

    let task =
if you don't want to use that object any further.

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

#49
post #32

Earlier quoted context omitted.

why? don't you need side effects, like print("hello world")

It would be nice if that returned the number of characters printed, ala sprintf() in c.

In my opinion, that would go against the principle of least surprise.

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

#50

Earlier quoted context omitted.

Swift might be "functional" (which means it has immutable values I guess?) or have a "pretty good type system" (which means it has generics?) but for a supposed "most productive language", I've never heard anyone mention how short the standard library falls. I decided to start using it this week and after learning the requisite umpteen fiddly syntax idiosyncracies was startled to discover how little Swift supports yo…

> "functional" (which means it has immutable values I guess?) No, it means that it's a functional language. Please consult google if you are not sure what that means. > "pretty good type system" (which means it has generics?) No, it means that it has a more advanced type system than any of the languages you mentioned. It's most likely the most popular language with a type system that can be considered somewhat advanc…

It's not a functional language: http://robnapier.net/swift-is-not-functional

Please inform me what Swift's type system has over, say, Java as I don't know of anything and neither does a cursory Google.

The lack of an HTTP server is only an example. Let's see you parse JSON, or stream a Unix socket, or any of countless basic things that even Node includes in its standard lib. Swift doesn't really have much of anything except some types and traits: https://developer.apple.com/library/ios/documentation/Genera...

Post reply on HN